Utility matrix
A=eye(3,3) B=zeros(3,2) C=ones(3,2)
A= B= C=
1 0 0 0 0 1 1
0 1 0 0 0 1 1
0 0 1 0 0 0 1
d=rand(2,2) v=[1 2 3] A=[1 2 3; 4 5 6; 7 8 9]
(normally distributed values) v= A=
d= 1 2 3 1 2 3
0.8147 0.1270 4 5 6
0.9058 0.9134 f=diag(v) 7 8 9
f=
1 0 0 g=diag(A)
0 2 0 g=
0 0 3 1
5
9
h=diag(A,1) k=diag(A,-1)
h= k=
2 4
6 8
a=0:10:100 b=0:pi/50:2*pi; a=(2:10)
a= a=
0 10 20 30 40 50 linearly spaced vector from 2 3 4 5 6 7 8 9 10
60 70 80 90 100 0 to 2*pi spaced with pi/50
0, pi/50, 2pi/50 3pi/50, …
u=linspace(2, 20, 5) u=logspace(2,20,5)
u= (logarthamic)
u=
2.0000 6.5000 11.0000 1.0e+20 *
15.5000 20.0000 0.0000 0.0000 0.0000
0.0000 1.0000
A=[1 2 3; 4 5 6; 7 8 9] A+B A*B
A= ans = ans =
1 2 3 3 6 9 60 72 84
4 5 6 12 15 18 132 162 192
7 8 9 21 24 27 204 252 300
B=[2,4,6;8,10,12;14,16,18] A-B A/B
B= ans = ans =
2 4 6 -1 -2 -3 0.5000 0 0
8 10 12 -4 -5 -6 0 0.5000 0
14 16 18 -7 -8 -9 0 0 0.5000
A^2 A.*B A./B
ans = ans = ans =
30 36 42 2 8 18
66 81 96 32 50 72 0.5000 0.5000 0.5000
102 126 150 98 128 162 0.5000 0.5000 0.5000
0.5000 0.5000 0.5000
A.\B A.^B A.'
ans = ans = ans =
2 2 2 1.0e+17 * 1 4 7
2 2 2 0.0000 0.0000 0.0000 2 5 8
2 2 2 0.0000 0.0000 0.0000 3 6 9
0.0000 0.0028 1.5009
x=[1 5 3 7] k=x<y k=x>=y
x= k= k=
1 5 3 7 0 0 1 0 1 1 0 1
y = [0 2 8 7] k=x>y k=x==y
y= k= k=
0 2 8 7 1 1 0 0 0 0 0 1
x<=y k=x~=y
ans = k=
0 0 1 1 1 1 1 0
x=[0 5 3 7] m=(x>y) & (x>4) m=~(x|y)
x= m= m=
0 5 3 7 0 1 0 0 1 0 0 0
y = [0 2 8 7] n=x|y p=xor(x,y)
y= n= p=
0 2 8 7 0 1 1 1 0 0 0 0
x= 0 5 3 7 any(x<0) isempty(x)
y= 0 2 8 7 ans = ans =
0 (false) 0 (false)
all(x>=0)
ans =
1 (true=1) any(x>0) c=[inf NaN]
ans = c=
1 (true) Inf NaN
all(x<=0)
ans =
0 (false)
isinf(c) isnan(c) sin(x)
ans = ans = ans =
1 0 0 1 0 -0.9589 0.1411 0.6570
sind(x)
isfinite(c) find(x) ans =
ans = ans = 0 0.0872 0.0523 0.1219
0 0 2 3 4
asind(x)
[r,s]=find(y>0) ans =
isfinite(x) r= (row) 1.0e+02 *
ans = 1 1 1 0.0000 + 0.0000i 0.9000 -
1 1 1 1 s= (col) 1.3135i 0.9000 - 1.0100i
2 3 4 0.9000 - 1.5091i
sinh(x) exp(x) sqrt(x)
ans = ans =
0 74.2032 10.0179 548.3161 1.0e+03 * ans =
0.0010 0.1484 0.0201 0 2.2361 1.7321 2.6458
1.0966
nthroot(x,4)
log(x) ans =
ans = 0 1.4953 1.3161 1.6266
-Inf 1.6094 1.0986
1.9459
abs(x) real(com) conj(com)
ans = com = ans =
0 5 3 7 0 5 3 7 0 5 3 7
com=complex (x) imag(com)
com = com =
0.0000 + 0.0000i 5.0000 + 0 0 0 0
0.0000i 3.0000 + 0.0000i
7.0000 + 0.0000i
fix([-2.22 2.36]) ceil([-2.22 2.36]) round([-2.22 2.36])
ans = ans = ans =
-2 2 -2 3 -2 2
floor([-2.22 2.36]) mod(26,3) sign([-2.22 2.36])
ans = ans = ans =
-3 2 2 -1 1
a=[-1.5 7] msg = 'leave me alone' names=['abcd';'pqrs';'wxyz']
a= msg = names =
-1.5000 7.0000 leave me alone abcd
pqrs
b=[2,3] size(msg) wxyz
b= ans =
2 3 1 14 size(names)
rem(a,b) ans =
ans = 3 4
-1.5000 1.0000
wish=['hi';'hello';'bye'] wish=['hi***'; 'hello'; 'bye**'] wish=char('hi','hello','bye')
Error using vertcat wish = wish =
Dimensions of matrices being hi*** hi
concatenated are not hello hello
consistent. bye** bye
m=char(76) p =blanks(10) msg='leave me alone '
m= ans = msg =
L leave me alone
size(p) size(msg)
abs(m) p= ans =
ans = 1 10 2 17
76
findstr(msg,'leave') isletter(msg) strcmp('hello','HELLO')
ans = ans = ans =
1 1 1 1 1 1 0 1 0
1 0 1 1 1 1 1
ischar('x') 0 0 0 strcmp('hi','hi')
ans = ans =
1 lower('HELLO') 1
ans =
ischar(0) hello strncmp('hihello','hihe',2)
ans = ans =
0 upper('Hello') 1
ans =
HELLO
strcat('hi','hello') strvcat('hi','hello','bye') eval('x=5*sin(pi/3)')
ans = ans =
hihello hi x=
hello
bye 4.3301
F=inline('x^2*sin(x)') Fx=inline('x^2-sin(x)') x = [0 pi/4 pi/2 3*pi/4 pi]
F= Fx = x=
Inline function: Inline function: 0 0.7854 1.5708 2.3562
F(x) = x^2*sin(x) Fx(x) = x^2-sin(x) 3.1416
F(5) Fx(pi) Fx(x)
ans = ans = ans =
-23.9731 9.8696 0 -0.0903 1.4674 4.8445
9.8696
sin(Fx(0.3)) A=[5 -3 2; -3 8 4; 4 2 -9] [eigvec,eigval]=eig(A)
ans = A= eigvec =
-0.2041 5 -3 2
-3 8 4 0.1725 0.8706 -0.5375
4 2 -9 0.2382 0.3774 0.8429
-0.9558 0.3156 -0.0247
eig(A)
ans = eigval =
-10.2206 -10.2206 0 0
4.4246 0 4.4246 0
9.7960 0 0 9.7960
rx=2; ry=-1; rz=0; ezplot('exp(-0.1*x)*cos(x)',[0, r=inline(‘1+2*sin(2*t).^2’)
20])
change path to your folder r=
save newdata rx ry rz Inline function:
or r(t) = 1+2*sin(2*t).^2
newdata.mat in your folder
F='exp(-0.1*x)*cos(x)'; ezpolar(r)
clear all
load newdata ezplot(F,[0,20])
variables are loaded to
workspace.
x='t.*cos(3*pi*t)'; Z=inline('cos(x)*.cos(y).*exp(-
y='t.*sin(3*pi*t)'; sqrt((x.^2+y.^2)/4)))');
z=’t’;
econtour(Z)
ezplot3(x, y, z)
try at home