Matlab Assignment 01
(From the book “Matlab an Introduction
with Applications” 4th edition Amos Gilat
Department of Mechanical Engineering the Ohio State
University)
Submitted by: Muhammad Irfan Malik (2017-CH-52)
Submitted to: Dr. Kashif
Date of submission: October 25, 2019.
Chapter 01:
Q13 (a):
>> x=12;
>> z=tand(4*x)
z=
1.110612514829193
>> y=(4*tand(x)-4*tand(x)^3)/(1-6*tand(x)^2+tand(x)^4)
y=
1.110612514829193
As z=y (Hence given Identity proved)
Q13 (b):
>> x=12
x=
12
>> y=sind(12)^3
y=
0.008987455040201
>> z=(1/4)*(3*sind(x)-sind(3*x))
z=
0.008987455040201
As y=z (Hence given Identity proved)
Q14:
>> a=(5*pi)/8;
>> b=(pi/8);
>> x=sin(a)*cos(b)
x=
0.853553390593274
>> y=(1/2)*(sin(a-b)+sin(a+b))
y=
0.853553390593274
As x=y (Hence given Identity proved)
Chapter 02:
Q11:
>> i=[1 6 -3 -3 -3 -3 -3 -3 -3]
i=
1 6 -3 -3 -3 -3 -3 -3 -3
>> f=i(3:9)
f=
-3 -3 -3 -3 -3 -3 -3
Here “f” is a row vector contains 7 elements that are all (-3).
Q24 (a):
>> a=[7 2 -3 1 0]
a=
7 2 -3 1 0
>> b=[-3 10 0 7 -2]
b=
-3 10 0 7 -2
>> c=[1 0 4 -6 5]
c=
1 0 4 -6 5
>> u=ones(3)
u=
1 1 1
1 1 1
1 1 1
>> u(1,:)=a(1:3)
u=
7 2 -3
1 1 1
1 1 1
>> u
u=
7 2 -3
1 1 1
1 1 1
>> u(2,:)=b(1:3)
u=
7 2 -3
-3 10 0
1 1 1
>> u(3,:)=c(1:3)
u=
7 2 -3
-3 10 0
1 0 4
Q24 (b):
>> a=[7 2 -3 1 0]
a=
7 2 -3 1 0
>> b=[-3 10 0 7 -2]
b=
-3 10 0 7 -2
>> c=[1 0 4 -6 5]
c=
1 0 4 -6 5
>> v=zeros(3)
v=
0 0 0
0 0 0
0 0 0
>> v
v=
0 0 0
0 0 0
0 0 0
>>
>> v(:,1)=a(3:5)
v=
-3 0 0
1 0 0
0 0 0
>> v(:,2)=b(3:5)
v=
-3 0 0
1 7 0
0 -2 0
>> v(:,3)=c(3:5)
v=
-3 0 4
1 7 -6
0 -2 5
Chapter 03:
Q12(a):
>> v=[2 4 6 8 10]
v=
2 4 6 8 10
>> s=[1 1 1 1 1]
s=
1 1 1 1 1
>> a=v.\s
a=
0.500000000000000 0.250000000000000 0.166666666666667 0.125000000000000
0.100000000000000
Q12 (b):
>> v=[2 4 6 8 10]
v=
2 4 6 8 10
>> q=[1 1 1 1 1]
q=
1 1 1 1 1
>> b=v.^2.\q
b=
0.250000000000000 0.062500000000000 0.027777777777778 0.015625000000000
0.010000000000000
Q12 (c):
v=
2 4 6 8 10
>> c=v./2
c=
1 2 3 4 5
Q12 (d):
>> v=[2 4 6 8 10]
v=
2 4 6 8 10
>> d=v./v
d=
1 1 1 1 1
Q34:
i1
i3 i2
i4
V1 =12V
V2 =24V
R1=20Ω
R2=12Ω
R3=8Ω
R4=6Ω
R5=10Ω
Using Mesh Analysis
For Loope1
V1 –(i1- i3)R1 – (i1 – i2)R2 = 0
V1- i1R1+ i3R1- i1R2+i2R2=0
12-20i+20i3-12i1+12i2 =0
12-32i1+12i2+20i3+0i4 =0 (Equ1)
For Loope2
-V2 – (i2- i4)R4 – (i2- i1)R2 =0
-V2 - i2R4 + i4R4 - i2R2 +i1R2=0
-24-6i2 +6i4 -12i2 +12i1 =0
-24+12i1-18i2+0i3+6i4= 0 (Equ2)
For Loope3
V2 –(i3-–i1)R1–i3R3 =0
V2 - i3R1+ i1R1- i3R3=0
24-20i3+20i1-8i3=0
24+20i1+0i2-28i3+0i4 =0 (Equ3)
For Loope4
- (i4 -i2)R4 - - i4R5 =0
- i4R4 + i2R4 – i4R5 =0
-6i4+6i2-10i4 =0
0+0i1+6i2+0i3-16i4 =0 (Equ4)
Summary of Equations:
12-32i1+12i2+20i3+0i4 =0
-32i1+12i2+20i3+0i4 = -12 (Equ1)
-24+12i1-18i2+0i3+6i4= 0
12i1-18i2+0i3+6i4 = 24 (Equ2)
24+20i1+0i2-28i3+0i4 =0
20i1+0i2-28i3+0i4 = -24 (Equ3)
0+0i1+6i2+0i3-16i4 =0
0i1+6i2+0i3-16i4 =0 (Equ4)
Now from Matlab
>> A=[-32 12 20 0; 12 -18 0 6; 20 0 -28 0; 0 6 0 -16]
A=
-32 12 20 0
12 -18 0 6
20 0 -28 0
0 6 0 -16
B=
-12
0
-24
0
>> inv(A)
ans =
-0.116666666666667 -0.088888888888889 -0.083333333333333 -0.033333333333333
-0.088888888888889 -0.131216931216931 -0.063492063492063 -0.049206349206349
-0.083333333333333 -0.063492063492063 -0.095238095238095 -0.023809523809524
-0.033333333333333 -0.049206349206349 -0.023809523809524 -0.080952380952381
>> X=inv(A)*B
X=
3.400000000000000
2.590476190476190
3.285714285714286
0.971428571428571
Therefore
i1= 3.4 A
i2= 2.59 A
i3= 3.28 A
i4= 0.97 A
Chapter5:
Q3(a):
>> x=[0:3]
x=
0 1 2 3
>> y=(x+1).*(x-2).*(2.*x-0.25)-exp(x)
y=
-0.500000000000000 -6.218281828459046 -7.389056098930650 2.914463076812332
>> plot(x,y,'g')
Q3(b):
>> x=[-3:6]
x=
-3 -2 -1 0 1 2 3 4 5 6
>> y=(x+1).*(x-2).*(2.*x-0.25)-exp(x)
y=
Columns 1 through 6
-62.549787068367863 -17.135335283236614 -0.367879441171442 -0.500000000000000
-6.218281828459046 -7.389056098930650
Columns 7 through 10
2.914463076812332 22.901849966855764 27.086840897423400 -74.428793492735110
>> plot(x,y)
Q4:
>> x=[-2:2]
x=
-2 -1 0 1 2
>> y=sqrt(abs(cosd(3.*x)))+sin(x).^2
y=
1.824078996602090 1.707387950717973 1.000000000000000 1.707387950717973
1.824078996602090
>> plot(x,y,'r')
Q8(a):
>> t=[-30:-1.6]
t=
Columns 1 through 20
-30 -29 -28 -27 -26 -25 -24 -23 -22 -21 -20 -19 -18 -17 -16 -15 -14 -13
-12 -11
Columns 21 through 29
-10 -9 -8 -7 -6 -5 -4 -3 -2
>> x=(3.*t)./(1+t.^3)
x=
Columns 1 through 6
0.003333456794696 0.003567328194194 0.003826704933716 0.004115435423229
0.004438122332859 0.004800307219662
Columns 7 through 12
0.005208710120813 0.005671543646227 0.006198929275852 0.006803455723542
0.007500937617202 0.008311461067367
Columns 13 through 18
0.009260847196021 0.010382736156352 0.011721611721612 0.013337285121517
0.015311702515494 0.017759562841530
Columns 19 through 24
0.020845396641575 0.024812030075188 0.030030030030030 0.037087912087912
0.046966731898239 0.061403508771930
Columns 25 through 29
0.083720930232558 0.120967741935484 0.190476190476190 0.346153846153846
0.857142857142857
>> y=(3.*t.^2)./(1+t.^3)
y=
Columns 1 through 6
-0.100003703840883 -0.103452517631622 -0.107147738144048 -0.111116756427192
-0.115391180654339 -0.120007680491551
Columns 7 through 12
-0.125009042899515 -0.130445503863225 -0.136376444068752 -0.142872570194384
-0.150018752344043 -0.157917760279965
Columns 13 through 18
-0.166695249528383 -0.176506514657980 -0.187545787545788 -0.200059276822762
-0.214363835216916 -0.230874316939891
Columns 19 through 24
-0.250144759698900 -0.272932330827068 -0.300300300300300 -0.333791208791209
-0.375733855185910 -0.429824561403509
Columns 25 through 29
-0.502325581395349 -0.604838709677419 -0.761904761904762 -1.038461538461539
-1.714285714285714
Q8(b):
>> t=[-0.6:40]
t=
Columns 1 through 6
-0.600000000000000 0.400000000000000 1.400000000000000 2.400000000000000
3.400000000000000 4.400000000000000
Columns 7 through 12
5.400000000000000 6.400000000000000 7.400000000000000 8.400000000000000
9.400000000000000 10.400000000000000
Columns 13 through 18
11.400000000000000 12.400000000000000 13.400000000000000 14.400000000000000
15.400000000000000 16.399999999999999
Columns 19 through 24
17.399999999999999 18.399999999999999 19.399999999999999 20.399999999999999
21.399999999999999 22.399999999999999
Columns 25 through 30
23.399999999999999 24.399999999999999 25.399999999999999 26.399999999999999
27.399999999999999 28.399999999999999
Columns 31 through 36
29.399999999999999 30.399999999999999 31.399999999999999 32.399999999999999
33.399999999999999 34.399999999999999
Columns 37 through 41
35.399999999999999 36.399999999999999 37.399999999999999 38.399999999999999
39.399999999999999
>> x=(3.*t)./(1+t.^3)
x=
Columns 1 through 6
-2.295918367346939 1.127819548872181 1.121794871794872 0.485698866702644
0.253076617705439 0.153160679476469
Columns 7 through 12
0.102231421647819 0.072963852491412 0.054649651423845 0.042445393664183
0.033911186362412 0.027712050478566
Columns 13 through 18
0.023068455303856 0.019500698250808 0.016700566323682 0.014462749047199
0.012646225402818 0.011151546801138
Columns 19 through 24
0.009906958100779 0.008859636395386 0.007969999934268 0.007207916836657
0.006550122105703 0.005978422166281
Columns 25 through 30
0.005478424061863 0.005038621168927 0.004649725556356 0.004304173787756
0.003995756526013 0.003719337727390
Columns 31 through 36
0.003470639491691 0.003246075594267 0.003042621507187 0.002857712047526
0.002689160140399 0.002535091861707
Columns 37 through 41
0.002393894136321 0.002264172350458 0.002144715787310 0.002034469278313
0.001932509824736
>> y=(3.*t.^2)./(1+t.^3)
y=
Columns 1 through 6
1.377551020408163 0.451127819548872 1.570512820512821 1.165677280086347
0.860460500198491 0.673906989696463
Columns 7 through 12
0.552049676898223 0.466968655945034 0.404407420536453 0.356541306779136
0.318765151806673 0.288205324977084
Columns 13 through 18
0.262980390463959 0.241808658310023 0.223787588737337 0.208263586279672
0.194751871203395 0.182885367538663
Columns 19 through 24
0.172381070953558 0.163017309675108 0.154617998724800 0.147041503467809
0.140172613062045 0.133916656524701
Columns 25 through 30
0.128195123047590 0.122942356521821 0.118103029131446 0.113630187996746
0.109483728812768 0.105629191457886
Columns 31 through 36
0.102036801055704 0.098680698065709 0.095538315325665 0.092589870339842
0.089817948689322 0.087207160042707
Columns 37 through 41
0.084743852425759 0.082415873556673 0.080212370445404 0.078123620287219
0.076140887094601
>> plot(x,t,':b',y,t,'-g')
Chapter4:
Q2:
>> r=4.85/100;
P=100000;
y=10:30;
M=(P*(r/12))./(1-(1+(r/12)).^(-12.*y));
tbl=[y,M];
disp(M)
disp(y)
disp(tbl)
1.0e+03 *
Columns 1 through 6
1.053338409158346 0.979037203037794 0.917383650308490 0.865457759352513
0.821173725417141 0.783001870280961
Columns 7 through 12
0.749794854663779 0.720675227539015 0.694960459103126 0.672111647628188
0.651697614333117 0.633369256928701
Columns 13 through 18
0.616840897707781 0.601876497400946 0.588279315611263 0.575884052781169
0.564550805582168 0.554160365576284
Columns 19 through 21
0.544610525327117 0.535813148778964 0.527691827570959
Columns 1 through 20
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
29
Column 21
30
1.0e+03 *
Columns 1 through 6
0.010000000000000 0.011000000000000 0.012000000000000 0.013000000000000
0.014000000000000 0.015000000000000
Columns 7 through 12
0.016000000000000 0.017000000000000 0.018000000000000 0.019000000000000
0.020000000000000 0.021000000000000
Columns 13 through 18
0.022000000000000 0.023000000000000 0.024000000000000 0.025000000000000
0.026000000000000 0.027000000000000
Columns 19 through 24
0.028000000000000 0.029000000000000 0.030000000000000 1.053338409158346
0.979037203037794 0.917383650308490
Columns 25 through 30
0.865457759352513 0.821173725417141 0.783001870280961 0.749794854663779
0.720675227539015 0.694960459103126
Columns 31 through 36
0.672111647628188 0.651697614333117 0.633369256928701 0.616840897707781
0.601876497400946 0.588279315611263
Columns 37 through 42
0.575884052781169 0.564550805582168 0.554160365576284 0.544610525327117
0.535813148778964 0.527691827570959
Note: Here is the link of book from which assignment was completed
https://ecedmans.files.wordpress.com/2014/03/matlab-an-introduction-with-applications-4th-edition.pdf