【Julia学习笔记】——数学运算和基本函数Mathematical Operations and Elementary Functions

Julia编程语言的新版本之所以受到整个人工智能界的关注,最主要的原因正是其将 C 语言的速度、Ruby 的灵活、Python 的通用性前所未有地结合在一起,支持并行处理,易于学习和使用,尤其适合科学和工程计算。

官方文档链接:

Julia Documentation · The Julia Language

软件下载链接:

Download Julia


▋〓〓特色〓〓▋位异或运算x ⊻ y

▋〓〓特色〓〓▋位逻辑右移运算符x >>> y

▋〓〓特色〓〓▋位算术右移运算符x >> y

▋〓〓特色〓〓▋位逻辑/算术左移运算符x << y

▋〓〓特色〓〓▋采用@.表示对一个表达式的逐元素点乘

 ▋〓〓特色〓〓▋比较运算可以在一串元素上进行

特色内容详见下文。


基本数学运算符(说明:与MATLAB无差异)

+xunary plusthe identity operation
-xunary minusmaps values to their additive inverses
x + ybinary plusperforms addition
x - ybinary minusperforms subtraction
x * ytimesperforms multiplication
x / ydivideperforms division
x ÷ yinteger dividex / y, truncated to an integer
x \ yinverse divideequivalent to y / x
x ^ ypowerraises x to the yth power
x % yremainderequivalent to rem(x,y)

  \color{red}{1+1}

julia> 1 + 1
2

布尔运算 (说明:与MATLAB无差异)

ExpressionName
!xnegation
x && yshort-circuiting and
x || yshort-circuiting or

 位运算

位运算规则如下所示

ExpressionName
~xbitwise not
x & ybitwise and
x | ybitwise or
x ⊻ ybitwise xor (exclusive or)▋〓〓特色〓〓▋
x >>> ylogical shift right▋〓〓特色〓〓▋
x >> yarithmetic shift right▋〓〓特色〓〓▋
x << ylogical/arithmetic shift left▋〓〓特色〓〓▋
julia> bitstring(0b00000001 ⊻ 0b00000010)
"00000011"

julia> bitstring(0b00010000 >>> 3)
"00000010"

julia> bitstring(0b00010000 >> 2)
"00000100"

julia> bitstring(0b00010000 << 2)
"01000000"

julia> bitstring(0b00010000 << 3)
"10000000"

累计预算

主要运算符如下(说明:与MATLAB相同)【 ⊻=  >>>=  >>=  <<=为上节的扩展】

+=  -=  *=  /=  \=  ÷=  %=  ^=  &=  |=  ⊻=  >>>=  >>=  <<=

 向量逐元素点乘运算(说明:与MATLAB相同)

julia> [1 2 3 4 5].*5
1×5 Matrix{Int64}:
 5  10  15  20  25

▋〓〓特色〓〓▋采用@.表示对一个表达式的逐元素点乘

julia> A = [1 2 3];

julia> @. A^2
1×3 Matrix{Int64}:
 1  4  9

数值比较

数值比较运算法如下所示(说明:与MATLAB相同)

==equality
!=inequality
<less than
<=less than or equal to
>greater than
>=greater than or equal to

 ▋〓〓特色〓〓▋比较运算可以在一串元素上进行

julia> 1<2<3
true

 元运算符(说明:与MATLAB相同)【 ⊻  >>>  >>  <<等为上节的扩展】

CategoryOperatorsAssociativity
Syntax. followed by ::Left
Exponentiation^Right
Unary+ - √Right
Bitshifts<< >> >>>Left
Fractions//Left
Multiplication* / % & \ ÷Left
Addition+ - | ⊻Left
Syntax: ..Left
Syntax|>Left
Syntax<|Right
Comparisons> < >= <= == === != !== <:Non-associative
Control flow&& followed by || followed by ?Right
Pair=>Right
Assignments= += -= *= /= //= \= ^= ÷= %= |= &= ⊻= <<= >>= >>>=Right

圆整函数(说明:与MATLAB基本相同)

FunctionDescriptionReturn type
round(x)round x to the nearest integertypeof(x)
round(T, x)round x to the nearest integerT
floor(x)round x towards -Inftypeof(x)
floor(T, x)round x towards -InfT
ceil(x)round x towards +Inftypeof(x)
ceil(T, x)round x towards +InfT
trunc(x)round x towards zerotypeof(x)
trunc(T, x)round x towards zeroT

分离函数(说明:与MATLAB基本相同)

分离函数主要指取模运算和整数小时分离运算等。

FunctionDescription
div(x,y)x÷ytruncated division; quotient rounded towards zero
fld(x,y)floored division; quotient rounded towards -Inf
cld(x,y)ceiling division; quotient rounded towards +Inf
rem(x,y)remainder; satisfies x == div(x,y)*y + rem(x,y); sign matches x
mod(x,y)modulus; satisfies x == fld(x,y)*y + mod(x,y); sign matches y
mod1(x,y)mod with offset 1; returns r∈(0,y] for y>0 or r∈[y,0) for y<0, where mod(r, y) == mod(x, y)
mod2pi(x)modulus with respect to 2pi; 0 <= mod2pi(x) < 2pi
divrem(x,y)returns (div(x,y),rem(x,y))
fldmod(x,y)returns (fld(x,y),mod(x,y))
gcd(x,y...)greatest positive common divisor of xy,...
lcm(x,y...)least positive common multiple of xy,...

符号函数(说明:与MATLAB基本相同)

FunctionDescription
abs(x)a positive value with the magnitude of x
abs2(x)the squared magnitude of x
sign(x)indicates the sign of x, returning -1, 0, or +1
signbit(x)indicates whether the sign bit is on (true) or off (false)
copysign(x,y)a value with the magnitude of x and the sign of y
flipsign(x,y)a value with the magnitude of x and the sign of x*y

幂函数(说明:与MATLAB基本相同)

FunctionDescription
sqrt(x)√xsquare root of x
cbrt(x)∛xcube root of x
hypot(x,y)hypotenuse of right-angled triangle with other sides of length x and y
exp(x)natural exponential function at x
expm1(x)accurate exp(x)-1 for x near zero
ldexp(x,n)x*2^n computed efficiently for integer values of n
log(x)natural logarithm of x
log(b,x)base b logarithm of x
log2(x)base 2 logarithm of x
log10(x)base 10 logarithm of x
log1p(x)accurate log(1+x) for x near zero
exponent(x)binary exponent of x
significand(x)binary significand (a.k.a. mantissa) of a floating-point number x

 三角函数和反函数(说明:与MATLAB基本相同)

sin    cos    tan    cot    sec    csc
sinh   cosh   tanh   coth   sech   csch
asin   acos   atan   acot   asec   acsc
asinh  acosh  atanh  acoth  asech  acsch
sinc   cosc
sind   cosd   tand   cotd   secd   cscd
asind  acosd  atand  acotd  asecd  acscd

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值