Skip to content
This repository was archived by the owner on Mar 15, 2019. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions manual/noteworthy-differences.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,12 @@ Julia 的语法和 MATLAB 很像。但 Julia 不是简单地复制 MATLAB ,它
Julia 把赋值和分配内存分开了:
如果 ``a`` 长度为4, ``a[5] = 7`` 会抛出一个错误。 Julia 有一个专用的 ``push!`` 函数来向 ``Vectors`` 里增加元素。并且远比Matlab的 ``a(end+1) = val`` 来的高效。
- 虚数单位 ``sqrt(-1)`` 用 ``im`` 来表示
- Literal numbers without a decimal point (such as ``42``) create integers
instead of floating point numbers. Arbitrarily large integer
literals are supported. But this means that some operations such as
``2^-1`` will throw a domain error as the result is not an integer (see
:ref:`the FAQ entry on domain errors <man-domain-error>` for details).
- 没有小数点的数字(比如42)将会创建一个整型变量而非浮点型变量。整型变量的赋值范围可以为任意大。担责意味着一些操作比如``2^-1``将会抛出一个域错误,因为结果将不是一个整数(详见:ref:`the FAQ entry on domain errors <man-domain-error>`)。
- 多返回值和多重赋值需要使用圆括号,如 ``return (a, b)`` 和 ``(a, b) = f(x)``
- Julia 有一维数组。列向量的长度为 ``N`` ,而不是 ``Nx1`` 。例如, ``rand(N)`` 生成的是一维数组
- 使用语法 ``[x,y,z]`` 来连接标量或数组,连接发生在第一维度(“垂直”)上。对于第二维度(“水平”)上的连接,需要使用空格,如 ``[x y z]`` 。 要想构造块矩阵,尽量使用语法 ``[a b; c d]``
- ``a:b`` 和 ``a:b:c`` 中的冒号,用来构造 ``Range`` 对象。使用 ``linspace`` 构造一个满向量,或者通过使用方括号来“连接”范围,如 ``[a:b]``
- 函数返回须使用 ``return`` 关键字,而不是把它们列在函数定义中(详见 :ref:`man-return-keyword` )
- 函数返回须使用 ``return`` 关键字,而不是把它们列在函数定义中(详见ref:`man-return-keyword` )
- 一个文件可以包含多个函数,文件被载入时,所有的函数定义都是外部可见的
- ``sum``, ``prod``, ``max`` 等约简操作,如果被调用时参数只有一个,作用域是数组的所有元素,如 ``sum(A)``
- ``sort`` 等函数,默认按列方向操作。( ``sort(A)`` 等价于 ``sort(A,1)`` )。要想排序 ``1xN`` 的矩阵,使用 ``sort(A,2)``
Expand Down