% this is a simple tutorial to matlab
% ans is by default define inside matlab
1+2*3
ans + 1
% vector
v = [1;2;3;4];v % 4x1 vector
w = [5,6,7,8];w % 1x4 vector
v(2)
w(3)
v + w' % 4x1 vector
% calculate sum
v(1) + v(2) + v(3) + v(4)
sum(v)
sum0= 0; % to not out print current result
for i=1:4
sum0 = sum0 + v(i); % matlab start from 1
end
sum0
%or
sumv = 0;
for i=1:4, sumv=sumv+v(i); end
sumv
help sum
% doc
% https://ww2.mathworks.cn/help/releases/R2026a/sm/ug/model-excavator-dipper-arm.html
lookfor sum % most useful tool to find any function related with given keywords
% Matrix
A = [1,2,3; 4,5,6; 7,8,0];A
b = [0; 1; 2];b
% solve Ax = b
x = A\b;x
A*x
% format output, up to 16 digits
format long
x
% show the floating error
format short
b - A*x