Julia编程语言的新版本之所以受到整个人工智能界的关注,最主要的原因正是其将 C 语言的速度、Ruby 的灵活、Python 的通用性前所未有地结合在一起,支持并行处理,易于学习和使用,尤其适合科学和工程计算。
官方文档链接:
Julia Documentation · The Julia Language
软件下载链接:
▋〓〓特色〓〓▋位异或运算符x ⊻ y
▋〓〓特色〓〓▋位逻辑右移运算符x >>> y
▋〓〓特色〓〓▋位算术右移运算符x >> y
▋〓〓特色〓〓▋位逻辑/算术左移运算符x << y
▋〓〓特色〓〓▋采用@.表示对一个表达式的逐元素点乘
▋〓〓特色〓〓▋比较运算可以在一串元素上进行
特色内容详见下文。
基本数学运算符(说明:与MATLAB无差异)
+x | unary plus | the identity operation |
-x | unary minus | maps values to their additive inverses |
x + y | binary plus | performs addition |
x - y | binary minus | performs subtraction |
x * y | times | performs multiplication |
x / y | divide | performs division |
x ÷ y | integer divide | x / y, truncated to an integer |
x \ y | inverse divide | equivalent to y / x |
x ^ y | power | raises x to the y th power |
x % y | remainder | equivalent to rem(x,y) |
julia> 1 + 1
2
布尔运算 (说明:与MATLAB无差异)
Expression | Name |
---|---|
!x | negation |
x && y | short-circuiting and |
x || y | short-circuiting or |
位运算
位运算规则如下所示
Expression | Name |
---|---|
~x | bitwise not |
x & y | bitwise and |
x | y | bitwise or |
x ⊻ y | bitwise xor (exclusive or)▋〓〓特色〓〓▋ |
x >>> y | logical shift right▋〓〓特色〓〓▋ |
x >> y | arithmetic shift right▋〓〓特色〓〓▋ |
x << y | logical/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相同)【 ⊻ >>> >> <<等为上节的扩展】
Category | Operators | Associativity |
---|---|---|
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基本相同)
Function | Description | Return type |
---|---|---|
round(x) | round x to the nearest integer | typeof(x) |
round(T, x) | round x to the nearest integer | T |
floor(x) | round x towards -Inf | typeof(x) |
floor(T, x) | round x towards -Inf | T |
ceil(x) | round x towards +Inf | typeof(x) |
ceil(T, x) | round x towards +Inf | T |
trunc(x) | round x towards zero | typeof(x) |
trunc(T, x) | round x towards zero | T |
分离函数(说明:与MATLAB基本相同)
分离函数主要指取模运算和整数小时分离运算等。
Function | Description |
---|---|
div(x,y), x÷y | truncated 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 x , y ,... |
lcm(x,y...) | least positive common multiple of x , y ,... |
符号函数(说明:与MATLAB基本相同)
Function | Description |
---|---|
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基本相同)
Function | Description |
---|---|
sqrt(x), √x | square root of x |
cbrt(x), ∛x | cube 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