Contents
input and output
disp('Hello World')
Hello World
var=input('Enter any value: ');
disp(var)
Enter any value: 20
var =
20
format of output results
format short
x=453*1.54^9
format long
x=453*1.54^9
format bank
x=453*1.54^9
x =
2.2069e+04
x =
2.206910340376303e+04
x =
22069.10
Matrix input
A=[1,2,3; 4,5,6; 7,8,9]
A =
1.00 2.00 3.00
4.00 5.00 6.00
7.00 8.00 9.00
For loops
for z= 1:2:100
Y = z^2;
disp(Y)
end
1.00
9.00
25.00
49.00
81.00
121.00
169.00
225.00
289.00
361.00
441.00
529.00
625.00
729.00
841.00
961.00
1089.00
1225.00
1369.00
1521.00
1681.00
1849.00
2025.00
2209.00
2401.00
2601.00
2809.00
3025.00
3249.00
3481.00
3721.00
3969.00
4225.00
4489.00
4761.00
5041.00
5329.00
5625.00
5929.00
6241.00
6561.00
6889.00
7225.00
7569.00
7921.00
8281.00
8649.00
9025.00
9409.00
9801.00
while loops
z=1;
while (z<= 100)
Y = z^2;
z = z+2;
disp(Y)
end
1.00
9.00
25.00
49.00
81.00
121.00
169.00
225.00
289.00
361.00
441.00
529.00
625.00
729.00
841.00
961.00
1089.00
1225.00
1369.00
1521.00
1681.00
1849.00
2025.00
2209.00
2401.00
2601.00
2809.00
3025.00
3249.00
3481.00
3721.00
3969.00
4225.00
4489.00
4761.00
5041.00
5329.00
5625.00
5929.00
6241.00
6561.00
6889.00
7225.00
7569.00
7921.00
8281.00
8649.00
9025.00
9409.00
9801.00
Linear Algebraic Equations
B=[1 -4 3;3 1 2; 1 5 -1];
C=[11;1;4];
x=B\C
x= inv(B)*C
x =
-14.00
7.18
17.91
x =
-14.00
7.18
17.91
Linear Algebraic Equations
B= [1 -4 3; 3 1 2; 1 5 -1];
B=B'
C=[11;1;4];
C= C'
x=C / B
B =
1.00 3.00 1.00
-4.00 1.00 5.00
3.00 2.00 -1.00
C =
11.00 1.00 4.00
x =
-14.00 7.18 17.91
Polynomial & Arrays
poly([-1,-2])
F=polyval([7 -4 3 4], [1:.5:4])
ans =
1.00 3.00 2.00
F =
Columns 1 through 5
10.00 23.12 50.00 95.88 166.00
Columns 6 through 7
265.62 400.00
function plotting
x=-pi:0.1:pi;
y=sin(x);
plot(x,y)
xlabel('x [rad]')
ylabel('y=sin(x)')
title('plot of y=sin(x)')
grid