You are on page 1of 2

matlab means matrix laboratory, matrix is the core of matlab

fx --> help
clc
clear all
clear
plot()
double()
mod(), modulus function
sys()
sysms x_1 x_2 x_3
pretty()
+-*/
factorial()
sqrt()
nthroot(x,n)
all trigonometric functions is in radian so you need to constantly multiply to p
i/180
sin() cos() tan() csc() sec() cot()
asin() acos() atan() acsc() asec() acot()
e is represented as exp(1) or e^1, so for e^2 ---> exp(2)
there is no ln(), log() is base e, to use base 10, we use log10(), for base 2, u
se log2(), not all "n" numbers can be used
in logn(), only log10(), and log2()
"i" is recognized as complex number in matlab
abs() ----> absolute value
abs(a+bi) ---> defines the magnitude of the imaginary number and the real number
in the complex plane,
always positive, to know the angle of the imaginary number between the real numb
er, use angle(a+bi), note that the angle
is in radian
real(a+bi) = a, returns whatever the real part of a complex number
imag(a+bi)=b, returns whatever the imaginary part of a complex number
conj(a+bi)=a-bi, returns the conjugate of complex number
x = [a b c], represents matrix containing a, b, c
x = [a b c], x(2) = b, x(n), returns the nth element in a matrix
format longeng
format short
dot(a,b) ---------- dot product
a' ----------> transpose of a
cross(a,b), cross product
length(a), tells you how many elements are there in matrix a
min(a), minimum value of matrix a
max(a), maximul value of matrix a
sum(a), takes the sum of matrix a
mean(a), takes the mean of matrix a
a(1:5), extract 1-5 elements of matrix a
[a:b:c], creates a matrix starting from "a" to "c" with an increment of "b"
linspace(a,b,c), creates a matrix starting from "a" to "b" with "c" elements
[a b] = c, where "a" and "b" are two sets of matrices and "c" is the joint form
of "a" and "b"
a.*b = c, means that we multiply matrix "a" and "b" element by element, this cou
ld also be ./ , .^
rand(m, n), generates a matrix of random number of m columns by n rows.
randperm(n), generates random permutation of "n" elements, random permutatio mea
ns no element is being repeated
ones(m, n), generates m by n of number 1 in each element, can be zeros(m, n)
sort(a), rearrange the elements of "a" in ascending order starting from the lowe
st value.
mean(a)
median(a)

std(a)
var(a)

You might also like