Professional Documents
Culture Documents
Command window
Command
history
Notes page 2
The answer of any line is printed bellow it
except lines ended by ;
a=3-2
b=5;
c=a+b
MATLAB is case sensitive so x is not X
a=3
b=A+3
wrong
b=a+3
Matrix (page 4)
To make a row vector called a as1 5 3 in
MATLAB, we write
a = [ 1 5 3]
OR
a = [ 1, 5 ,3]
1
in MATLAB, we write
a=[1 ; -10 ; 4]
Note that ; means new line in the matrix
What are the dimensions of the above
matrices ?
Matrix (page 4)
9
3
as 5 10
6 30
Matrix (page 4)
3 2
3 5
3 2
3 5
1 3
* 4 2
1 3
.* 4 2
11 5
= 23 1
6
3
= 12 10
Transpose (page 4)
Rotate each column to a row
OR
Rotate each row to a column
Its symbol is
10
30
5 6
3
10
30
Constants and
formats( page 2)
1- pi the number = 3.141592653589793
format short : 4 digits after decimal point
format long : 15 digits after decimal point
pi
format long
pi
format short
pi
Dont
forget
a
report
of
examples of page
4
Constants ( page 2)
Inf : infinity
S=1/0
If (page 7)
if condition
.
.
end
if condition
.
else
.
end
if condition
.
elseif condition
.
else
.
end
See example in
page 7
i
end
for i=2:-0.1:1
i
end
while(page 8)
while condition
.
.
end
t=0;
while t<5
t=t+1
end
2-using feval
b = feval(myfun1,3)
Look at page 5 to the build in MATLAB functions
Write
Plotting (page 7)
x= [ 1 , 2 , 3 , 4, 5]
% x data
y= [ 4 , 6 , 8 , 10 , 12]
% y data
plot (x,y)
%plotting
title(my first graph)
%plot title
xlabel(x data)
% x axis name
ylabel(y data)
% y axis name
Note that % is followed by comments
The first line can be replaced with
x=1:1:5
% start : step : end
Plotting (page 7)
You can choose the color of the graph
b blue
ggreen r red
y yellow k black
You can choose the line shape of the graph
-
solid
. point
-. dashdot
-- dashed
You can choose the points shape
*
star
+ plus
plot(x,y,r-);
plot(x,y,g.)
plot(x,y,b-.); plot(x,y,y--)
plot(x,y,k*);plot(x,y,b+)
plot(x,y,r-*); plot(x,y,b-+)
OR
plot(x,y1,r-, x,y2,b--)