5+7
6/4
5-6
2^4
5*5
sin(5)
cos(5)
tan(pi)
pi
format long
pi
format short
exp(1)
log(exp(1))
log10(10)
sinh(4)
tanh(3)
x1 = sqrt(100^2 -60^2)
y1 = x1*15*(60^2 + x1^2)^(-1/2)
% row vector
x=[1 2]
% column vector
y=[3;4]
% transpose
y'
y=[3 4]
A=[1 2; 3 4]
$A*A$ and A^2 are same but A.^2 is different! $A*A$ or A^2 are the multiplication of A with A; however, A.^2 is the square of each element of A.
A*A
A^2
A.^2
$.*$
$./$
$.^$
are element-wise operations.
P = [2, 4]; Q = [3, 2];
P.*Q
P./Q
P.^Q
B = [5 6; 7 8]
C=B^(-1)
A*C
B*C
% component wise multiplication
B.*C
inv(B)
% determinant
det(B)
help eig
A=[1 2 3; 4 5 6; 7 8 98]
[eigvec, eigval] = eig(A)
$\left[ \begin{array}{ccc} a_{1,1} & a_{1,2} & a_{1,3}\\ a_{2,1} & a_{2,2} & a_{2,3}\\ a_{3,1} & a_{3,2} & a_{3,3} \end{array} \right]$
A(1:3,3)
size(A)
A=zeros(3)
%identity matrix
A = eye(4)
A=rand(4)
For example, solve the following system of linear equations:
x+2y+3z = 1
3x+3y+4z = 1
2x+3y+3z = 2
Check the determinant whether the system has a unique solution or not. If $det(A)\ne 0$ then the system has unique solution.
A=[1 2 3; 3 3 4; 2 3 3];
det(A)
b=[1; 1; 2];
x=A\b
x = 1:5
x = 1:0.5:5
length(x)
x = linspace(0,5,11)
index = find(x>2)
x(index)
For example plottest.m is an script file. plottest.m contains the following three lines:
x = 0:0.1:10;
y = sin(x);
plot(x,y)
We can run plottest.m by simply write plottest
%plot gnuplot
plottest