This is not meant as a reference to the language. For that you should read the manual
The first few are drawn from here
- Use brackets to index into vectors and matrices, i.e. do
v[i]
instead ofv(i)
. - Array assigment is done by reference, i.e after
A = B
modifyingA
will modifyB
! - One dimensional vectors are column vectors by default.
[17, 42, 25]
and[17;42;25]
both create a column vector. To create a row vector do[17 42 25]
, this is really a 1-by-3 (two-dimensional matrix).- The imaginary unit
sqrt(-1)
is represented byim
. - You don't need semicolons at the end of lines to supress output. You can still have them if you like them.
- Files don't have to be named after the main function of the file. A file can contain many modules, a module can contain many functions and has to explicitely export some for them to be available externally.
- Trying to access an undefined variable or an entry of a vector which is out of bounce will produce an error (throw an exception)
The syntax of Julia seems to be heavily inspired in MATLAB's. So, a there are more similiraties than differences. Here is a short list of some of the things that are (roughly) the same:
- Getting help on a function
help( sin )
- Ranges
10:-3:2
(fast range not fully expanded in memory) and[10:-3:2]
(fully expanded in memory) - Control flow structures -- note no parenthesis around if and while expressions:
if <boolean-expr> ... elseif else ...end
for i = 1:n ... end
.while <boolean-expr> ... end
.
- function declarations (
function myfun(arg1, arg2) ... end
). Note, however that there are no named output arguments preciding function name. Functions can return several values by returning a tuple, like so:return (out1,out2,out3)
.
MATLAB | Julia | Comments |
---|---|---|
fun = @(x,y) x + y |
fun = (x,y) -> x + y |
|
cell(3) |
cell(3,3) | This produces an Array{Any,2} |