Professional Documents
Culture Documents
Numerical Lab - EEE-2122
Numerical Lab - EEE-2122
y=
14.1906
Solution:
>>a=54^3;
>>b=6*pi;
>>c=exp(a/b);
>>d=sinh(c);
>>y=log10(d)
Output:
y=
Inf
Solution:
B=7:1:13.5;
>> size(A)
>>length(A)
>> size(B)
>>length(B)
Output:
ans =
4 3
ans =
ans =
1 7
ans =
solution:
output:
5 7
10 12
24 29
42 51
6 12
24 35
1.3333 -0.3333
0.6667 0.3333
1.5000 0.5000
0 1.0000
4 9
16 25
0.6667 0.7500
0.6667 0.7143
Exercise 4. Plot the following functions in the same window y1=sin x, y2=sin 2x, y3=sin 3x,
y4=sin 4x where x varies from 0 to pi
Solution:
>>x1=0:0.1:pi;
>>y1=sin(x);
>>x2=0:0.1:pi;
>>y2=sin(2.*x);
>>x3=0:0.1:pi;
>>y3=sin(3.*x);
>>x4=0:0.1:pi;
>>y4=sin(4.*x);
>>figure(1)
>>subplot(2,2,1)
>>plot(x1,y1)
>>subplot(2,2,2)
>>plot(x2,y2)
>>subplot(2,2,3)
>>plot(x3,y3)
>>subplot(2,2,4)
>>plot(x4,y4)
output:
Example 7. WHILE
x=-10;
while x<0
x=x+1;
end
What is the value of x after execution of the above loop?
Solution:
>>x=-10;
>>while x<0
>>x=x+1;
>>disp(x)
end
output:
-9
-8
-7
-6
-5
-4
-3
-2
-1
Solution:
x=0;
for i=1:10
x=x+1;
disp(x)
end
output:
10
Solution:
a)
b)
A=[17 2 3 4; 5 6 7 8; 9 10 11 12; 13 14 15 16];
B=[ 2 3 4 5 ; 6 7 8 9 ; 10 11 12 13 ; 14 15 16 17 ];
C=[ 1 2 3 ; 4 5 6 ; 7 8 9 ];
A*C
Output:
A=
17 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
>> B=[4;3;2;1]
B=
4
3
2
1
>> x=A^-1*B
Output:
x =
0.0000
9.0000
-21.5000
14.5000
3I1-I2-2I3=1
I1-6I2+3I3=0
2I1+3I2-6I3=-6
A=[3 -1 -2;1 -6 3;2 3 -6]
A=
3 -1 -2
1 -6 3
2 3 -6
>> B=[1;0;-6]
B=
1
0
-6
>>I =A^-1*B
Output:
I =
3.0000
2.0000
3.0000