More Related Content Similar to 2019-ME-37(NMC).docx Similar to 2019-ME-37(NMC).docx (20) 2019-ME-37(NMC).docx1. Numeric Method Control Lab
Lab Assignment
Submitted by: M.Shahrooz Shahbaz
(2019-ME-37)
Submitted To: Sir Ali Ovais
University of Engineering and Technology,Lahore
2. Chapter no 1
Question 1
Script
clear, clc
disp('Part (a)')
((14.5^2+6.5^2)/(3.8^2))+55/(sqrt(2)+14)
disp('Part (b)')
(-3.5^3)+(exp(6)/log10(524))+206^1/3
Command window
Question 2
Script
clear, clc
disp('Part (a)')
16.5^2*(8.4-sqrt(70))/(4.3^2-17.3)
disp('Part (b)')
((5.2^3)-((6.4^2)+3)/(1.6^8)-2)+((13.3/5)^1.5)
Command window
Question 3
Script
clear, clc
disp('Part (a)')
4. Question 6
Script
x=2.34;
% Part a
disp('Part (a)')
2*x^4-6*x^3+14.8*x^2+9.1
% Part b
disp('Part (b)')
exp(2*x)/sqrt(14+x^2-x)
Command window
Question 7
Script
disp('problem7')
t=6.8;
% Part a
log(abs(t^2-t^3))
% Part b
6. PartA=a*b/(c+d)+d*a/(c*d)-(a-b^2)*(c+d)
% Part b
disp('Part b')
PartB=sqrt(a^2+b^2)/(d-c)+log(abs(b-a+c-d))
Command window
Chapter no 2
Question no 1
disp('Problem 1')
v1=[3 4*2.55 68/16 45 110^(1/3) cosd(25) 0.05]
Command window
Problem 1
v1 =
3.0000 10.2000 4.2500 45.0000 4.7914 0.9063 0.0500
Question no 2
disp('Problem 2')
v2=[54/(3+4.2^2), 32, 6.3^2-7.2^2, 54, exp(3.7),sind(66)+cos(3*pi/8)]
Problem 2
v2 =
2.6163 32.0000 -12.1500 54.0000 40.4473 1.2962
7. Question no 3
disp('Problem 3')
v3=[25.5 14*tand(58)/(2.1^2+11) factorial(6) 2.7^4 0.0375,pi/5]
Command window
Problem 3
v3 =
25.5000 1.4539 720.0000 53.1441 0.0375 0.6283
Question no 4
disp('Problem 4')
v4=[32/3.2^2; sind(35)^2; 6.1; log(29^2); 0.00552;
log(29)^2; 133]
Command window
Problem 4
v4 =
3.1250
0.3290
6.1000
6.7346
0.0055
11.3387
133.0000
8. Question no 5
disp('Problem 5')
x=0.85; y=12.5;
v5=[y; y^x; log(y/x); y*x; x+y]
Command window
Problem 5
v5 =
12.5000
8.5580
2.6882
10.6250
13.3500
Question no 6
disp('Problem 6')
a=3.5; b=-6.4;
v6=[a a^2 a/b a*b sqrt(a)]
Command window
Problem 6
v6 =
3.5000 12.2500 -0.5469 -22.4000 1.8708
Question no 7
disp('Problem 7')
v7=2:5:37
Command window
9. Problem 7
v7 =
2 7 12 17 22 27 32 37
Question no 8
disp('Problem 8')
v8=linspace(81,12,9)
Command window
Problem 8
v8 =
81.0000 72.3750 63.7500 55.1250 46.5000 37.8750 29.2500 20.6250
12.0000
Question no 9
disp('Problem 9')
v9=[22.5:-2.5:0]'
Command window
Problem 9
v9 =
22.5000
20.0000
17.5000
11. Question no 11
disp('Problem 11')
same(1:7)=-3
Command window
Problem 11
same =
-3 -3 -3 -3 -3 -3 -3
Question no 12
disp('Problem 12')
a(9)=7.5
Command window
Problem 12
a =
3.5000 0 0 0 0 0 0 0 7.5000
Question no 13
disp('Problem 13')
b=[1:10 9:-1:1]
Command window
Problem 13
b =
Columns 1 through 17
12. 1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3
Columns 18 through 19
2 1
Question no 21
disp('Problem 21')
E(2:4,3:5)=[1:3;4:6;7:9]
Command window
Problem 21
E =
0 0 0 0 0
0 0 1 2 3
0 0 4 5 6
0 0 7 8 9
Question no 22
disp('Problem 22')
F(2:4,3:5)=[1:3;10:-2:6;20:6:32]'
Command window
Problem 22
F =
0 0 0 0 0
0 0 1 10 20
13. 0 0 2 8 26
0 0 3 6 32
Question no 23
disp('Problem 23')
a=[7 2 -3 1 0];
b=[-3 10 0 7 -2];
c=[1 0 4 -6 5];
ma=[a;b;c]
mb=[a' b' c']
Command window
Problem 23
ma =
7 2 -3 1 0
-3 10 0 7 -2
1 0 4 -6 5
mb =
7 -3 1
2 10 0
-3 0 4
1 7 -6
0 -2 5
Question no 29
disp('Problem 29')
A=[1:6;7:12;13:18]
16. 3
13
7
1
Question no 31
disp('Problem 31')
C=0.7:1.2:17.5
D=reshape(C,5,3)'
ua=[D(:,1)' D(:,3)' D(:,4)']'
ub=[D(2,:) D(:,3)']
uc=[D(1,1:3) D(3,3:5)]
Command window
Problem 31
C =
Columns 1 through 10
0.7000 1.9000 3.1000 4.3000 5.5000 6.7000 7.9000 9.1000 10.3000
11.5000
Columns 11 through 15
12.7000 13.9000 15.1000 16.3000 17.5000
D =
0.7000 1.9000 3.1000 4.3000 5.5000
6.7000 7.9000 9.1000 10.3000 11.5000
12.7000 13.9000 15.1000 16.3000 17.5000
18. E =
7.0000 2.0000 -3.0000 1.0000 2.0000 2.0000 2.0000
0.7000 0.6000 0.5000 0.4000 0.3000 0.2000 0.1000
2.0000 4.0000 6.0000 8.0000 10.0000 12.0000 14.0000
22.0000 19.0000 16.0000 13.0000 10.0000 7.0000 4.0000
F =
0.5000 0.4000 0.3000 0.2000 0.1000
16.0000 13.0000 10.0000 7.0000 4.0000
G =
-3.0000 1.0000 2.0000
0.5000 0.4000 0.3000
6.0000 8.0000 10.0000
16.0000 13.0000 10.0000
Question no 38
disp('Problem 38')
A=[eye(2) zeros(2,1) ones(2)]
B=[zeros(2) ones(2); zeros(1,4); ones(1,4)]
C=[ones(4,2),zeros(4,2),[ones(1) zeros(1,3)]']
Command window
Problem 38
A =
19. 1 0 0 1 1
0 1 0 1 1
B =
0 0 1 1
0 0 1 1
0 0 0 0
1 1 1 1
C =
1 1 0 0 1
1 1 0 0 0
1 1 0 0 0
1 1 0 0 0
Question no 39
disp('Problem 39')
A=eye(6)
A(1:3,4:6)=eye(3)
A(4:6,1:3)=eye(3)
Command window
Problem 39
A =
1 0 0 0 0 0
0 1 0 0 0 0
20. 0 0 1 0 0 0
0 0 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1
A =
1 0 0 1 0 0
0 1 0 0 1 0
0 0 1 0 0 1
0 0 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1
A =
1 0 0 1 0 0
0 1 0 0 1 0
0 0 1 0 0 1
1 0 0 1 0 0
0 1 0 0 1 0
0 0 1 0 0 1
Question no 40
disp('Problem 40')
A=ones(2)
A(3:4,3:4)=A
A=[A A]
Command window
21. Problem 40
A =
1 1
1 1
A =
1 1 0 0
1 1 0 0
0 0 1 1
0 0 1 1
A =
1 1 0 0 1 1 0 0
1 1 0 0 1 1 0 0
0 0 1 1 0 0 1 1
0 0 1 1 0 0 1 1
Chapter 3
Question no 1
disp('Problem 1')
x=-2:4
Command window
Problem 1
22. x =
-2 -1 0 1 2 3 4
Question no 2
disp('Problem 2')
x=-3:3
y=(x.^2-2)./(x+4)
Command window
Problem 2
x =
-3 -2 -1 0 1 2 3
y =
7.0000 1.0000 -0.3333 -0.5000 -0.2000 0.3333 1.0000
Question no 3
disp('Problem 3')
x=1:7
y=(x-3).*(x.^2+3)./x.^2
23. Command window
Problem 3
x =
1 2 3 4 5 6 7
y =
-8.0000 -1.7500 0 1.1875 2.2400 3.2500 4.2449
Question no 4
disp('Problem 4')
t=0:8
y=20*t.^(2/3)./(t+1)-(t+1).^2./exp(0.3*t+5)+2./(t+1)
Command window
Problem 4
t =
0 1 2 3 4 5 6 7 8
24. y =
1.9933 10.9800 11.2161 10.8566 10.4286 10.0259 9.6652 9.3455
9.0616
Question no 10
disp('Problem 10')
v=[3 -2 4];
u=[5 3 -1];
v.*u
v*u'
v'*u
Command window
Problem 10
ans =
15 -6 -4
ans =
5
ans =
15 9 -3
-10 -6 2
20 12 -4
25. Question no 11
disp('Problem 11')
va=[6.5 -5 -4];
ua=[-3 8 -2];
dotuva=sum(u.*v)
ub=[-3 8 -2];
vb=[6.5; -5; -4];
ub*vb
vc=[6.5 -5 -4];
uc=[-3 8 -2];
dotuvc=dot(vc,uc)
Command window
Problem 11
dotuva =
5
ans =
-51.5000
dotuvc =
-51.5000
26. Question no 12
disp('Problem 12')
v=2:2:10
a=1./v
b=1./v.^2
c=v/2
d=v./v
Command window
Problem 12
v =
2 4 6 8 10
a =
0.5000 0.2500 0.1667 0.1250 0.1000
b =
0.2500 0.0625 0.0278 0.0156 0.0100
c =
1 2 3 4 5
d =
1 1 1 1 1
27. Question no 13
disp('Problem 13')
v=5:-1:1
a=v.^2
b=v.^v
c=v*5
d=v-1
Command window
Problem 13
v =
5 4 3 2 1
a =
25 16 9 4 1
b =
3125 256 27 4 1
28. c =
25 20 15 10 5
d =
4 3 2 1 0
Question no 14
disp('Problem 14')
x=1:2:9;
y=2:3:14;
disp('Parta')
za=x.*y.^2./(x+y)
disp('Partb')
zb=x.*(x.^2-y)-(x-y).^2
Command window
Problem 14
Part a
za =
1.3333 9.3750 24.6154 47.0556 76.6957
29. Part b
zb =
-2 8 76 250 578
Question no 23
disp('Problem 23')
na = 1:10;
ya = 1./2.^na;
disp('Parta')
Sa = sum(ya)
aPercentError=abs(1-Sa)*100
nb = 1:20;
yb = 1./2.^nb;
disp('Partb')
Sb = sum(yb)
bPercentError=abs(1-Sb)*100
nc = 1:30;
yc = 1./2.^nc;
disp('Partc')
Sc = sum(yc)
cPercentError=abs(1-Sc)*100
nd = 1:40;
yd = 1./2.^nb;
disp('Partd')
Sd = sum(yd)
dPercentError=abs(1-Sc)*100
32. Problem 14
Part a
za =
1.3333 9.3750 24.6154 47.0556 76.6957
Part b
zb =
-2 8 76 250 578
Command window
Problem 23
Part a
Sa =
0.9990
34. 9.3132e-08
Part d
Sd =
1.0000
dPercentError =
9.3132e-08
Question no 24
disp('Problem 24')
clear,clc
na = 0:10;
ya = (-3).^(-na)./(2*na+1);
disp('Parta')
Sa = sqrt(12)*sum(ya)
aPercentError=abs((pi-Sa)/pi)*100
nb = 0:20;
yb = (-3).^(-nb)./(2*nb+1);
disp('Partb')
Sb = sqrt(12)*sum(yb)
bPercentError=abs((pi-Sb)/pi)*100
nc = 0:30;
yc = (-3).^(-nc)./(2*nc+1);
36. 1.8596e-10
Part c
Sc =
3.1416
cPercentError =
2.8272e-14
Question no 32
disp('Problem 32')
A=[3 1.5 1 0.5 4; -2 1 4 -3.5 2; 6 -3 2 2.5 1; 1 4 -3 0.5 -2; 3 2 -1 1.5 -3];
C=[-11.75; 19; -23; -1.5; -3.5];
x=AC
Problem 32
x =
41. y=1.5*cos(3*t);
plot(x,y)
axis([-2 2 -2 2])
xlabel('x')
ylabel('y')
Commandwindow
Problem 8
Script
disp('Problem 8')
t1=linspace(-30,-1.6,500);
t2=linspace(-0.6,40,500);
x1=3*t1./(1+t1.^3);
y1=3*t1.^2./(1+t1.^3);
x2=3*t2./(1+t2.^3);
y2=3*t2.^2./(1+t2.^3);
plot(x1,y1,x2,y2)
xlabel('x')
ylabel('y')
Commandwindow