# 'zeros' and 'ones' accepts any number of argumentsA=zeros(5); # create vector of size 5 filled with zerosB=ones(7, 4); # create 7x4 matrix filled with onesC=zeros(1, 2, 3); # create 1x2x3 matrix filled with zeros# eye accepts exactly two argumentsD=eye(10, 8); # create 10x8 matrix filled with ones on diagonal and zeros elsewhereE= [1, 2, 3, 4] # vector of size 4F= [[1, 2, 3], # matrix of size 2x3
[4, 5, 6]]
Scalars operations
r=a+b# additionr=a-b# subtractionr=a*b# multiplicationr=a/b# divisionr=-a# negationr+=a# assignment with additionr-=a# assignment with subtractionr*=a# assignment with multiplicationr/=a# assignment with divisionr=a>b# comparision: greaterr=a<b# comparision: lesserr=a>=b# comparision: greater or equalr=a<=b# comparision: lesser or equal
Matrix operations
R=A .+B# element wise additionR=A .-B# element wise subtractionR=A .*B# element wise multiplicationR=A ./B# element wise divisionR=A' # matrix transpositonA[1,2] =B[3,4] # metrix selectors
Comparators
r=A==B# equality comparatorr=a==br=A!=B# not equality comparatorr=a!=b
IF statement
if (a>b)
print"Yes";
if (a>b) {
print"Yes";
}
if (a>b)
print"Yes";
elseprint"No";
if (a>b) {
print"Yes";
} else {
print"No";
}
Loops
# while loopswhile (a>b)
b+=1;
while (a>b) {
b+=1;
}
# for (range) loopsfori=1:5printi;
fori=1:5 {
printi;
}
# break and continue keywordswhile(a>b) {
if (a>10)
break;
if (a>5)
continue;
a+=1;
}
Built-in instructions
printa, b, c; # prints to stdout, acepts any amount of arguments returna; # terminates program with given value as result