Professional Documents
Culture Documents
Programming report
1
Introduction
The name MATLAB stands for matrix laboratory. MATLAB was originally written
to provide easy access to matrix software developed by the LINPACK and
EISPACK projects, which together represent the state-of-the-art in software for
matrix computation.
2
Part (1)
>>x=1+2*3 x= 7
>>4*x ans= 28
4- Error messages.
??? 5x
|
Error: Unexpected MATLAB expression.
3
5- Mathematical functions.
6- Basic plotting.
>> x = [1 2 3 4 5 6];
>> y = [3 -1 2 4 5 1];
>> plot(x,y)
4
Plot for the vectors x and y.
>> x = 0:pi/100:2*pi;
>> y1 = 2*cos(x);
y3 = 0.5*cos(x);
>> plot(x,y1,’--’,x,y2,’-’,x,y3,’:’)
>> legend(’2*cos(x)’,’cos(x)’,’0.5*cos(x)’)
5
8- Specifying line styles and colors.
plot(x,y,’style_color_marker’)
9- Matrix generation.
6
>> v = [1 4 7 10 13]
v = 1 4 7 10 13
>> w = [1;4;7;10;13]
w=1
7
10
13
>> A = [1 2 3; 4 5 6; 7 8 9]
A= 1 2 3
4 5 6
7 8 9
10 - Matrix indexing.
>> A(3,3) = 0
A= 1 2 3
4 5 6
7 8 0
>> A(3,:) = []
A= 1 2 3
4 5 6
11– Dimension.
7
>> size(A)
ans= 3 3
12 - Matrix generators.
a - >> b=ones(3,1)
b= 1
b - >> eye(3)
ans = 1 0 0
0 1 0
0 0 1
8
A+ B or +A A*B is valid if A and B are of the same size
det Determinant
9
f=
120
10
Table 1.8 : Example of input and output arguments
• if... end
if expression
statements
end
Example:
if discr < 0
imaginary’);
11
end
statements
end
Example
for ii=1:5
x=ii*ii
end
n = 5; A = eye(n);
for j=2:n
for i=1:j-1
A(i,j)=i/j;
A(j,i)=i/j;
end
end
while expression
statements
end
x=1
12
while x <= 10
x = 3*x
end
13
(Part 2)
1– Differentiation (diff).
Clear
Clc
%% input
syms x
y=x
%% processing
diff (y , x ) or diff (y , x , a)
Clear
Clc
%% input
Syms x
Y = 9*x + x^3 + 10 ;
%% processing
diff ( y , x)
14
2– Integral(int).
Clear
Clc
%% input
syms x
y=x
%% processing
int ( y , x) or int (y , x , a , b)
Clear
Clc
%% input
syms x
y = 9*x + x^3 + 10 ;
%% processing
Int ( y , x )
15
(Part 3)
16