Solution Manual + Answer Key
Solution Manual for An Engineers Guide to MATLAB 3rd Edition
by Edward B. Magrab
View Full Product:
[Link]
Book Title: An Engineers Guide to MATLAB
Edition: 3rd Edition
Author: Edward B. Magrab
Click above to view a sample
Solution to Exercises
Chapter 2
2.1
n = 0:7;
a = 2*n-1;
b = 2*n+1;
aplusb = a+b
aminusb = a-b
atimesb = a'*b
detatimesb = det(atimesb)
atimesbtranspose = a*b'
Answers: aplusb = 0 4 8 12 16 20 24 28
aminusb = -2 -2 -2 -2 -2 -2 -2 -2
atimesb =
-1 -3 -5 -7 -9 -11 -13 -15
1 3 5 7 9 11 13 15
3 9 15 21 27 33 39 45
5 15 25 35 45 55 65 75
7 21 35 49 63 77 91 105
9 27 45 63 81 99 117 135
11 33 55 77 99 121 143 165
13 39 65 91 117 143 169 195
detatimesb = 0 atimesbtranspose = 552
2.2
x = sort( [17 -3 -47 5 29 -37 51 -7 19], 'descend');
xs = [x(find(sort(x, 'descend')<=0)), x(find(sort(x, 'descend')>0))]
Answer: w = -3 -7 -37 -47 51 29 19 17 5
2.3
y = [0, -0.2, 0.4, -0.6, 0.8, -1.0, -1.2, -1.4, 1.6];
sy = sin(y);
% (a)
mx = max(sy(find(sy<0)))
mn = min(sy(find(sy<0)))
% (b)
mp = sqrt(sy(find(sy>0)))
Answers: mx = -0.1987 mn = -0.9854 mp = 0.6240 0.8470 0.9998
2.4
v = logspace(log10(6), log10(106), 8)
v5 = v(5)
z = v([Link])
Answers: v5 = 30.9607 z = 6.0000 13.6295 30.9607 70.3300
© 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This publication is protected by Copyright and written permission should be
obtained from the publisher prior to any prohibited reproduction, storage in a1retrieval system, or transmission in any form or by any means, electronic,
mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department,
Pearson Education, Inc., Upper Saddle River, NJ 07458.
2.5
z = magic(5)
z(:,2) = z(:,2)/sqrt(3);
z(5,:) = z(5,:)+z(3,:);
z(:,1) = z(:,1).*z(:,4);
q = z-diag(diag(z))+diag([2 2 2 2 2]);
format long g
dq = diag(q*q')
format short
qmax = max(max(q))
qmin = min(min(q))
Answers: z =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
dq = [486 104189 7300 44522 111024]
qmax = 330 qmin = 1
2.6
w = magic(2);
wa = repmat(w, 2, 2)
wb = repmat(w, 3, 1)
wc = [repmat(w, 3, 1), repmat(w', 3, 1)]
wad = [w, w; w, w]
wbd = [w; w; w]
wcd = [w, w'; w, w'; w, w']
Answers: wa = % or wad
1 3 1 3
4 2 4 2
1 3 1 3
4 2 4 2
wb = % or wbd
1 3
4 2
1 3
4 2
1 3
4 2
wc = % or wcd
1 3 1 4
4 2 3 2
1 3 1 4
4 2 3 2
1 3 1 4
4 2 3 2
2.7
© 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This publication is protected by Copyright and written permission should be
obtained from the publisher prior to any prohibited reproduction, storage in a2retrieval system, or transmission in any form or by any means, electronic,
mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department,
Pearson Education, Inc., Upper Saddle River, NJ 07458.
(a)
x = magic(3);
t = x(1,:);
x(1:2,:) = x(2:3,:);
x(3,:) = t;
x
Answers: x =
3 5 7
4 9 2
8 1 6
(b)
x = magic(3)
t = x(:,3);
x(:,2:3) = x(:,1:2);
x(:,1) = t;
x
Answers: x =
6 8 1
7 3 5
2 4 9
2.8
x = magic(5);
xf = fliplr(x);
xf = fliplr(xf-diag(diag(xf)))
Answer: xf =
17 24 1 8 0
23 5 7 0 16
4 6 0 20 22
10 0 19 21 3
0 18 25 2 9
2.9
a = 1; b = 1.5; e = 0.3;
phi = linspace(0, 2*pi);
s = a*cos(phi)+sqrt(b^2-(a*sin(phi)-e).^2);
plot(phi*180/pi, s)
Answer:
© 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This publication is protected by Copyright and written permission should be
obtained from the publisher prior to any prohibited reproduction, storage in a3retrieval system, or transmission in any form or by any means, electronic,
mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department,
Pearson Education, Inc., Upper Saddle River, NJ 07458.
2.5
1.5
0.5
0
0 50 100 150 200 250 300 350 400
2.10
n = 1:25;
a = n*pi/sqrt(19);
P = 100*(1+2*cumsum((sin(a)./a).^2))/4.3589;
plot(n(2:25), P(2:25))
Answer:
100
98
96
94
92
90
88
86
84
82
0 5 10 15 20 25
2.11
a = sqrt(2.8);
n = 1:100; % (1x100)
x = 1:0.5:5; % (1x9)
exact = a./sqrt(a^2+x.^2).*sin(pi*sqrt(a^2+x.^2))/sin(pi*a);
e = 100*(prod(1-(1./(n.^2-a^2))'*x.^2)-exact)./exact % prod works on columns
Answer: e = 1.0001 2.2643 4.0610 6.4176 9.3707 12.9670 17.2642 22.3330 28.2588
2.12
x = [72, 82, 97, 103, 113, 117, 126, 127, 127, 139, 154, 159, 199, 207];
beta = 3.644;
delta = (sum(x.^beta)/length(x))^(1/beta)
Answer: delta = 144.2741
© 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This publication is protected by Copyright and written permission should be
obtained from the publisher prior to any prohibited reproduction, storage in a4retrieval system, or transmission in any form or by any means, electronic,
mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department,
Pearson Education, Inc., Upper Saddle River, NJ 07458.
2.13
b = 2;
phi = linspace(0, pi/2, 10);
the = linspace(0, 2*pi, 24);
[p, t] = meshgrid(phi, the);
mesh(b*sin(p).*cos(t), b*sin(p).*sin(t), b*cos(p))
Answer:
1.5
0.5
0
2
1 2
1.5
1
0 0.5
0
-1 -0.5
-1
-1.5
-2 -2
2.14
x = linspace(0.1, 1, 5);
n = -25:25;
y = pi*x*sqrt(2);
exact = 2*pi^4./y.^3.*(sinh(y)+sin(y))./(cosh(y)-cos(y));
[xx, nn] = meshgrid(x, n);
apx = sum(1./(nn.^4+xx.^4));
format long g
comp = [apx' exact']
format short
Answer: comp =
10002.1644054971 10002.1644456719
91.7751642291914 91.7752044040698
12.9244097924593 12.9244499673344
4.40350416999114 4.40354434485533
2.15691498449604 2.15695515933427
2.15
k = 0:25; n = 2;
x = linspace(1, 6, 6);
[xx, kk] = meshgrid(x, k);
Jn = sum((-1).^kk.*(xx/2).^(2*kk+n)./factorial(kk)./gamma(kk+1+n));
format long g
Comp = [Jn' besselj(n, x)']
format short
Answer: Comp =
0.1149034849319 0.114903484931901
0.352834028615638 0.352834028615638
© 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This publication is protected by Copyright and written permission should be
obtained from the publisher prior to any prohibited reproduction, storage in a5retrieval system, or transmission in any form or by any means, electronic,
mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department,
Pearson Education, Inc., Upper Saddle River, NJ 07458.
0.486091260585891 0.486091260585891
0.364128145852073 0.364128145852073
0.0465651162777518 0.0465651162777523
-0.242873209960186 -0.242873209960185
2.16
n = 7; k = 1:(2*n-1);
ser = sum(cos(k*pi/n))
Answer: ser = -1.0000
2.17
n = 6; k = 1:n;
N1 = n*(2*n^2+3*n+1)/6
S1 = sum(k.^2)
N2 = n*(6*n^4+15*n^3+10*n^2-1)/30
S2 = sum(k.^4)
N3 = n^2*(2*n^4+6*n^3+5*n^2-1)/12
S3 = sum(k.^5)
Answers: N1 = 91 S1 = 91 N2 = 2275 S2 = 2275 N3 = 12201 S3 = 12201
2.18
N = 10; n = 0:N;
PieDiff = sum((4./(8*n+1)-2./(8*n+4)-1./(8*n+5)-1./(8*n+6)).*(1/16).^n) -pi
Answer: PieDiff = 0
2.19
k=1:300;
dn=0.5*cumsum(1./k);
On = find(dn>1);
d1 = On(1)
tw = find(dn>2);
d2 = tw(1)
th = find(dn>3);
d3 = th(1)
Answer: d1 = 4 d2 = 31 d3 = 227
2.20
N = 10; k = 0:N;
e = sum(1./factorial(k))-exp(1)
Jo = sum((-1).^k./factorial(k).^2)-besselj(0,2)
co = sum((-1).^k./factorial(2*k))-cos(1)
Answers: e = -2.7313e-008 Jo = 6.3838e-016 co = -1.1102e-016
© 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This publication is protected by Copyright and written permission should be
obtained from the publisher prior to any prohibited reproduction, storage in a6retrieval system, or transmission in any form or by any means, electronic,
mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department,
Pearson Education, Inc., Upper Saddle River, NJ 07458.
2.21
K = 41; k = [Link]K; y = pi/3; x = 0.75;
SKdiff = sum(exp(-k*x).*sin(k*y)./k)-0.5*atan(sin(y)/sinh(x))
Answer: SKdiff = -2.2204e-016
2.22
K = 14; k = 0:K; a = 3; x = -2;
axdiff = sum((x*log(a)).^k./factorial(k))-a^x
Answer: axdiff = 9.0230e-008
2.23
N = 500; k = 1:N; z = 10;
c = pi*coth(pi*z)/(2*z)-1/(2*z^2)
S1 = cumsum(1./(k.^2+z^2));
K = find(abs(S1-c)<3e-3);
N =K(1)
Answer: N = 333
2.24
w = [-1 -1;1 -1;-1 1;1 1]/2;
orthw = w'*w
q = [1 -1 -1 1;1 1 -1 -1;1 -1 1 -1;1 1 1 1]/2;
orthq = q'*q
Answer: orthw =
1 0
0 1
orthq =
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
2.25
A = [2 -2 -4; -1 3 4; 1 -2 -3];
T = A*A-A
Answer: T =
0 0 0
0 0 0
0 0 0
2.26
© 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This publication is protected by Copyright and written permission should be
obtained from the publisher prior to any prohibited reproduction, storage in a7retrieval system, or transmission in any form or by any means, electronic,
mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department,
Pearson Education, Inc., Upper Saddle River, NJ 07458.
A = [1 2 2; 2 1 2; 2 2 1];
T = A*A-4*A-5*eye(3)
Answer: T =
0 0 0
0 0 0
0 0 0
2.27
A = [1 -1; 2 -1]; B = [1 1; 4 -1];
T = (A+B)^2-A^2-B^2
Answer: T =
0 0
0 0
2.28
A = [7 -2 1; -2 10 -2; 1 -2 7];
P = [1/sqrt(2) 1/sqrt(3) 1/sqrt(6); 0 1/sqrt(3) -2/sqrt(6); -1/sqrt(2) 1/sqrt(3) 1/sqrt(6)];
L = eig(A)
LL = diag(inv(P)*A*P)
Answers: L =
6.0000
6.0000
12.0000
LL =
6.0000
6.0000
12.0000
2.29
c = pi/180;
th1 = 30*c; th2 = 30*c; th3 = 30*c;
a1 = 1; a2 = 2; a3= 3;
a01 = [cos(th1) -sin(th1) 0 a1*cos(th1); sin(th1) cos(th1) 0 a1*sin(th1);0 0 1 0; 0 0 0 1];
a12 = [cos(th2) -sin(th2) 0 a2*cos(th2); sin(th2) cos(th2) 0 a2*sin(th2);0 0 1 0; 0 0 0 1];
a23 = [cos(th3) -sin(th3) 0 a3*cos(th3); sin(th3) cos(th3) 0 a3*sin(th3);0 0 1 0; 0 0 0 1];
t = a01*a12*a23;
thx3 = atan2(t(2,1), t(1,1))/c
thy3 = atan2(t(2,2), t(1,2))/c
qx = t(1,4)
qy = t(2,4)
Answers: thx3 = 90.0000 thy3 = 180 qx = 1.8660 qy = 5.2321
2.30
c = pi/180;
th1 = 15*c; th2 = 105*c; th3 = 145*c;
© 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This publication is protected by Copyright and written permission should be
obtained from the publisher prior to any prohibited reproduction, storage in a8retrieval system, or transmission in any form or by any means, electronic,
mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department,
Pearson Education, Inc., Upper Saddle River, NJ 07458.
th4 = 0; th5 = 215*c; th6 = 55*c;
a2 = 0.431; a3 = 0.019; r4 = a2; r3 = 0.125;
T12 = [cos(th1) 0 sin(th1) 0 ; sin(th1) 0 -cos(th1) 0 ; 0 1 0 0; 0 0 0 1];
T23 = [cos(th2) -sin(th2) 0 a2*cos(th2); sin(th2) cos(th2) 0 a2*sin(th2); 0 0 1 0; 0 0 0 1];
T34 = [cos(th3) 0 sin(th3) a3*cos(th3); sin(th3) 0 -cos(th3) a3*sin(th3); 0 1 0 r3; 0 0 0 1];
T45 = [cos(th4) 0 sin(th4) 0; sin(th4) 0 -cos(th4) 0; 0 1 0 r4; 0 0 0 1];
T56 = [cos(th5) 0 sin(th5) 0; sin(th5) 0 -cos(th5) 0; 0 1 0 0; 0 0 0 1];
T67 = [cos(th6) 0 sin(th6) 0; sin(th6) 0 -cos(th6) 0; 0 1 0 0; 0 0 0 1];
T17 =T12*T23*T34*T45*T56*T67
Answer: T17 =
0.2418 -0.5540 0.7966 -0.4729
0.9128 -0.1485 -0.3804 -0.2561
0.3290 0.8192 0.4698 0.5459
0 0 0 1.0000
2.31
x = [17 31 5;6 5 4;19 28 9;12 11 10];
H = diag(x*inv(x'*x)*x')'
Answer: H = 0.7294 0.9041 0.4477 0.9188
2.32
% square
n = [Link];
tau = linspace(-0.5, 0.5, 200);
plot(tau, 4/pi*(1./n)*sin(2*pi*n'*tau))
% sawtooth
n = 1:200;
tau = linspace(-1, 1, 200);
plot(tau, 0.5+1/pi*(1./n)*sin(2*pi*n'*tau))
% sawtooth
n = 1:200;
tau = linspace(-1, 1, 200);
plot(tau, 0.5-1/pi*(1./n)*sin(2*pi*n'*tau))
% triangular
n = 1:200;
tau = linspace(-1, 1, 200);
plot(tau, 0.5*pi-4/pi*((1./(2*n-1).^2)*cos(pi*(2*n'-1)*tau)))
% recitified sine wave
n = 1:200;
tau = linspace(-1, 1, 200);
plot(tau, 2/pi+4/pi*((1./(1-4*n.^2))*cos(2*pi*n'*tau)))
% half sine wave
n = [Link];
tau = linspace(-2, 2, 200);
plot(tau, 1/pi+.5*sin(pi*tau)-2/pi*(1./(n.^2-1)*cos(pi*n'*tau)))
% exponential
n = 1:250;
tau = linspace(0, 4*pi, 350);
plot(tau, (exp(2*pi)-1)/pi*(0.5+((1./(1+n.^2))*cos(n'*tau)-(n./(1+n.^2))*sin(n'*tau))))
% trapezoidal
n = [Link];
© 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This publication is protected by Copyright and written permission should be
obtained from the publisher prior to any prohibited reproduction, storage in a9retrieval system, or transmission in any form or by any means, electronic,
mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department,
Pearson Education, Inc., Upper Saddle River, NJ 07458.
tau = linspace(-2, 2, 200);
plot(tau, 64*((sin(n*pi/4)./(pi*n).^2)*sin(pi*n'*tau)))
2.33
a = sqrt(3); n = 1:25;
t = ([Link])*pi/180;
c = pi/sinh(pi*a)/2;
b = 1./(n.^2+a^2);
e1 = 100*(b*cos(n'*t)./(c*cosh(a*(pi-t))/a-0.5/a^2)-1)
e2 = 100*(n.*b*sin(n'*t)./(c*sinh(a*(pi-t)))-1)
Answers: e1 = -1.2435 0.8565 0.8728 -1.9417 -0.9579 -8.1206 0.7239 1.1661
e2 = 8.0538 10.4192 -8.9135 -5.4994 12.9734 -0.5090 -17.2259 11.2961
2.34
n = ([Link])*pi; a = 2;
eta = 0:1/14:1; xi = 0:1/14:1;
temp = meshgrid(1./(n.*sinh(n*a)), eta);
z = 4*(temp.*sinh(a*n'*eta)')*sin(n'*xi);
mesh(xi, eta, z)
Answer:
1.4
1.2
0.8
0.6
0.4
0.2
0
1
0.8
1
0.6 0.8
0.6
0.4
0.4
0.2
0.2
0 0
2.35
n = (1:50)*pi; eta = 0:0.05:1;
tau = 0:0.05:2; a = 0.25;
temp = meshgrid(sin(a*n)./n.^2, eta);
z = 2*pi/a/(1-a)*temp.*sin(n'*eta)'*cos(n'*tau);
mesh(tau, eta, z)
Answers:
© 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This publication is protected by Copyright and written permission should be
obtained from the publisher prior to any prohibited reproduction, storage in a10
retrieval system, or transmission in any form or by any means, electronic,
mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department,
Pearson Education, Inc., Upper Saddle River, NJ 07458.
4
-2
-4
1
0.9
0.8
0.7
2
0.6
0.5 1.5
0.4
0.3 1
0.2
0.5
0.1
0 0
2.36
A = [1 3 4; 31 67 9; 7 5 9];
B = [11 34 6; 7 13 8; 43 10 53];
DADB = det(A)*det(B)
DAB = det(A*B)
Answer: DADB = -3832062 DAB = -3832062
2.37
syms x y
x1 = -1; y1 = 1; x2 = 0; y2 = 0; x3 = 1; y3 = 1;
p = det([x^2+y^2 x y 1; x1^2+y1^2 x1 y1 1; x2^2+y2^2 x2 y2 1; x3^2+y3^2 x3 y3 1]);
p = factor(p)
Answer: p = 2*(x^2 + y^2 - 2*y)
2.38
syms x y
x1 = -1; y1 = 1; x2 = 1; y2 = 1; x3 = 2; y3 = 2;
p = det([x^2 x y 1; x1^2 x1 y1 1; x2^2 x2 y2 1; x3^2 x3 y3 1]);
p = factor(p)
Answer: p = 2*(x^2 - 3*y + 2)
2.39
A = [16, 32, 33, 13; 5, 11, 10, 8; 9, 7, 6, 12; 34, 14, 15, 1];
c = [91, 16, 5, 43];
supw = A\c' % or supw = linsolve(A, c')
determin = det(A)
invA = inv(A)
Answers: supw = [-0.1258 -8.7133 11.2875 -0.0500]
determin = 7680
invA =
-0.0177 -0.0023 0.0180 0.0333
-0.3344 1.2352 -0.4695 0.1000
© 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This publication is protected by Copyright and written permission should be
obtained from the publisher prior to any prohibited reproduction, storage in a11
retrieval system, or transmission in any form or by any means, electronic,
mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department,
Pearson Education, Inc., Upper Saddle River, NJ 07458.
0.3500 -1.1375 0.3875 -0.1000
0.0333 -0.1500 0.1500 -0.0333
2.40
a = 0.005; b = 0.0064; c = 0.008;
E1 = 2.1e9; E2 = 0.21e9;
nu1 = 0.4; nu2 = 0.4; Uo = 0.00025;
Matrix = [1, a^2, 0, 0; 1, b^2, -1, -b^2; ...
-(1+nu1), (1-nu1)*b^2, (1+nu2)*E1/E2, -(1-nu2)*b^2*E1/E2;...
0, 0, -(1+nu2), (1-nu2)*c^2];
y = [0, 0, 0, -Uo*E2*c]';
AB = Matrix\y;
hoop1 = -AB(1)/b^2+AB(2)
hoop2 = -AB(3)/b^2+AB(4)
% check
urc = -(1+nu2)*AB(3)/E2/c+(1-nu2)*c*AB(4)/E2
Answers: hoop1 = -6.3013e+007 hoop2 = -1.1790e+007 urc = -2.5000e-004
2.41
syms i1 i2 i3 R V1 V2 V3
Q1 = 'V1-6*R*i1+4*R*(i2-i1)=0,';
Q2 = 'V2+2*R*(i3-i2)-3*R*i2-4*R*(i2-i1)=0,';
Q3 = '-V3-R*i3-2*R*(i3-i2y)=0';
[i1 i2 i3] = solve([Q1 Q2 Q3])
Answer: i1 = 1/182/R*(23*V1 + 12*V2 - 8*V3)
i2 = 1/91/R*(6*V1 + 15*V2 - 10*V3)
i3 = 1/91/R*(4*V1 + 10*V2 - 37*V3)
2.42
Either
syms s t V1 V2 V3 U real
A = [2*s+t -s 0; -s 2*s+t -s; 0 -s s+t];
B = [s*U 0 0]';
V=inv(A)*B
or
syms s t V1 V2 V3 U real
[V1 V2 V3] = solve((2*s+t)*V1-s*V2-s*U, -s*V1+(2*s+t)*V2-s*V3, -s*V2+(s+t)*V3, V1, V2, V3);
V1 = factor(V1)
V2 = factor(V2)
V3 = factor(V3)
gives
Answer: V1 = (U*s*(s^2 + 3*s*t + t^2))/(s^3 + 6*s^2*t + 5*s*t^2 + t^3)
V2 = (U*s^2*(s + t))/(s^3 + 6*s^2*t + 5*s*t^2 + t^3)
V3 = (U*s^3)/(s^3 + 6*s^2*t + 5*s*t^2 + t^3)
© 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This publication is protected by Copyright and written permission should be
obtained from the publisher prior to any prohibited reproduction, storage in a12
retrieval system, or transmission in any form or by any means, electronic,
mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department,
Pearson Education, Inc., Upper Saddle River, NJ 07458.