Beruflich Dokumente
Kultur Dokumente
Chapter 1
1.1
E1 = 1+5^3+3^3-153
E2 = 1+6^4+3^4+4^4-1634
E3 = 5^6+4^6+8^6+8^6+3^6+4^6-548834
E4 = 1+factorial(7)-71^2
E5 = factorial(1)+factorial(4)+factorial(5)+factorial(6)+factorial(7)+factorial(8)-215^2
1.2
pie = pi - (100-(2125^3+214^3+30^3+37^2)/82^5)^(1/4)
1.3
format long g
I1 = 53453/log(53453)
I2 = 613*exp(1)/37-35/991
format short
1.4
x = (49-27*sqrt(5)+3*sqrt(6)*sqrt(93-49*sqrt(5)))^(1/3)
R = 0.5*sqrt((8*2^(2/3)-16*x+2^(1/3)*x^2)/(8*2^(2/3)-10*x+2^(1/3)*x^2))
Answers: x = 2.5375 + 1.9080i
R = 0.8161 - 0.0000i
1.5
E1 = cot(pi/5)-sqrt(25+10*sqrt(5))/5
E2 = sin(pi/15)-sqrt(7-sqrt(5)-sqrt(30-6*sqrt(5)))/4
E3 = pi-16*atan(1/5)+4*atan(1/239)
1.6
g = sqrt(17-sqrt(17));
b = sqrt(17+sqrt(17));
a = sqrt(34+6*sqrt(17)+sqrt(2)*(sqrt(17)-1)*g-8*b*sqrt(2));
E1 = sin(pi/17)-sqrt(2)/8*sqrt(g^2-sqrt(2)*(a+g))
1.7
a = 1; b = 2;
E1 = exp(a)-sinh(a)-cosh(a)
E2 = sinh(2*b)/(cosh(a+b)*cosh(a-b))-tanh(a+b)+tanh(a-b)
1.8
L = 1.5; h = 1; r = 1.6;
V = L*(r^2*acos((r-h)/r)-(r-h)*sqrt(2*r*h-h^2))
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.
Answer: V = 3.2209
1.9
g = 60*pi/180; a = 35*pi/180; n = 4/3;
D = a-g+asin(n*sin(g-asin(sin(a)/n)))
Answer: D = 0.4203
1.10
k = 7; n =12;
Cnk = factorial(n)/factorial(k)/factorial(n-k)
Answer: Cnk = 792
1.11
r = 2.5;
I = (pi/8-8/9/pi)*r^4
Answer: I = 4.2874
1.12
c = 5;
K = (4*c-1)/(4*c+4)+0.615/c
Answer: K = 0.9147
1.13
B = 0.6;
K = 3/(1-B)^3*(0.5-2*B+B*(1.5-log(B)))
Answer: K =
23.7420
1.14
R = 30; r = 12; S = 50;
theta = asin((R-r)/S);
L = 2*S*cos(theta)+pi*(R+r)+2*theta*(R-r)
Answer: L = 238.4998
1.15
Fn = 250; f = 0.35; r = 0.4; theta = 60*pi/180;
T = (4*f*r*Fn*sin(theta/2))/(theta+sin(theta))
Answer: T = 36.5875
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.
1.16
A = 1.7; B = 1.2;
D = 1.265*((A*B)^3/(A+B))^(1/5)
Answer: D = 1.5682
1.17
n = 6;
M = 1/sin(pi/n);
C = (1+M^2)/4/M;
alpha = acos(sqrt(C^2+2)-C);
aG = M*(1-M^2)*sin(alpha)/(1+M^2-2*M*cos(alpha))^2
Answer: aG = -1.3496
1.18
L = 3000; d = 45; V = 1600;
Deltap = 0.03*L/d^1.24*(V/1000)^1.84
Answer: Deltap = 1.9048
1.19
E1 = 206e9; E2 = 206e9; nu1 = 0.3; nu2 = 0.3;
d1 = 0.038; d2 = 0.070; F = 450; z = 0.00025;
a = (0.375*F*((1-nu1^2)/E1+(1-nu2^2)/E2)/(1/d1+1/d2))^(1/3);
pmax = 1.5*F/pi/a^2;
za = z/a;
sxsy = -pmax*((1-za*atan(1/za))*(1-nu1)-0.5/(1+za^2))
sz = -pmax/(1+za^2)
Answers: sxsy = 2.0779e+008 sz = -1.2421e+009
1.20
E1 = 206e9; E2 = 206e9; nu1 = 0.3; nu2 = 0.3;
d1 = 0.038; d2 = 0.070; F = 450; z = 0.000025; L = 0.05;
b = sqrt(2*F/pi/L*((1-nu1^2)/E1+(1-nu2^2)/E2 )/(1/d1+1/d2));
pmax = 2*F/pi/b/L;
zb = z/b;
sx = -pmax*2*nu2*(sqrt(1+zb^2)-zb)
sy = -pmax*((2-1/(1+zb^2))*sqrt(1+zb^2)-2*zb)
sz = -pmax/sqrt((1+zb^2))
Answers: sx = -5.0360e+007 sy = -3.5432e+007 sz = -1.3243e+008
1.21
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.
e = 0.8;
NL = pi*e*sqrt(pi^2*(1-e^2)+16*e^2)/(1-e^2)^2
Answer: NL = 72.0220
1.22
h = 0.03; d0 = 0.006;
d1 = 0.016; E = 206e9;
d2 = d1+h*tan(pi/6);
k = pi*E*d0*tan(pi/6)/log((d2-d0)*(d1+d0)/(d2+d0)/(d1-d0))
Answer: k = 5.2831e+009
1.23
alpha = 2e-5; E = 206e9; nu = 0.3;
Ta = 260; Tb = 150; a = 0.006; b = 0.012; r = 0.010;
c1 = alpha*E*(Ta-Tb)/2/(1-nu)/log(b/a);
c2 = a^2/(b^2-a^2)*log(b/a);
br = b/r;
sr = c1*(c2*(br^2-1)-log(br))
st = c1*(1-c2*(br^2+1)-log(br))
T = Tb+(Ta-Tb)*log(br)/log(b/a)
Answers: sr = -3.7670e+007 st = 1.1859e+008 T = 178.9338
1.24
k = 1.4; pepo = 0.3;
psi = sqrt(k/(k-1))*sqrt(pepo^(2/k)-pepo^((k+1)/k))
Answer: psi = 0.4271
1.25
x = 0.45;
K = 1.2/x/(sqrt(16*x^2+1)+log(sqrt(16*x^2+1)+4*x)/4/x)^(2/3)
Answer: K = 1.3394
1.26
c = sqrt(8)/9801;
n = 0;
oneopi0 = c*(1103+26390*n)*factorial(4*n)/factorial(n)^4/396^(4*n);
n = 1;
oneopi1 = c*(1103+26390*n)*factorial(4*n)/factorial(n)^4/396^(4*n);
format long e
pin0 = 1/oneopi0
diffpino = pin0-pi
pin0n1 = 1/(oneopi0+oneopi1)
diffpin0n1 = pin0n1-pi
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.
format short
Answers: pin0 = 3.141592730013306e+000 diffpino = 7.642351240733092e-008
pin0n1 = 3.141592653589794e+000 diffpin0n1 = 4.440892098500626e-016
1.27
r = 10; rc = 3; k = 1.4;
eta = 1-1/r^(k-1)*((rc^k-1)/k/(rc-1))
Answer: eta = 0.4803
1.28
M = 2; k = 1.4;
AA = 1/M*(2/(k+1)*(1+(k-1)/2*M^2))^((k+1)/(2*(k-1)))
Answer: AA = 1.6875
1.29
n = 5; ep = 0.1;
w = 0.5
T = 1/sqrt(1+(ep*cos(n*acos(w))).^2)
w=1
T = 1/sqrt(1+(ep*cos(n*acos(w))).^2)
w = 1.5
T = 1/sqrt(1+(ep*cosh(n*acosh(w))).^2)
Answers: w = 0.5000 T = 0.9988 w = 1 T = 0.9950 w = 1.5000 T = 0.1605
1.30
m = 1; n = 2; nu = 0.3; hR = 0.05; Rl = 0.1;
Lm = pi/4*Rl*(4*m+1);
Om = (1-nu^2)*Lm^4/(Lm^2+n^2+1.78*n^2*Lm^2);
Om = Om+hR^2/12*(Lm^4+n^4+1.78*m^2*Lm^2)
Answer: Om = 7.5159e-003
1.31
V = 2.9; D = 0.3; ep = 0.00025; nu = 1.012e-6;
Re = V*D/nu;
f = ((64/Re)^8+9.5*(log(ep/3.7/D+5.74/Re^0.9)-(2500/Re)^6)^-16)^(1/8)
Answer: f = 0.0193
1.32
n = 3; th = pi/7;
a = cos(th)+(n^2*cos(2*th)+sin(th)^4)/(n^2-sin(th)^2)^(3/2)
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.
Answer: a = 1.1168
1.33 [Note: These solutions are obtained with a large amount of user interaction, almost on a line
by line basis.]
(a)
x = a*sin(t);
y = a*cos(t)^2*(2+cos(t))/(3+sin(t)^2);
xp = diff(x,t,1);
xpp = diff(x,t,2);
yp = diff(y,t,1);
ypp = diff(y,t,2);
[Nnum Nden] = numden(xp*ypp-yp*xpp);
Nden = factor(Nden)
Nnum = simple(Nnum)
[Dnum Dden] = numden(simple(xp^2+yp^2))
Partial answers: Nden = (sin(t)^2 + 3)^3 Nnum = -a^2*cos(t)^2*(cos(t) + 2)^3*(9*cos(t) - 6)
Dnum = a^2*(cos(2*t) + 1)*(9*cos(2*t) - 80*cos(t) + 73) Dden = 4*(cos(t) - 2)^4
At this point, we place these results in standard notation and make a few trigonometric substitutions as follows:
3'2
! =
(sin
3/ 2
(4
3/ 2
3/ 2
(9cos(2t )
80cos(t ) + 73)
3
(b)
syms a t
x = 3*t*a/(1+t^3);
y = x*t;
xp = diff(x,t,1);
xpp = diff(x,t,2);
yp = diff(y,t,1);
ypp = diff(y,t,2);
kn = simple(xp*ypp-yp*xpp);
kd = simple(xp^2+yp^2);
k = simple(kn/kd^(3/2))
Answer: k = (2*a^2)/(3*(t^3 + 1)^2*((a^2*(t^8 + 4*t^6 - 4*t^5 - 4*t^3 + 4*t^2 + 1))/(t^3 + 1)^4)^(3/2))
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.
(c)
syms a t
x = a*(t-tanh(t));
y = a*sech(t);
xp = diff(x,t,1);
xpp = diff(x,t,2);
yp = diff(y,t,1);
ypp = diff(y,t,2);
kn = simple(xp*ypp-yp*xpp);
kn = subs(kn, cosh(t)^2 - 1, sinh(t)^2);
kd = collect(simple(xp^2+yp^2), a);
kd = subs(kd,1 - 1/cosh(t)^2, sinh(t)^2/cosh(t)^2);
kd = subs(kd, (1/cosh(t)^2)-1, -sinh(t)^2/cosh(t)^2);
k = simple(kn/kd^(3/2))
Answer: k = (a^2*sinh(t)^2)/(cosh(t)^3*((a^2*sinh(t)^2)/cosh(t)^2)^(3/2))
1.34
(a)
z = vpa('cos(pi*cos(pi*cos(log(pi+20))))+1', 40)
Answer: 0.000000000000000000000000000000000039321609261272240194541
(b)
z = vpa('exp(pi*sqrt(163))', 35)
Answer: z = 262537412640768743.99999999999925007
1.35
syms x
tay1 = taylor(x*(7*x+1)/(1-x)^3, 5, x, 0)
tay2 = taylor((1+x-sqrt(1-6*x+x^2))/4,5,x,0)
tay3 = taylor(2*x/(1-x)^3,5,x,0)
tay4 = taylor(x*(x^2+4*x+1)/(1-x)^3,5,x,0)
Answers: tay1 = 52*x^4 + 27*x^3 + 10*x^2 + x
tay2 = 11*x^4 + 3*x^3 + x^2 + x
tay3 = 20*x^4 + 12*x^3 + 6*x^2 + 2*x
tay4 = 37*x^4 + 19*x^3 + 7*x^2 + x
1.36
syms x n e a t
L1 = limit((x^e-1)/e, e, 0)
L2 = limit((1-sin(2*x))^(1/x), x, 0)
L3 = limit(((exp(t)-1)/t)^(-a), t, 0)
L4 = limit(log(x^n)/(1-x^2), x, 1)
Answers: L1 = log(x)
L2 = 1/exp(2)
L3 = 1 L4 = -n/2
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.
1.37
syms s t
rD = roots(sym2poly(s^4+0.282*s^3+4.573*s^2+0.4792*s+2.889));
rN = roots(sym2poly(0.1*s^3+0.0282*s^2-0.0427*s+0.0076));
Xt = vpa(ilaplace(((s-rN(1))*(s-rN(2))*(s-rN(3)))/((s-rD(1))*(s-rD(2))*(s-rD(3))*(s-rD(4))), s, t),5)
Answer: Xt = (1.3974*(cos(1.9456*t)+0.050033*sin(1.9456*t)))/exp(0.097401*t)(0.39736*(cos(0.87145*t)+0.049799*sin(0.87145*t)))/exp(0.043599*t)
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.
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
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(1:2:7)
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
qmax = 330 qmin = 1
44522 111024]
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
4 2 4
1 3 1
4 2 4
wb = % or wbd
1 3
4 2
1 3
4 2
1 3
4 2
wc = % or wcd
1 3 1
4 2 3
1 3 1
4 2 3
1 3 1
4 2 3
3
2
3
2
4
2
4
2
4
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
4
8
5
9
1
7
2
6
8
3
4
1
5
9
(b)
x = magic(3)
t = x(:,3);
x(:,2:3) = x(:,1:2);
x(:,1) = t;
x
Answers: x =
6
7
2
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
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
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
1.5
0.5
0
-1
-1
-2
-0.5
-1.5
-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
91.7751642291914
12.9244097924593
4.40350416999114
2.15691498449604
10002.1644456719
91.7752044040698
12.9244499673344
4.40354434485533
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.352834028615638
0.114903484931901
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.364128145852073
0.0465651162777518
-0.242873209960186
0.486091260585891
0.364128145852073
0.0465651162777523
-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 = 1:2: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
1
0
0
0
0
1
0
0
orthq =
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.
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 = 1:2:401;
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 = 2:2:106;
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 = 1:2:105;
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.
2.33
a = sqrt(3); n = 1:25;
t = (10:10:80)*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 = (1:2:51)*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
1
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
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
0
-2
-4
1
0.9
0.8
0.7
2
0.6
0.5
1.5
0.4
1
0.3
0.2
0.5
0.1
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.0333 -0.1500
0.3875 -0.1000
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.
Solution to Exercises
Chapter 3
3.1
ft = input('Enter the value of length in feet: ');
disp([num2str(ft) ' ft = ' num2str(ft*0.3048) ' m'])
Answer: Enter the value of length in feet: 11.4
11.4 ft = 3.4747 m
3.2
acre = input('Enter the number of acres: ');
disp([num2str(acre) ' acres = ' num2str(acre*43560*0.092903) ' sq. m'])
Answer: Enter the number of acres: 2.4
2.4 acres = 9712.4512 sq. m
3.3
Decimal = input('Enter a positive integer < 4.5x10^15: ');
disp(['The binary representation of ' num2str(Decimal) ' is ' num2str(dec2bin(Decimal))])
Answer: Enter a positive integer < 4.5x10^15: 37
The binary representation of 37 is 100101
3.4
R = input('Enter the real part of a complex number: ');
I = input('Enter the imaginary part of a complex number: ');
z = complex(R,I);
disp(['The magnitude and phase of ' num2str(z) ' is'])
disp(['Magnitude = ' num2str(abs(z)) ' Phase angle = ' num2str(angle(z)*180/pi) ' degrees'])
Answer: Enter the real part of a complex number: -7
Enter the imaginary part of a complex number: 13
The magnitude and phase of -7+13i is
Magnitude = 14.7648 Phase angle = 118.3008 degrees
3.5
n = 0:15;
f = (((1+sqrt(5))/2).^n-((1-sqrt(5))/2).^n)/sqrt(5);
disp([repmat('F', length(n),1) num2str(n',2) repmat(' = ', length(n),1) num2str(f')])
% or
fprintf(1, 'F%2.0f = %3.0f \n', [n;f])
Answers: F 0 = 0
F1= 1
F2= 1
F3= 2
F15 = 610
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.
3.6
n = 9:-1:2; L = length(n);
A = [repmat('cos(pi/', L, 1) int2str(n') repmat(') = ', L, 1) num2str(cos(pi./n'),'%1.5f')]
B = [repmat(' pi/', L, 1) int2str(n') repmat(' = ', L, 1) num2str(180./n','%2.1f') repmat(' degrees',L,1)]
disp([A B])
fprintf(1,'cos(pi/%1.0f) = %1.5f pi/%1.0f = %2.1f degrees\n', [n; cos(pi./n); n; 180./n])
Answer: cos(pi/9) = 0.93969
cos(pi/8) = 0.92388
cos(pi/7) = 0.90097
cos(pi/6) = 0.86603
cos(pi/5) = 0.80902
cos(pi/4) = 0.70711
cos(pi/3) = 0.50000
cos(pi/2) = 0.00000
3.7
Mon ={'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', ...
'September', 'October', 'November', 'December'};
Srt = char(sort(Mon));
disp([Srt(1:6,:) repmat(' ',6,1) Srt(7:12,:)])
Answer: April
June
August
March
December May
February November
January
October
July
September
3.8
N = input('Enter an integer < 12: ');
n = 1:N;
disp(' ')
disp([repmat('For n = ', N, 1) int2str(n') repmat(', ', N, 1) int2str(n') repmat('! = ', N, 1) int2str(factorial(n)')])
disp(' ')
disp(['The sum of these ' int2str(N) ' factorials = ' int2str(sum(factorial(n)))])
Answer: Enter an integer < 12: 4
For n = 1,
For n = 2,
For n = 3,
For n = 4,
1! = 1
2! = 2
3! = 6
4! = 24
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.
Solution to Exercises
Chapter 4
4.1
day = char('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
nonleapyear = [31 28 31 30 31 30 31 31 30 31 30 31];
leapyear = [31 29 31 30 31 30 31 31 30 31 30 31];
datee = input('Enter month, day and year in the form xx/xx/xxxx for 2010, 2011, or 2012: ','s');
f = findstr(datee,'/');
monthno = str2num(datee(1:f(1)-1));
dayno = str2num(datee(f(1)+1:f(2)-1));
yearno = str2num(datee(f(2)+1:f(2)+4));
if yearno == 2010
offse t= 5;
nodaypermonth = nonleapyear;
elseif yearno == 2011
offset = 6;
nodaypermonth = nonleapyear;
elseif yearno == 2012
offset = 7;
nodaypermonth = leapyear;
else
error('Not programmed for this year')
end
if monthno>1
dayofyear = sum(nodaypermonth(1:monthno-1))+dayno;
else
dayofyear = dayno;
end
dayofweek = offset+dayofyear-fix(dayofyear/7)*7;
if dayofweek>7
dayofweek = dayofweek-7;
end
disp(['The date ' datee(1:f(2)+4) ' is the ' num2str(dayofyear) ' day of the year and falls on a '
deblank(day(dayofweek,: )) '.'])
Answer: Enter month, day and year in the form xx/xx/xxxx for 2010, 2011, or 2012: 08/31/2011
The date 08/31/2011 is the 243 day of the year and falls on a Wednesday.
4.2
dat = [45 38 47 41 35 43]; L = length(dat);
vvar = zeros(L,1);
for n = 2:L
vvar(n) = var(dat(1:n));
end
disp([repmat('var(n=', L-1, 1) int2str((2:L)') repmat('): ', L-1,1) num2str(vvar(2:L),4)])
Answer: var(n=2): 24.5
var(n=3): 22.33
var(n=4): 16.25
var(n=5): 24.2
var(n=6): 19.9
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.
4.3
m = 6; N = 100; Lend = (N-m+1);
a = 5*(1+rand(N,1));
A = zeros(Lend,1);
Avg(1) = mean(a(1:m));
for k = 2:Lend
Avg(k) = Avg(k-1)+(a(m+k-1)-a(k-1))/m;
end
plot(1:Lend, Avg, 'ks-')
Answer:
8.5
7.5
6.5
6
0
10
20
30
40
50
60
70
80
90
100
4.4
xold = 1.5; fx = 1; cnt = 0;
while fx>1e-8
xnew = xold-(cos(xold)+sin(xold))/(-sin(xold)+cos(xold));
fx = abs(cos(xnew)+sin(xnew));
cnt = cnt+1;
xold = xnew;
end
disp(['At x = ' num2str(xold,8) ', f(x) = ' num2str(fx) ' after ' int2str(cnt) ' iterations'])
Answer: At x = 2.3561945, f(x) = 1.1102e-016 after 4 iterations
4.5
ir = 0.045; P = 250000; A = 25000;
disp('Principal Annuity Interest No. Remain')
disp(' ($)
($/yr)
(%)
years
($)')
R = P-A; n = 1;
while R>A
n = n+1;
R = R*(1+ir)-A;
end
disp([num2str(P,6) blanks(6) num2str(A,5) blanks(8) num2str(ir*100,3) blanks(9) num2str(n,3) blanks(6)
num2str(R,5)])
Answer: Principal Annuity Interest
No.
Remain
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.
($)
250000
($/yr)
25000
(%)
4.5
years
12
($)
19112
4.6
alp = pi/4; tol = 1e-5;
ao = 1; bo = cos(alp); co = sin(alp);
while abs(co)>tol
an = (ao+bo)/2;
bn = sqrt(ao*bo);
co = (ao-bo)/2;
ao = an;
bo = bn;
end
format long e
Kalp = pi/ao/2
K = ellipke(sin(alp)^2)
format short
Answers: Kalp = 1.854074677301372e+000 K = 1.854074677301372e+000
4.7
h = [1 3 6 -7 -45 12 17 9];
a = 3; b=13; n = zeros(length(h),1);
for k = 1:length(h)
if h(k)<=a||h(k)>=b
n(k) = 0;
else
n(k) = 1;
end
end
disp(['n = ' int2str(n')])
Answer: n = 0 0 1 0 0 1 0 1
4.8
N = input('Enter a positive integer < 10: ');
h = zeros(N,N);
for m = 1:N
for n = 1:N
if (n+m-1) <= N
h(n, m) = n+m-1;
end
end
end
disp(h)
Answer: Enter a positive integer < 10: 4
1 2 3 4
2 3 4 0
3 4 0 0
4 0 0 0
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.
4.9
num = 1.5;
while (num < 1)||(num> 19)||(rem(num,1)~=0)
num = input(' Enter any integer from 1 to 19: ');
end
4.10
x = zeros(1000,1);
x(1) = 3; cnt = 1;
while x(cnt)~=1
cnt = cnt+1;
if rem(x(cnt-1), 2) > 0
x(cnt) = 3*x(cnt-1)+1;
else
x(cnt) = x(cnt-1)/2;
end
end
disp(['x = ' num2str(x(1:cnt)')])
Answer: x = 3 10 5 16 8 4 2 1
4.11
x(1) = 0; n = 201;
x = zeros(n,1);
for k = 2:n
x(k) = x(k-1)^2+0.25;
end
plot(0:5:n-1, x(1:5:n), 'ks')
m = 1; xw(1) = 0;
xw = zeros(201, 1);
while m<201
xw(m+1) = xw(m)^2+0.25;
m = m+1;
end
figure(2)
plot(0:5:m-1, xw(1:5:m), 'ks')
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 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.
0.5
0.45
0.4
0.35
0.3
0.25
0.2
0.15
0.1
0.05
0
0
20
40
60
80
100
120
140
160
180
200
4.12
a = 7; x = [3 100];
for k=1:2
xold = x(k); test = 1; cnt = 0;
while test>1e-6
xnew = 0.5*(xold+a/xold);
test = abs(xnew-xold);
xold = xnew;
cnt = cnt+1;
end
disp(['For xo = ' int2str(x(k)) ' the number of iterations = ' num2str(cnt)])
end
Answers: For xo = 3 the number of iterations = 4
For xo = 100 the number of iterations = 10
4.13
for k = 1:3
switch k
case 1
p=[1 2 3 4]; s = [10 20 30 40];
case 2
p = [11 12 13 14]; s = [101 102];
case 3
p = [43 54 55]; s = [77 66 88 44 33];
end
n = length(p);
m = length(s);
d = n-m;
if d==0
h = p+s
elseif d<0
h = [s(1:-d) p+s(-d+1:m)]
else
h = [p(1:d) s+p(d+1:n)]
end
end
Answers: h = 11
22
33
44
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.
h = 11
h = 77
12 114 116
66 131 98 88
4.14
a = [1.45, 2.75, 3.2, 4]; N = 200;
for k = 1:length(a)
xold = 0.1; cnt = 1; test = 1;
while (test>1e-4)
cnt = cnt+1;
xnew = xold*a(k)*(1-xold);
test = abs((xnew-xold)/xnew);
xold = xnew;
if cnt>N
break
end
end
disp(['For a = ' num2str(a(k)) ', x(n=' int2str(cnt) ') = ' num2str(xold)])
end
Answers: For a = 1.45, x(n=19) = 0.31031
For a = 2.75, x(n=31) = 0.63634
For a = 3.2, x(n=201) = 0.51304
For a = 4, x(n=201) = 0.08737
4.15
Nu = 10;
for k = 1:2
test = -1;
while test < 0
NM(k) = input(['Enter a positive integer<' int2str(Nu) ': ']);
if (NM(k) < 1)||(NM(k)> Nu)||(rem(NM(k),1)~=0)
else
test = 1;
Nu = NM(k)^2+1;
end
end
end
N = NM(1)
M = NM(2)
Answer: Enter a positive integer<10: -1
Enter a positive integer<10: 14
Enter a positive integer<10: 3.6
Enter a positive integer<10: 8
Enter a positive integer<65: 0.5
Enter a positive integer<65: 66
Enter a positive integer<65: 45.03
Enter a positive integer<65: 38
N = 8 M = 38
4.16
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.
for k = 1:3
xon = [];
eon = [];
switch k
case 1
xo=[1 7 8 6 5 7 3 5 4];
eo=[2 6 10 4 3 6 1 2 3];
case 2
xo=[7 11 13 6];
eo=[6 10 15 7];
case 3
xo=[3 14 20 25 14 6 2 0 1 0];
eo=[4 12 19 19 14 8 4 2 1 1];
end
cutoff = 5; n = 1; nend = length(eo); cnt = 1;
while n<= nend
z = cumsum(eo(n:nend));
zx = cumsum(xo(n:nend));
ind = find(z<cutoff);
mxind = max(ind);
if max(ind) > 0
if n+mxind<= nend
eon(cnt) = z(mxind+1);
xon(cnt) = zx(mxind+1);
else
eon(cnt-1) = eon(cnt-1)+z(mxind);
xon(cnt-1) = xon(cnt-1)+zx(mxind);
end
n = n+mxind+1;
else
eon(cnt)=eo(n);
xon(cnt)=xo(n);
n=n+1;
end
cnt=cnt+1;
end
disp(['Case ' int2str(k)])
ve = eon(1:length(eon));
vx = xon(1:length(eon));
x2 = sum((vx-ve).^2./ve);
disp(['e = ' num2str(ve) ' x = ' num2str(vx) ' chi^2 = ' num2str(x2)])
end
Answers: Case 1
e = 8 10 7 6 6 x = 8 8 11 7 12 chi^2 = 8.8524
Case 2
e = 6 10 15 7 x = 7 11 13 6 chi^2 = 0.67619
Case 3
e = 16 19 19 14 8 8 x = 17 20 25 14 6 3 chi^2 = 5.6349
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.
Solution to Exercises
Chapter 5
5.1
Dod = [6 3 2 1.5 1.2 1.1 1.07 1.05 1.03 1.01];
c = [.88 .89 .91 .94 .97 .95 .98 .98 .98 .92];
a = [.33 .31 .29 .26 .22 .24 .21 .20 .18 .17];
Kspline = spline(Dod, c, Dod).*((Dod-1)/2).^-spline(Dod, a, Dod);
Kpoly = polyval(polyfit(Dod, c, 5), Dod).*((Dod-1)/2).^-polyval(polyfit(Dod, a, 5), Dod);
Kt = c.*((Dod-1)/2).^-a;
disp('
Kt
Kspline Kpoly')
disp([Kt' Kspline' Kpoly'])
Answers:
Kt
Kspline
0.6504 0.6504
0.8900 0.8900
1.1126 1.1126
1.3479 1.3479
1.6098 1.6098
1.9497 1.9497
1.9814 1.9814
2.0495 2.0495
2.0870 2.0870
2.2645 2.2645
Kpoly
0.6504
0.8900
1.1135
1.3369
1.6970
1.8546
1.9221
1.9886
2.1037
2.4324
5.2
function Exercise5_2
N = 2^10; wn = 2*pi*[5, 9, 9.4, 20];
dT = 2*pi/wn(end)/4; T = N*dT; df = 1/T;
t = (0:N-1)*T/N;
NHSignal = foft(t, N, wn);
whamm = 0.54-0.46*cos(2*pi*t/T);
k1 = sum(whamm.*NHSignal)/sum(whamm);
k2 = sqrt(N/sum(whamm.^2));
HSignal = whamm.*(NHSignal-k1)*k2;
subplot(2,1,1)
ft = fft(NHSignal, N);
Sig = 2*abs(ft(1:N/2))/N;
plot((0:N/2-1)*df, Sig)
temp = [1 find(diff(Sig)<=0)]; % add 1 because diff shifts array down 1
temp1 = find(diff(temp)~=1);
freqpeak = temp(temp1+1)*df;
An = abs(ft)/N;
disp([' Average power = ' num2str(sum(An.^2))])
disp([' Peaks occur at ' num2str(freqpeak) ' Hz'])
subplot(2,1,2)
ft = fft(HSignal, N);
Sig = 2*abs(ft(1:N/2))/N;
plot((0:N/2-1)*df,Sig)
An = abs(ft)/N;
disp([' Average power = ' num2str(sum(An.^2))])
temp = [1 find(diff(Sig)<=0)];
temp1 = find(diff(temp)~=1); % add 1 because diff shifts array down 1
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.
freqpeak = temp(temp1+1)*df;
disp([' Peaks occur at ' num2str(freqpeak) ' Hz'])
function NHSignal = foft(t, N, wn)
x = [0.1, 0.04, 0.04, 0.03];
Ho = [1 1.3 1.3 1.8];
NHSignal = 0;
for k = 1:length(x)
NHSignal = NHSignal+Ho(k)*Hw(t,wn(k),x(k));
end
function hw = Hw(t, wn, x)
hw = exp(-x*wn*t).*sin(sqrt(1-x^2)*wn*t);
Answers: Average power = 0.07529
Peaks occur at 4.84375
9.14063
Average power = 0.0013038
Peaks occur at 4.92188
9.0625
20.0781 Hz
9.45313
20.0781 Hz
0.07
0.06
0.05
0.04
0.03
0.02
0.01
0
10
15
20
25
30
35
40
10
15
20
25
30
35
40
0.01
0.008
0.006
0.004
0.002
0
5.3
sx = 100; sy = -60; sz = 80; txy = -40; tyz = 50; tzx = 70;
c2 = sx+sy+sz;
c1 = txy^2+tyz^2+tzx^2-sx*sy-sy*sz-sz*sx;
c0 = sx*sy*sz+2*txy*tyz*tzx-sx*tyz^2-sy*tzx^2-sz*txy^2;
ps = sort(roots([1 -c2 -c1 -c0]), 'descend')
t12 = 0.5*(ps(1)-ps(2))
t23 = 0.5*(ps(2)-ps(3))
t13 = 0.5*(ps(1)-ps(3))
Answers: ps = 160.7444 54.8980 -95.6424 t12 = 52.9232 t23 = 75.2702 t13 = 128.1934
Rt = zeros(Nroot, 1);
for k = 1:Nroot
Rt(k) = fzero(FunName, [x(indx(k)), x(indx(k)+1)], [], w);
end
5.4
Ex4 = @(x) (sin(x)-x.*cos(x))
Rt = FindZeros(Ex4, 5, linspace(0,10*pi,100), [])
Answers: Rt = 4.4934
5.5
Ex5 = @(x,p) (2*cos(x)-(x/p-p./x).*sin(x));
p = [0.1 1];
for k = 1:2
Rt = FindZeros(Ex5, 5, linspace(0,10*pi,100), p(k))'
end
Answers: Rt =
Rt =
0.4435 3.2040
1.3065 3.6732
6.3149
6.5846
9.4460 12.5823
9.6317 12.7232
5.6
Ex6 = @(x,b) (besselj(0,x).*bessely(0,b*x)-besselj(0,b*x).*bessely(0,x));
Rt = FindZeros(Ex6, 5, linspace(0,10*pi,100), 2)'
Answers: Rt = 3.1230
6.2734
5.7
Ex7 = @(x, m) (m*x.*(cos(x).*sinh(x)-sin(x).*cosh(x))+cos(x).*cosh(x)+1);
m = [0, 0.2, 1];
for k = 1:3
Rt = FindZeros(Ex7, 5, linspace(0,10*pi,100), m(k));
disp(['m = ' num2str(Rt')])
end
Answers: m = 0: 1.8751
4.69409
7.85476
10.9955
14.1372
m = 0.2: 1.6164
4.26706
7.31837 10.4016
13.5067
m = 1: 1.24792
4.03114
7.13413
10.2566
13.3878
5.8
Ex8 = @(x,w) (cos(x).*tanh(x)-sin(x));
Rt = FindZeros(Ex8, 5, linspace(0,10*pi,100), [])'
Answers: Rt = 3.9266 7.0686 10.2102 13.3518 16.4934
5.9
Ex9 = @(x,m) (besselj(m,x).*besseli(m+1,x)+besseli(m,x).*besselj(m+1,x));
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.
for m = 0:2
Rt = FindZeros(Ex9, 3, linspace(0,10*pi,100), m);
disp(['m = ' int2str(m) ': ' num2str(Rt')])
end
Answers: m = 0: 3.1962
m = 1: 4.6109
m = 2: 5.90568
6.3064
9.4395
7.79927
10.9581
9.19688
12.4022
5.10
Ex10 = @(x,L2) (sin(x)-(x-4*x.^3/L2).*cos(x));
L2 = [2, 4, 8]*pi^2;
for k = 1:3
Rt = FindZeros(Ex10, 1, linspace(0,2*pi,100), L2(k));
disp(['(Lambda/pi)^2 = ' int2str(L2(k)/pi^2) ': ' num2str(Rt')])
end
Answers: (Lambda/pi)^2 = 2: 2.5185
(Lambda/pi)^2 = 4: 3.1416
(Lambda/pi)^2 = 8: 3.8834
5.11
channel = inline('(1+c(1)*x).^2.*(x.^2-x.^3)-c(2)','x','c');
c0 = [0.4, 7]; c1 = [0.2, 4];
for k = 1:length(c0)
r = roots([-c0(k)^2 c0(k)^2-2*c0(k) 2*c0(k)-1 1 0 -c1(k)]);
val = r(find((real(r)>0)&(real(r)<1)));
disp(['c0 = ' num2str(c0(k)) ' c1 = ' num2str(c1(k))])
disp(['From roots: ' num2str(sort(val'))])
Rt = FindZeros(channel, 2, linspace(0,1,30), [c0(k), c1(k)])';
disp(['From fzero: ' num2str(Rt)])
end
Answers: c0 = 0.4 c1 = 0.2
From roots: 0.54385
From fzero: 0.54385
c0 = 7 c1 = 4
From roots: 0.60777
From fzero: 0.60777
0.84226
0.84226
0.91168
0.91168
5.12
wavechannel = inline('2*(t(2)*sin(beta).*tan(beta-t(1))).^2-tan(beta).*tan(beta-t(1))-tan(beta).^2','beta','t');
w = [35*pi/180, 5];
Rt = FindZeros(wavechannel, 2, linspace(w(1), pi/2-0.05,40), w)'*180/pi
Answers: Rt = 48.1088 81.7999
5.13
weibullbeta = inline('b-1/(sum(x.^b.*log(x))/sum(x.^b)-sum(log(x))/length(x))', 'b', 'x');
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.
x = [72 82 97 103 113 117 126 127 127 139 154 159 199 207];
beta = fzero(weibullbeta, [2 4], [], x)
Answer: beta = 3.6437
5.14
bearingstress = inline('x.*log(sqrt(x.^2-1)+x)-sqrt(x.^2-1)-c*x', 'x', 'c');
r = fzero(bearingstress, [1 4], [], 0.5)
Answer: r = 2.1155
5.15
jeffcooper = inline('x.^4-2.^x', 'x','w');
Rt = FindZeros(jeffcooper, 3, linspace(-2, 20, 100), [])
Answers: Rt = -0.8613
1.2396 16.0000
5.16
function Exercise5_16
format long e
Zi = zstanford(1,1)
Zii = zstanford(1/0.3,1)
Ziii = zstanford(2.5,0.5)
format short
% (b)
p = 0.6; t = 1/1.05; trecip = 1.05;
r = fzero(@pvrtr, 5, [], p, t);
z = zstanford(r,t);
disp(['p = ' num2str(p) ' 1/tau = ' num2str(trecip) ' r = ' num2str(r) ' Z = ' num2str(z)])
p = 2.18; t = 1/1.2; trecip = 1.2;
r = fzero(@pvrtr, 5, [], p, t);
z = zstanford(r, t);
disp(['p = ' num2str(p) ' 1/tau = ' num2str(trecip) ' r = ' num2str(r) ' Z = ' num2str(z)])
% (c)
p = 0.6; r = 1/1.4; rrecip = 1.4;
t = fzero(@pvrtt, 0.8, [], p, r);
z = zstanford(r,t);
disp(['p = ' num2str(p) ' 1/r = ' num2str(rrecip) ' t = ' num2str(t) ' Z = ' num2str(z)])
p = 2.18; r = 1/0.6; rrecip = 0.6;
t = fzero(@pvrtt, 0.8, [], p, r);
z = zstanford(r,t);
disp(['p = ' num2str(p) ' 1/r = ' num2str(rrecip) ' t = ' num2str(t) ' Z = ' num2str(z)])
function z = zstanford(rr, tt)
a = [0.062432384 0.12721477 -0.93633233 0.70184411 -0.35160896 0.056450032 ...
0.0299561469907 -0.0318174367647 -0.0168211055516 1.6020406008 ...
-0.001099967407467 -0.000727155024312992 -0.0045245465261 0.001304687241 ...
-0.00022216512840926 -0.0019814053565598 5.9757397292e-5 -3.6413534970217e-6 ...
8.413648453856e-6 -9.828688588219e-9 -1.57683056810249 0.040072898890756 ...
-0.08451944938128 -0.003409313119283 -0.0019512704990109 4.938999109783e-5 ...
-4.9326461293046e-5 8.856665723816e-7 5.347880295527e-8 -5.934205591923e-8 ...
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.
5.17
function Exercise5_17
re = 100000; dk = [200, 200000];
for n =1:2
lambda = fzero(@pipefrictioncoeff, [.008 .08], [], re, dk(n));
disp(['Re = ' num2str(re) ' d/k = ' num2str(dk(n)) ': lambda = ' num2str(lambda)])
end
function x = pipefrictioncoeff(el, re, dk)
if (dk>100000)||(dk==0)
x = el-(2*log10(re*sqrt(el)/2.51))^-2;
else
x = el-(2*log10(2.51/re/sqrt(el)+0.27/dk))^-2;
end
Answers: Re = 100000 d/k = 200: lambda = 0.031298
Re = 100000 d/k = 200000: lambda = 0.01799
5.18
rts = roots([10 0 0 -75 0 -190 21]);
rr = rts(find(imag(rts)==0))'
Answer: rr = 2.2323
0.1100
5.19
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.
5.20
function Exercise5_20
tto = fzero(@Tto, [0.2 0.9])
function t = Tto(x)
t = Thq(exp(-x*pi^2))-pi/2/sqrt(5);
function qq = Thq(q)
k = 0:10;
qq = 2*q^(1/4).*sum((-1).^k./(2*k+1).*q.^(k.*(k+1)));
Answer: tto = 0.4240
5.21
fx =@(x) (x-(1+1./x).^x);
r = fzero(fx, [0 10])
Anwser: r = 2.2932
5.22
are = inline('sin(x)-0.5*abs(sin(2*x))', 'x');
x = linspace(0, pi);
aret = trapz(x, are(x))
areq = quadl(are, 0, pi)
Answers: aret = 0.9999
areq = 1.0000
5.23
bearing = inline('(1-(1-cos(x))/2/epsilon).^c.*cos(m*x)', 'x', 'c', 'm', 'epsilon');
m = 1; epsilon = 0.6;
c = 1.5; a = acos(1-2*epsilon);
Im = quadl(bearing, -a, a, [], [], c, m, epsilon)/2/pi
Answer: Im = 0.2416
5.24
Ee = inline('C1./lam.^5./(exp(C2./(lam*T))-1)', 'lam', 'C1', 'C2', 'T');
C1 = 3.742e8;
C2 = 1.439e4;
sig = 5.667e-8;
T = [300 400 500];
for k=1:length(T)
App = quadl(Ee, 1, 200, [], [], C1, C2, T(k));
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.
exact = sig*T(k)^4;
err = 100*(exact/App-1);
disp(['T = ' num2str(T(k)) ' exact = ' num2str(exact) ' Approx. = ' num2str(App) ' %error = ' num2str(err)])
end
Answers: T = 300 exact = 459.027 Approx. = 458.7468 %error = 0.061087
T = 400 exact = 1450.752 Approx. = 1450.3993 %error = 0.024315
T = 500 exact = 3541.875 Approx. = 3541.4894 %error = 0.010889
5.25
arg = @(x,y) (cos(x-y).*exp(-x.*y/pi^2));
Z = dblquad(arg, 0, pi/2, pi/4, pi)
Answer: Z = 0.8449
5.26
arg = @(x) (1./sqrt((6-x.^2)));
Z = quadl(arg, 2, sqrt(6))-acot(sqrt(2))
Answer: Z = 1.3216e-006
5.27
function Exercise5_27
Om = pi*[0.5969, 1.4942, 2.5002, 3.5:9.5];
Cn = -T(Om)./Q(Om);
N = zeros(10,1);
for n=1:10
N(n) = quadl(@W, 0, 1, [], [], Om(n), Cn(n));
end
disp(['N = ' num2str(N',4)])
function w = W(x, Om, Cn)
w = (Cn*T(Om*x)+S(Om*x)).^2;
function q = Q(x)
q = 0.5*(cosh(x)+cos(x));
function s = S(x)
s = 0.5*(cosh(x)-cos(x));
function t = T(x)
t = 0.5*(sinh(x)+sin(x));
Answers: N = 0.6133 0.3546 0.3137 0.2955 0.2854 0.2789 0.2745 0.2712 0.2687 0.2668
5.28
function Exercise5_28
g = 9.8; alpha = 45*pi/180;
v0 = 180; cd = 0.007;
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.
[x, y] = ode45(@projectile, [0, 300], [v0*cos(alpha) v0*sin(alpha) 0 0]', [], v0, cd, g);
N = length(x);
indx = find(y(:,3)>0);
height = @(v,x,y) (-spline(x,y,v));
opt = optimset('display','off');
xmax = fminbnd(height, 0, 1000, opt, x, y(:,3));
ymax = -height(xmax, x, y(:,3));
disp(['ymax = ' num2str(ymax) ' m at x = ' num2str(xmax) ' m'])
xe = interp1(y(indx(end)-5:N, 3), x(indx(end)-5:N), 0);
te = interp1(y(indx(end)-5:N, 3), y(indx(end)-5:N, 4), 0);
disp(['Travel distance = ' num2str(xe) ' m and time of travel = ' num2str(te) ' s'])
function p=projectile(x, z, v0, cd, g)
v = sqrt(z(1)^2+z(2)^2);
if v<v0*1e-6
error('Initial velocity not large enough. Increase.')
end
p = [-cd*v; -(g+cd*v*z(2))/z(1); z(2)/z(1); 1/z(1)];
Answers: ymax = 137.2577 m at x = 187.8652 m
Travel distance = 280.7721 m and time of travel = 10.353 s
5.29
function Exercise5_29
opt = optimset('display', 'off');
g = 9.8; co = 0.00324;
L = 150; kmj = 10/70;
[t, y] = ode45(@bungee, [0 50], [0 0]', [], g, co, kmj, L);
splinefit = @(td, t, y) (-spline(t, y, td));
maxdisptime = fminbnd(splinefit, 0, 20, opt, t, y(:,1));
maxdisplace = -splinefit(maxdisptime, t, y(:,1));
disp(['Max distance = ' num2str(maxdisplace) ' m at ' num2str(maxdisptime) ' s.'])
slack =@(td, t, y, L) (L-spline(t,y,td));
tL = fzero(slack, [0 10], opt, t, y(:,1), L);
vL = -splinefit(tL, t, y(:,2));
disp(['Diver reaches ' num2str(L) ' m in ' num2str(tL) ' s at at which time the velocity is ' num2str(vL) ' m/s'])
accel = g-sign(y(:,2))*co.*y(:,2).^2-kmj*(y(:,1)-L).*(y(:,1)>=L);
maxacceltime = fminbnd(splinefit, 0, 20, opt, t, -accel);
maxaccel = splinefit(maxacceltime, t, accel);
disp(['Max acceleration = ' num2str(maxaccel) ' m/s^2 (' num2str(maxaccel/9.8) ' g) at ' num2str(maxacceltime)
' s'])
function v = bungee(t, y, g, co, kmj, L)
v = [y(2); g-sign(y(2))*co*y(2)^2-kmj*(y(1)-L)*(y(1)>=L)];
Answers: Max distance = 308.4649 m at 11.4679 s.
Diver reaches 150 m in 5.9875 s at at which time the velocity is 43.4764 m/s
Max acceleration = 12.843 m/s^2 (1.3105 g) at 11.3745 s
5.30
function Exercise5_30
a = 0.1; b = 10.0;
[t, th] = ode45(@IP, linspace(0, 50, 1000), [pi/4 0]', [], b, a);
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.
subplot(2,1,1)
plot(t, th(:,1))
subplot(2,1,2)
plot(th(:,1), th(:,2))
function v = IP(t, y, b, a)
v = [y(2); -a*y(2)+sin(y(1))-b*sin(y(1))*(1-1/sqrt(5-4*cos(y(1))))];
Answer:
1
0.5
-0.5
-1
10
15
20
25
30
35
40
45
50
0.5
-0.5
-1
-0.8
-0.6
-0.4
-0.2
0.2
0.4
0.6
0.8
5.31
function Exercise5_31
p = 0.375; q = 7.43e-4;
Z = [10 50]; zer = zeros(length(Z),1);
for k = 1:2
[t, y] = ode45(@ReservoirOsc, [0 500], [Z(k) 0], [], p, q);
ind = min(find(y(:,1)<0));
zer = interp1(y(ind-5:ind+4,1), t(ind-5:ind+4), 0);
disp(['For Z = ' num2str(Z(k)) ': t = ' num2str(zer) ' s'])
end
function c = ReservoirOsc(t, y, p, q )
c = [y(2); -p*sign(y(2))*y(2)^2-q*y(1)];
Answer: For Z = 10: t = 114.2692 s
For Z = 50: t = 276.1428 s
5.32
function Exercise5_32
fm = fminbnd(@fxi, 0.0, 0.99);
disp(['Minimum xi = ' num2str(fm)])
function f = fxi(xi)
[t, y] = ode45(@minodeoutput, [0 35], [0 0]', [], xi);
f = sum((y(:,1)-1).^2);
function v = minodeoutput(t, w, xi)
v = [w(2); -2*xi*w(2)-w(1)+1];
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.
5.33
function Exercise5_33
e = 0.16; g = 0.4; w = 0.97;
[t, y] = ode45(@tunus, [0, 60], [-1,1], [], e, w, g);
plot(y(:,1), y(:,2),'k-')
function d = tunus(t, z, e, w, g)
c = w*t+9*pi/8;
L = 1+e*sin(c)^7;
Lp = 7*e*w*sin(c)^6*cos(c);
d = [z(2); -((2*Lp/L+g*L)*z(2)+sin(z(1))/L)];
Answer:
1.5
0.5
-0.5
-1
-1
-0.5
0.5
1.5
5.34
function Exercise5_34
a = 0.5; b = 0.6; k = 1;
[t, z] = ode45(@Ray, [0 30],[ 0 0.1], [], a, b, k);
plot(z(:,1), z(:,2), 'k-')
function d = Ray(t, y, a, b, k)
d = [y(2); -k*y(1)+a*y(2)-b*y(2)^3];
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 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.
1.5
0.5
-0.5
-1
-1.5
-1.5
-1
-0.5
0.5
1.5
5.35
function Exercise5_35
uo = 0.05; c = 0.02; r = 1;
w = 0.2; p = 2.01;
pe = fzero(@Static, [0.1, 0.2], [], p);
opt = odeset('RelTol', 0.00001);
[t, ph] = ode45(@Mecha, [0, 800], [pe, 0], opt, uo, c, r, w, p);
plot(t, ph(:,1), 'k-')
hold on
plot(t, uo*sin(w*t)+2*cos(ph(:,1))-2*cos(pe), 'b-')
function g = Mecha(t, y, uo, c, r, w, p)
den = 1/3+(1+2*r*p)*sin(y(1))^2;
g = [y(2); (-(1+2*r*p)*y(2)^2*sin(y(1))*cos(y(1))-(1+r*p)*uo*w^2*sin(y(1))*sin(w*t)...
-2*c*y(2)-2*y(1)+p*sin(y(1)))/den];
function d = Static(h, p)
d = 2*h-p*sin(h);
Answer:
0.3
0.2
0.1
-0.1
-0.2
-0.3
-0.4
0
100
200
300
400
500
600
700
800
5.36
function Exercise5_36
solinit = bvpinit(linspace(0,1,5),[1, 1, 1, -10, 0.91]);
sol = bvp4c(@Exode, @Exbc, solinit);
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.
xx = linspace(0, 1, 50);
yy = deval(sol, xx);
plot(xx,yy(1,:))
hold on
plot(xx, yy(2,:))
plot(xx, yy(3,:))
function res = Exbc(ya,yb)
% y(1) = u, y(2) = v, y(3) = w, y(4) = z, y(5) = y.
res = [ ya(1) - 1; ya(2) - 1; ya(3) - 1; ya(4) + 10; yb(3) - yb(5)];
function dydx = Exode(x,y)
% y(1) = u, y(2) = v, y(3) = w, y(4) = z, y(5) = y.
dydx = [ 0.5*y(1)*(y(3) - y(1))/y(2)
-0.5*(y(3) - y(1))
(0.9 - 1000*(y(3) - y(5)) - 0.5*y(3)*(y(3) - y(1)))/y(4)
0.5*(y(3) - y(1))
100*(y(3) - y(5)) ];
Answer:
2.2
1.8
1.6
1.4
1.2
0.8
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
5.37
function Exercise5_37
LLo = 1.2;
opt = optimset('display','off');
beta = fzero(@cablebeta, 2, opt, LLo);
solinit = bvpinit(linspace(0,1,5), [0.1 0.1]);
sol = bvp4c(@inextcable, @BC, solinit, [], beta);
z = deval(sol, 0);
disp(['beta = ' num2str(beta) ' and the slope at eta = 0 is ' num2str(z(2,1))])
function a = cablebeta(beta, LLo)
solinit = bvpinit(linspace(0,1,5), [0.1 0.1]);
sol = bvp4c(@inextcable, @BC, solinit, [], beta);
eta = linspace(0, 1, 100);
zz = deval(sol, eta);
a = LLo-trapz(eta, sqrt(1+zz(2,:).^2));
function c = inextcable(t, z, beta)
c = [z(2); beta*sqrt(1+z(2)^2)];
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 a13
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.
function r = BC(za,zb,beta)
r = [za(1); zb(1)];
Answer: beta = 2.1297 and the slope at eta = 0 is -1.2778
5.38
function Exercise5_38
qo = 1;
solinit = bvpinit(linspace(0, 1, 10), [0.5, 0.5, 0.5, 0.5]);
beamsol = bvp4c(@BeamODEqo, @CantBC, solinit, [], qo);
eta = linspace(0, 1, 50);
y = deval(beamsol, eta);
subplot(2,2,1)
plot(eta, y(1,:),'k-')
subplot(2,2,2)
plot(eta, y(2,:),'k-')
subplot(2,2,3)
plot(eta, y(3,:),'k-')
subplot(2,2,4)
plot(eta, y(4,:),'k-')
function dydx = BeamODEqo(x, y, qo)
dydx = [y(2); y(3); y(4); qo.*(x>0.5)];
function bc = CantBC(y0, y1, qo)
bc = [y0(1); y0(2); y1(3); y1(4)];
Answer:
0.12
0.2
0.1
0.15
0.08
0.06
0.1
0.04
0.05
0.02
0
0.2
0.4
0.6
0.8
0.4
0.2
0.4
0.6
0.8
0.2
0.4
0.6
0.8
0
-0.1
0.3
-0.2
0.2
-0.3
0.1
-0.4
-0.5
0
0.2
0.4
0.6
0.8
5.39
function Exerxise5_39
Pbar = 8; alph = pi/2;
sw = 0; tol = 0.001;
gl = 157; gh = 158;
qq = fzero(@Shoot, [gl, gh]*pi/180, [], Pbar, alph, sw, tol)*180/pi;
sw = 1;
[r, x] = NLBeam(qq*pi/180, Pbar, alph, sw, tol);
disp(['Pbar = ' num2str(Pbar) ' phi(0) = ' num2str(qq) ' (deg) x(0) = '...
num2str(x(1)), ' y(0) = ' num2str(x(2))])
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 a14
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.
5.40
function Exercise5_40
a = 0.8;
zinfi = fzero(@Eqn, [1.1 4], [], a)
function slop = Eqn(zinf, a)
zin = [zinf 1.05*zinf]; d(1:2) = 0;
for k = 1:2
solinit = bvpinit(linspace(0, zin(k), 5), [0.1, 0.1]);
exmp = bvp4c(@odeQ3, @bcQ3,solinit, [], a);
et = linspace(0, zin(k), 100);
wnew = deval(exmp, et);
slop = wnew(1, end)-0.05;
d(k) = interp1(et, wnew(1,:), 1.1);
end
slop = (d(2)-d(1))/0.05-0.03;
function de = odeQ3(t, y, a)
de = [y(2); -2*t*y(2)/sqrt(1-a*y(1))];
function b = bcQ3(ya, yb, a)
b = [ya(1)-1; yb(1)];
Answer: zinfi = 1.9501
5.41
function Exercise5_41
v = 0.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 a15
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.08
0.05
0.06
0.04
0.03
0.04
0.02
0.02
0.01
0
0.2
0.4
0.6
0.8
0.8
0
0.2
0.4
0.6
0.8
0.4
0.6
0.8
0.5
0
0.6
-0.5
0.4
-1
0.2
-1.5
0
-0.2
0.2
-2
0.4
0.6
0.8
-2.5
0.2
5.42
function Exercise5_42
S = 0.4;
solinit = bvpinit(linspace(0, 1, 10), [0.5, 0.5, 0.5, 0.5]);
beamsol = bvp4c(@BeamODE, @CantileverBC, solinit, [], S);
eta = linspace(0, 1, 50);
y = deval(beamsol, eta);
subplot(2,2,1)
plot(eta, y(1,:),'k-')
subplot(2,2,2)
plot(eta, y(2,:),'k-')
subplot(2,2,3)
plot(eta, y(3,:),'k-')
subplot(2,2,4)
plot(eta, y(4,:),'k-')
function dydx = BeamODE(x, y, S)
dydx = [y(2); y(3); y(4); 1-S*y(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 a16
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.25
0.2
0.15
0.15
0.1
0.1
0.05
0.05
0.2
0.4
0.6
0.8
0.7
0.2
0.4
0.6
0.8
0.2
0.4
0.6
0.8
0.6
-0.2
0.5
0.4
-0.4
0.3
-0.6
0.2
-0.8
0.1
0
-1
0
0.2
0.4
0.6
0.8
5.43
function Exercise5_43
Omguess = pi/2;
gbs = 3.12; Ro = 0.06;
solinit = bvpinit(linspace(0,1,10), @TimoBeamInit, Omguess);
beamsol = bvp4c(@TimoBeamODE, @TimoBeamBC, solinit, [], gbs, Ro);
Omega = beamsol.parameters
function yinit = TimoBeamInit(x)
yinit = [sin(x*pi/2); cos(x*pi/2); -sin(x*pi/2); -cos(x*pi/2)];
function dydx = TimoBeamODE(x, y, Om, gbs, Ro)
dydx = [y(2); y(4)-gbs*Ro^2*Om^4*y(1); y(4); -(y(2)+(gbs*Ro^4*Om^4-1)*y(3))/(gbs*Ro^2)];
function bc = TimoBeamBC(y0, y1, Om, gbs, Ro)
bc = [y0(1); y0(4)-0.05; y0(3); y1(2)-y1(3); y1(4)];
Answer: Omega = 1.8444
5.44
function Exercise5_44
% Part (a)
wormleadmin = @(lambda, b) (b./sin(lambda)+1./cos(lambda));
bt = [0.02, 0.05, 0.08, 0.11, 0.15, 0.18, 0.23, 0.30];
opt = optimset('display','off'); z = zeros(length(bt),1);
for j = 1:length(bt)
z(j )= fminbnd(wormleadmin, pi/180, 40*pi/180, opt, bt(j))*180/pi;
end
disp(' beta
Kmin')
disp([bt' z])
% Part (b)
wormlead = @(lambda, b, k) (k-wormleadmin(lambda,b));
lambda1 = fzero(wormlead, [10 25]*pi/180, opt, 0.16, 1.5)*180/pi
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 a17
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.
beta
Kmin
0.0200 15.1866
0.0500 20.2231
0.0800 23.3098
0.1100 25.6001
0.1500 27.9830
0.1800 29.4501
0.2300 31.4950
0.3000 33.7997
lambda1 = 22.5505
lambda2 = 35.0343
5.45
gasflowtank = inline('-sqrt(k/(k-1))*sqrt(pepo.^(2/k)-pepo.^((k+1)/k))','pepo','k');
opt = optimset('display','off');
k = 1.4;
maxpratio = fminbnd(gasflowtank, 0, 1, opt, k);
maxexact = (2/(k+1))^(k/(k-1));
pepo = linspace(0, 1, 200);
[minarray, index] = min(gasflowtank(pepo,k));
numpratio = pepo(index);
disp(['max ratio exact = ' num2str(maxexact) ' max ratio w/fminbnd = '
num2str(maxpratio) ' max ratio w/min = ' num2str(numpratio)])
Answers: max ratio exact = 0.52828 max ratio w/fminbnd = 0.5283 max ratio w/min = 0.52764
5.46
function Exercsie5_46
opt = optimset('Display', 'off');
sol = fsolve(@functExamp, [1 1 1], opt)
disp(['x = ' num2str(sol(1)) ' y = ' num2str(sol(2)) ' z = ' num2str(sol(3))])
function f = functExamp(x)
f = [sin(x(1))+x(2)^2+log(x(3))-7;
3*x(1)+2^x(2)+1-x(3)^3;
x(1)+x(2)+x(3)-5];
Answers: x = 0.59905 y = 2.3959 z = 2.005
5.47
fs = inline('[b-z(1)*(1-cos(z(2)));a-z(1)*(z(2)-sin(z(2)))]', 'z', 'a', 'b');
a = 1; b = 3;
opt = optimset('Display','off');
r = fsolve(fs, [5 pi/4], opt, a, b);
disp(['k = ' num2str(r(1)) ' theta = ' num2str(r(2)*180/pi) ' degrees'])
fz = inline('b*(th-sin(th))-a*(1-cos(th))', 'th', 'a', 'b');
th = fzero(fz, [pi/4], opt, a, b);
disp(['k = ' num2str(a/(th-sin(th))) ' theta = ' num2str(th*180/pi) ' degrees'])
Answers: k = 6.9189 theta = 55.4999 degrees
k = 6.9189 theta = 55.4999 degrees
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 a18
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.
5.48
QQ = inline('[T1^4-T(1)^4-T(3)/sig; T(1)^4-T(2)^4-T(3)/sig; T(2)^4-T2^4-T(3)/sig]', 'T', 'T1', 'T2', 'sig');
sig = 5.667e-8; T2 = 293; T1 = 373;
opt = optimset('display', 'off');
TQ = fsolve(QQ, [ 300 300 300], opt, T1, T2, sig);
disp('From fsolve:')
disp(['TA = ' num2str(TQ(1)) ' TB = ' num2str(TQ(2)) ' Q = ' num2str(TQ(3))])
% (b)
V = [1, 0, 1/sig; 1, -1, -1/sig; 0, 1, -1/sig] \[T1^4, 0, T2^4]';
disp(' ')
disp('From matrix inversion:')
disp(['TA = ' num2str(V(1)^(1/4)) ' TB = ' num2str(V(2)^(1/4)) ' Q = ' num2str(V(3))])
Answers: From fsolve:
TA = 352.052 TB = 326.5116
Q = 226.4312
Q = 226.4312
5.49
syms x
dfx = diff(exp(sin(x)), x);
xext = solve(dfx, x)
dfxx = limit(diff(dfx,x), x, xext)
Answers: xext = 1/2*PI
dfxx = -exp(1)
5.50
syms x b
Intg = int((2*x+5)/(x^2+4*x+5), x, 0, b)
AofB = matlabFunction(Intg, 'vars', [b])
A = AofB(linspace(0, 4*pi, 10))'
Answers: A =
0
1.0964
1.8252
2.3653
2.7927
3.1459
3.4467
3.7084
3.9401
4.1478
5.51
function Exercise5_51
[AlphMax fAlphaMax] = fminbnd(@(x) (-Integ(x)), 0, 1);
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 a19
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.
5.52
function Exercise5_52
ka = pi/4; v = 0.3; b = 0.05/sqrt(12);
N = 10; rot = zeros(N+1,3);
for meth = 1:3
switch meth
case 1
[C1 C2 C3 C4] = Coef;
for n = 0:N
a11 = ka^2+(1-v)/2*n.^2;
a12 = (1+v)*n*ka/2;
a13 = v*ka;
a23 = n;
a22 = (1-v)/2*ka^2+n.^2;
a33 = 1+b^2*(ka^2+n.^2).^2;
C11 = C1(a11,a12,a13, a22,a23,a33);
C22 = C2(a11,a12,a13, a22,a23,a33);
C33 = C3(a11,a12,a13, a22,a23,a33);
C44 = C4(a11,a12,a13, a22,a23,a33);
rot(n+1,:) = sqrt(roots([C44 C33 C22 C11]));
end
case 2
for n = 0:N
A = MatrixElements(n, ka, b, v);
rot(n+1,:) = sqrt(eig(A));
end
case 3
Nroot = 3;
x = logspace(-2, 1.2, 100);
for n = 0:N
rot(n+1,:) = FindZero(@deter, Nroot, x, [n,ka,b,v]);
end
end
figure(meth)
for m=1:3
semilogy(0:10, rot(:,m), 'ks-' )
hold on
end
axis tight
disp(' ')
disp('
n
L(1,n) L(2,n) L(3,n) ')
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 a20
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.
disp([(0:10)' rot])
end
function [C1 C2 C3 C4] = Coef
syms La a11 a12 a13 a21 a22 a23 a31 a32 a33
A = [-La+a11, a12, a13;
a12, -La+a22, a23;
a13, a23, -La+a33];
DetA = collect(simple(det(A)), La);
C = coeffs(DetA, La);
C1 = matlabFunction(C(1), 'vars', [a11, a12, a13,
C2 = matlabFunction(C(2), 'vars', [a11, a12, a13,
C3 = matlabFunction(C(3), 'vars', [a11, a12, a13,
C4 = matlabFunction(C(4), 'vars', [a11, a12, a13,
function D = deter(La, w)
n = w(1); ka = w(2); b = w(3); v = w(4);
A = MatrixElements(n, ka, b, v);
A(1,1) = A(1,1)-La^2;
A(2,2) = A(2,2)-La^2;
A(3,3) = A(3,3)-La^2;
D = det(A);
function Rt=FindZero(FunName, Nroot, x, w)
cnt = 0; Rt = []; n = 3;
D = zeros(length(x),1);
% Following change required because 'deter' cannot
% deal with an array of values for x
for k = 1:length(x)
D(k) = feval(FunName, x(k), w);
end
for k = 1:length(x)
if sign(D(n))*sign(D(n-1))>0
n=n+1;
else
cnt = cnt+1;
rte = fzero(FunName,[x(n-1),x(n)],[],w);
Rt = [Rt rte];
n = n+2;
end
if n>length(x)-1||cnt==Nroot
break
end
end
function A = MatrixElements(n,ka,b,v)
a11 = ka^2+(1-v)/2*n.^2;
a12 = (1+v)*n*ka/2;
a13 = v*ka;
a23 = n;
a22 = (1-v)/2*ka^2+n.^2;
a33 = 1+b^2*(ka^2+n.^2).^2;
A = [a11, a12, a13; a12, a22, a23; a13, a23, a33];
Answers:
n
0
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 a21
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.
1.0000
2.0000
3.0000
4.0000
5.0000
6.0000
7.0000
8.0000
9.0000
10.0000
10
10
1.5258
2.3405
3.2468
4.1920
5.1566
6.1320
7.1141
8.1004
9.0897
10.0811
0.8883
1.3203
1.8546
2.4212
2.9996
3.5831
4.1693
4.7570
5.3457
5.9351
0.2574
0.1271
0.1433
0.2348
0.3630
0.5213
0.7088
0.9253
1.1706
1.4449
10
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 a22
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.
Solution to Exercises
Chapter 6
6.1
% Cycloid
phi = linspace(-pi, 3*pi, 200);
ra = [0.5, 1, 1.5];
for k = 1:length(ra)
subplot(3,1,k)
plot(ra(k)*phi-sin(phi), ra(k)-cos(phi))
axis equal
title(['r_a = ' num2str(ra(k))])
axis equal off
end
Answer:
ra = 0.5
ra = 1
ra = 1.5
% Leminscate
phi = linspace(-pi/4, pi/4, 101);
plot(cos(phi).*sqrt(2*cos(2*phi)), sin(phi).*sqrt(2*cos(2*phi)))
axis equal off
Answer:
% Archimedean spiral
phi = linspace(0, 6*pi, 200);
plot(phi.*cos(phi), phi.*sin(phi))
axis equal off
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 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.
%Logarithmic spiral
phi = linspace(0, 6*pi, 200); k = 0.1;
plot(exp(k*phi).*cos(phi), exp(k*phi).*sin(phi))
axis equal off
Answer:
% Cardioid
phi = linspace(0, 2*pi, 100);
plot(2*cos(phi)-cos(2*phi), 2*sin(phi)-sin(2*phi))
axis equal off
Answer:
% Astroid
phi = linspace(0, 2*pi, 100);
plot(4*cos(phi).^3, 4*sin(phi).^3)
axis equal off
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 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.
% Epicycloid
en = [2*pi, 4*pi]; r = [3, 2.5]; a = [0.5 2];
for k = 1:2
subplot(1,2,k)
phi = linspace(0, en(k), 200);
rr = r(k); ar = a(k);
plot((rr+1)*cos(phi)-ar*cos(phi*(rr+1)), (rr+1)*sin(phi)-ar*sin(phi*(rr+1)))
axis equal off
end
Answer:
% Hypocycloid
phi = linspace(0, 2*pi, 200);
rr = 3; ar = [0.5, 1, 2];
for k = 1:length(ar)
subplot(1,3,k)
plot((rr-1)*cos(phi)+ar(k)*cos(phi*(rr-1)), (rr-1)*sin(phi)-ar(k)*sin(phi*(rr-1)))
axis equal off
end
Answer:
% Eight curve
ph = linspace(0, 2*pi, 200); a = 2;
plot(a*sin(ph), a*sin(ph).*cos(ph), 'k-')
axis equal off
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.
Answer:
% Butterfly
x = linspace(-1, 1, 201); a = 2;
plot(x, (x.^4-x.^6).^(1/6), 'k-', x, -(x.^4-x.^6).^(1/6), 'k-')
axis equal off
Answer:
% Dumbbell
x = linspace(-1, 1, 200); a = 2;
plot(x, a*sqrt((x.^4-x.^6)), 'k-', x, -a*sqrt((x.^4-x.^6)), 'k-')
axis equal off
Answer:
% Bicuspid
a = 1; x = linspace(-a, a, 200);
rt = @(x,a) sqrt((a^2-x.^2).*(x-a).^2);
plot(x, sqrt(a^2+rt(x,a)), 'k-', x, -sqrt(a^2+rt(x,a)), 'k-')
hold on
A = @(x,a) (a^2-rt(x,a));
xl = fzero(A, -a/2, [], a)
x = linspace(-a, xl, 50);
plot(x, sqrt(a^2-rt(x,a)), 'k-', x, -sqrt(a^2-rt(x,a)), 'k-')
x= linspace(0, a, 50);
plot(x, sqrt(a^2-rt(x,a)), 'k-', x, -sqrt(a^2-rt(x,a)), 'k-')
axis equal off
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 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.
% Super ellipse
a = 2; b = 1; n = [2/3, 3, 7];
for k = 1:3
subplot(1,3,k)
x = [linspace(-a, 0, 100) 0 linspace(0.01, a, 100)];
y = b*(1-abs(x/a).^n(k)).^(1/n(k));
plot(x, y, 'k-', x, -y, 'k-')
axis equal off
end
Answer:
% Gear
n = 12; a = 1; b = 10;
t = linspace(0, 2*pi, 600);
r = a+tanh(b*sin(n*t))/b;
plot(r.*cos(t), r.*sin(t), 'k-')
axis equal off
Answer:
% Folium
th = linspace(0, 2*pi, 100);
a = 2; b = 3;
c = cos(th); s = sin(th);
r = real(sqrt(c.*(4*a*s.^2-b)));
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.
6.2
rts = sort(roots([.001 -.01 -0.2 1 4 -5]), 'ascend');
ind = find((rts>=-12)&(rts<=7));
for k = 1:2:length(ind)
x = linspace(rts(k), rts(k+1), 25);
y = polyval([.001 -.01 -0.2 1 4 -5], x);
plot(x, y, 'k-' )
hold on
end
xlim([-12 7])
xlabel('x')
ylabel('y')
Answer:
70
60
50
40
30
y
20
10
-10
-12
-10
-8
-6
-4
-2
6.3
tho = pi/3; N = 17; del = 1;
x1 = 0:N;
x2 = x1.*del*cos(tho);
y2 = x1.*del*sin(tho);
N = N+1; z = zeros(1,N);
plot(x1, z, 'k-s')
hold on
plot(x2, y2, 'k-s')
plot([x1(2:N); x2(N:-1:2)], [z(N:-1:2); y2(N:-1:2)], 'k-')
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.
6.4
n = input('Enter number of circles (>2): ');
rb = 1.5;
phi = linspace(0, 2*pi);
rs = rb*sin(pi/n)/(1-sin(pi/n));
th = (1:n)*2*pi/n;
plot(rb*cos(phi), rb*sin(phi), 'k', 0, 0, 'k+', (rb+rs)*cos(th), (rb+rs)*sin(th), 'k+')
axis equal
[x, phd] = meshgrid((rb+rs)*cos(th), phi);
y = meshgrid((rb+rs)*sin(th), phi);
hold on
axis off
plot(x+rs.*cos(phd), y+rs.*sin(phd), 'k-')
Answer:
6.5
N = 15000; x = zeros(N,1); y=x;
x(1) = 1; y(1) = 3.65;
for n = 2:N
x(n) = 1-y(n-1)+abs(x(n-1));
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.
y(n) = x(n-1);
end
plot(x, y, 'k.')
axis equal off
Answer:
6.6
eta = linspace(0, 1, 10); phi = linspace(0, 2*pi, 200);
c = cos(phi); s = sin(phi); a = 1.5; N = 4;
for k = 1:length(eta)
D = cosh(eta(k))-c;
x = sinh(eta(k))./D;
y = s./D;
plot(a*x, a*y, 'k-', -a*x, -a*y, 'k-')
hold on
end
phi = linspace(0, 2*pi, 30);
for k = 1:length(phi)
D = cosh(eta)-cos(phi(k));
x = sinh(eta)./D;
y = sin(phi(k))./D;
plot(a*x, a*y, 'k-', -a*x, -a*y, 'k-')
hold on
end
axis equal off
axis([-N N -N N])
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 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.
6.7
A = 2; N = 20;
t = linspace(-pi, pi, 400); T = t(end)-t(1);
signal = A*sin(t); dt = t(2)-t(1);
x = linspace(-A, A, N); dx = x(2)-x(1);
L = zeros(N-1,1);
for k = 1:N-1
Index = find((signal>=x(k))&(signal<x(k+1)));
L(k) = dt*length(Index)/T/dx;
end
xx = x(1:N-1)+dx/2;
xn = [xx(1)-dx/4, xx, xx(end)+dx/4];
exacty = 1/pi./sqrt(A^2-xn.^2);
plot(xx, L, 'ks', xn, exacty, 'k')
xlabel('Amplitude')
ylabel('P(x)')
[ll lo] = legend('Approximate', 'Exact');
Answer:
0.8
Approximate
Exact
0.7
0.6
0.5
)
x
(
P
0.4
0.3
0.2
0.1
-2
-1.5
-1
-0.5
0
Amplitude
0.5
1.5
6.8
h = 1:0.25:3;
d = linspace(0, 5, 100);
[ht, dt] = meshgrid(h, d, 1);
plot(dt, 0.5*dt.^3-1.5*ht.*dt.^2+(1+ht.^2).*dt, 'k')
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.
axis([0 5 0 8])
xlabel('\delta/t')
ylabel('C_1')
dd = 1.2;
pht = 0.5*dd.^3-1.5*h.*dd.^2+(1+h.^2).*dd+.12;
text(repmat(.9, 1, length(h)-1), pht(2:length(h)), num2str(h(2:end)'))
text(.9, pht(end)+.4,'h/t = ')
text(0.9, pht(1)-.4,num2str(h(1)))
Answer:
8
h/t =
3
6
2.75
5
2.5
1
2.25
3
2
1.75
1.5
1.25
1
0
0
0.5
1.5
2.5
/t
3.5
4.5
6.9
function Exercise6_9
rb = 90.21; rt = 106; ts = 14.022;
m = 8; n = 24;
[t, r] = geartoothshape(rb, rt, ts, m, n);
rm = max(r);
subplot(1,2,1)
for k = 0:n-1
polar(t+2*k*pi/n, r/rm)
hold on
end
subplot(1,2,2)
for k = 0:n-1
plot(r.*cos(t+2*k*pi/n), r.*sin(t+2*k*pi/n))
hold on
axis equal off
end
plot(0, 0, '+b')
Answer:
90
120
60
0.5
150
30
180
210
330
240
300
270
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.
6.10
powerscreweff = inline('100*(cos(a)-mu.*tan(lamb))./(cos(a)+mu.*cot(lamb))', 'a', 'lamb', 'mu');
lam = linspace(0.01, pi/2-.01, 100);
mum = [0.02, 0.05:0.05:.25];
[mu, lamb] = meshgrid(mum, lam, 1);
e = powerscreweff(14.5*pi/180, lamb, mu);
plot(lamb*180/pi, powerscreweff(14.5*pi/180, lamb, mu), ...
'-k', lamb*180/pi, powerscreweff(7*pi/180, lamb, mu),'--k')
axis([0 90 0 100])
legend('thread angle = 14.5\circ', 'thread angle = 7\circ', 'Location', 'SouthWest')
xlabel('Lead angle (degrees)')
ylabel('Efficiency (%)')
title('Efficiency of a power screw')
text(repmat(30, 1, length(mum)), powerscreweff(7*pi/180,pi/4,mum)-3,...
[repmat('\mu = ', length(mum),1) num2str(mum')])
Answer:
Efficiency of a power screw
100
= 0.02
90
)
%
(
y
c
n
e
i
c
i
f
f
E
= 0.05
80
= 0.1
70
= 0.15
= 0.2
60
= 0.25
50
40
30
20
10
0
0
10
20
30
40
50
Lead angle (degrees)
60
70
80
90
6.11
L = 1; W = 2; d = 2;
r1 = sqrt(d^2+(W/2)^2);
r2 = sqrt((d+L)^2+(W/2)^2);
alpha = atan(W/(2*d));
beta = atan(W/(2*(L+d)));
Nv = floor(pi/alpha);
Dtheta = 2*pi/Nv;
theta = 0:Dtheta:2*pi-Dtheta;
gama = [-alpha, alpha, beta, -beta];
rad = [r1, r1, r2, r2];
for k = 1:Nv
x = rad.*cos(theta(k)+gama);
y = rad.*sin(theta(k)+gama);
plot([x, x(1)], [y, y(1)], 'k')
hold on
end
plot([zeros(1,Nv); d*cos(theta)], [zeros(1,Nv); d*sin(theta)], 'k')
axis equal off
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 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.
6.12
N = 15; n = 1:N;
Angl = cumsum(atan(1./sqrt(1:N-1)));
Angl = [pi, pi-Angl];
R = sqrt(n);
x = R.*cos(Angl);
y = R.*sin(Angl);
plot(x, y, 'k-')
hold on
plot([zeros(1,N);x], [zeros(1,N);y], 'k-')
axis equal off
ang = [pi/8, Angl(1:N-1)+diff(Angl)/2];
text(x(1)/2, 0, '1', 'VerticalAlignment','bottom')
for k = 2:N
text(x(k)/2, y(k)/2, ['\surd' num2str(k)])
text(R(k).*cos(ang(k)), R(k).*sin(ang(k)), '1', 'HorizontalAlignment','right')
end
Answer:
1
1
1
4
3
1
5
2
6
7
8
9
15
10
14
13
11
12
1
1
1
1
1
6.13
za = linspace(0.01, 3); vu1 = 0.3;
sx = (1-za.*atan(1./za))*(1+vu1)-0.5./(1+za.^2);
sz = 1./(1+za.^2);
plot(za, sx, 'k-', za, sz, 'k--', za, -0.5*(sx-sz), 'k:')
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.
1
sigma x
sigma z
shear
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0
0.5
1.5
depth (z/a)
2.5
6.14
zb = linspace(0.01, 3, 100); nu = 0.3;
sx = 2*nu*(sqrt(1+zb.^2)-zb);
sy = (2-1./(1+zb.^2)).*sqrt(1+zb.^2)-2*zb;
sz = 1./sqrt((1+zb.^2));
plot(zb, sx , 'k-', zb, sz, 'k--', zb, -0.5*(sy-sz), 'k:', zb, sy, 'k-.')
legend('\sigma_x' ,'\sigma_z', '\tau', '\sigma_y')
axis([0, 3, 0, 1])
xlabel('depth (z/b)')
ylabel('Compressive stress and shear')
title('Contact stresses in cylinders as a function of depth')
Answer:
Contact stresses in cylinders as a function of depth
r
a
e
h
s
d
n
a
s
s
e
r
t
s
e
v
i
s
s
e
r
p
m
o
C
0.9
0.8
x
z
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0
0.5
1.5
depth (z/b)
2.5
6.15
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 a13
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.
1.9
0.3
1.8
0.23
1.7
1.6
0.18
1.5
0.15
1.4
0.11
0.08
1.3
0.05
1.2
=
0.02
1.1
Minimum
1
0
10
15
20
25
30
35
40
6.16
function Exercise6_16
dk = [0, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000];
options = optimset('display', 'off');
re = logspace(3.603, 7);
lambda = zeros(length(re),1); label = zeros(length(dk),1);
for k = 1:length(dk)
for r = 1:length(re)
lambda(r) = fzero(@PipeFrictionCoeff,[.008 .08], options, re(r), dk(k));
end
semilogx(re, log10(lambda),'k')
label(k) = lambda(end);
hold on
end
xlabel('Reynolds number')
ylabel('log_{10}(\lambda)')
text(repmat(10^(7+.03), length(dk)-1,1), log10(label(2:end)'), num2str(dk(2:end)'))
text(10^(7+.06), log10(label(1)), '\infty')
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 a14
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.
v = axis;
text(10^(7+.1), v(4), 'd/k')
function x = PipeFrictionCoeff(el, re, dk)
if dk>100000||dk==0
x = el-(2*log10(re*sqrt(el)/2.51))^-2;
else
x = el-(2*log10(2.51/re/sqrt(el)+0.27/dk))^-2;
end
Answer:
-1.1
d/k
20
-1.2
-1.3
50
-1.4
100
-1.5
)
( 0
g1
o
l
200
-1.6
500
-1.7
1000
2000
-1.8
5000
-1.9
10000
20000
-2
-2.1
3
10
50000
100000
10
10
Reynolds number
10
10
6.17
th = 0:pi/90:2*pi;
fill(3.+cos(th), 1.+sin(th), 'g')
axis equal
axis([-2, 5, -5, 4])
hold on
fill([0 4.5 5 5], [-5 4 4 -5], 'r')
plot([-2 5], [0 0], 'k', [0 0], [-5 4], 'k', 1, 1, 'k+')
r = 0.5:.5:3;
plot(1.+cos(th')*r, 1.+sin(th')*r, 'b')
title('Blue circles: function minimized. Green area: feasible region')
xlabel('x_1')
ylabel('x_2')
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 a15
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.
-1
-2
-3
-4
-5
-2
-1
2
x
6.18
t = linspace(0, pi, 200);
s1 = sin(t);
s2 = 0.5*abs(sin(2*t));
plot(t, s1, 'k', t, s2, 'k')
fill([t fliplr(t)], [s1 fliplr(s2)], 'c')
axis([0, pi, 0, 1])
hold on
plot([0, pi], [0.5 0.5], '--k')
Answer:
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0
0.5
1.5
2.5
6.19
phi = linspace(0, 2*pi, 200); N = 2; kd = [0.25, 0.5, 1, 2]*pi;
for k = 1:4
subplot(2,2,k)
polar(phi, sin(2*N*kd(k)*cos(phi))./(2*N*sin(kd(k)*cos(phi))), 'k-')
title(['kd/\pi = ' num2str(kd(k)/pi)])
end
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 a16
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.
kd/ = 0.25
90 1
120
kd/ = 0.5
90 1
60
0.5
150
120
30
180
210
330
240
210
300
330
240
kd/ = 1
90 1
kd/ = 2
90 1
60
0.5
120
30
180
210
330
300
60
0.5
150
270
300
270
120
240
30
180
270
150
60
0.5
150
30
180
210
330
240
300
270
6.20
th = linspace(0, pi, 100); r = 2/3; rad = [2/6, 1/6, 1/2];
c = cos(th); s = sin(th);
a = [rad(1), 2*rad(1)+rad(2), rad(3)];
ch = char('w', 'w', 'g');
for k = 3:-1:1 % Displaying colors is order dependent
fill(a(k)+rad(k)*c, rad(k)*s, ch(k,1))
hold on
end
plot([0 2*rad(3)], [0 0], 'k-')
axis equal off
N = 6; th = linspace(0, 2*pi, 100);
c = cos(th); s = sin(th);
for n = 1:N
D = n^2*(1-r)^2+r;
xn = r*(r+1)/2/D;
yn = n*r*(1-r)/D;
rn = r*(1-r)/2/D;
fill(xn+rn*c, yn+rn*s, 'y')
plot(xn, yn, 'k+')
end
% Ellipse for centers of circles.
x = linspace(0, (1+r)/2, 50);
v = ((4*x-(r+1))/(1+r)).^2;
y = sqrt(r)*sqrt(1-v)/2;
plot(x, y, 'k--')
plot(rad(1), 0, 'k+', 2*rad(1)+rad(2), 0, 'k+')
text(0, -0.04, '(0,0)', 'HorizontalAlignment','center')
text(rad(1), -0.04, ['(' num2str(rad(1),3),',0)'], 'HorizontalAlignment','center')
text(2*rad(1)+rad(2), -0.04, ['(' num2str(2*rad(1)+rad(2),3),',0)'],'HorizontalAlignment','center')
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 a17
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,0)
(0.333,0)
(0.833,0)
6.21
function Exercise6_21
xi = logspace(-1, 2, 100);
Lam = 10.^(-(1:5));
for k = 1:length(Lam)
y = LossFactor(xi, Lam(k));
loglog(xi, y, '-k')
hold on
text(0.8*interp1(y, xi, 0.1), 0.1, ['\lambda = ' num2str(Lam(k))],'Rotation', 60)
end
v = axis; v(3)=10^(-3); axis(v)
xlabel('\xi')
ylabel('\eta')
function eta = LossFactor(xi, Lam)
eta = Lam*xi./(1+Lam*xi);
eta = eta.*(3+6*xi+4*xi.^2+2*Lam*xi.^3+Lam^2*xi.^4);
eta = eta./(1+2*Lam*(2*xi+3*xi.^2+2*xi.^3)+Lam^2*xi.^4);
Answer:
10
10
-1
1
0
0
.0
0
1
0
.0
0
1
.0
0
.1
0
=
5
0
0
e
1
10
10
-2
-3
10
-1
10
10
10
6.22
AB = 5; ab = linspace(0.3, AB, 50);
N = inline('(m./ab+ab/m).^2', 'ab', 'm');
cusp = sqrt((1:5).*(((1:5)+1)));
hold on
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 a18
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.
for m = 1:AB
y = N(ab,m);
plot(ab, y, 'k--')
a = interp1(y(1:20), ab(1:20), 9);
if m==AB
text(a+0.1, 9, [int2str(m) ' = m'])
else
text(a+0.1, 9, int2str(m))
end
end
for m=1:AB
if m==1
ab = linspace(0.3, cusp(m), 30);
else
ab = linspace(cusp(m-1), cusp(m), 30);
end
plot(ab, N(ab,m), 'k-', 'linewidth', 3)
end
axis([0, AB, 3, 10])
xlabel('a/b')
ylabel('N_{cr}')
Answer:
10
5= m
7
r
c
3
0
0.5
1.5
2.5
a/b
3.5
4.5
6.23
wt = logspace(-2, 6, 100);
for k = 1:5
a = 10^-k;
y = 100*(1-1./sqrt((1+a)^2+(a*wt).^2));
loglog(wt, y, 'k-')
hold on
text(0.09, 1.4*y(1), ['R_g/R_i = ' num2str(a)])
end
xlabel('\omega\tau_i (=\omegaR_iC_i)')
ylabel('Percentage error')
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 a19
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.
10
10
R /R = 0.1
Rg /R i = 0.01
r
o
r
r
e
e
g
a
t
n
e
c
r
e
P
10
10
10
10
R /R = 0.001
g
-1
R /R = 0.0001
g
-2
R /R = 1e-005
g
-3
10
-2
10
-1
10
10
10
10
10
10
10
(= R C )
i
i i
6.24
function Exercise6_24
v = 0.3; k = 10^-5; N = 100;
L = logspace(-2, 1, N);
Om = zeros(N, 3);
for n = 1:6
for m = 1:N
Om(m,:) = NatFreqShell(L(m), k, n, v)';
end
loglog(1./L, Om(:,1), 'k-')
hold on
text(40, 1.2*Om(1,1), ['n = ' num2str(n)])
end
xlabel('1/\lambda')
ylabel('\Omega_1')
function Om = NatFreqShell(L, k, n, v)
g = n.^2+L.^2;
K2 = 1+0.5*(3-v)*g+k*g.^2;
K1 = 0.5*(1-v)*((3+2*v)*L.^2+n.^2+g.^2+(3-v)/(1-v)*k*g.^3);
K0 = 0.5*(1-v)*((1-v^2)*L.^4+k*g.^4);
Om = sort(sqrt(roots([1, -K2, K1, -K0])));
Answer:
10
n= 6
10
-1
n= 5
n= 4
n= 3
n= 2
10
-2
n= 1
10
-3
10
-1
10
10
10
1/
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 a20
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.
6.25
function Exercise6_25
beta = 60*pi/180; rb = 3;
h = 0.5; rc = 0.5; n = 23;
phi = linspace(0, beta, n);
ph = [phi, beta+phi];
[Rx, Ry, Cx, Cy] = ContourFlat(phi, rb, h, beta, rc);
ang = linspace(2*beta, 2*pi, 40);
plot(Rx, Ry, 'k', rb*cos(ang), rb*sin(ang), 'k')
hold on
plot(Cx(1:5:2*n), Cy(1:5:2*n), 'k+')
axis equal
phd = linspace(0, 2*pi, 50);
[x, phx] = meshgrid(Cx(1:5:2*n), phd);
y = meshgrid(Cy(1:5:2*n), phd);
hold on
plot(x+rc.*cos(phx), y+rc.*sin(phx), 'k--')
plot([0 Rx(4)], [0, Ry(4)], 'k-')
text(Rx(4), Ry(4), '>', 'HorizontalAlignment','Right')
text(-1, 0.8, 'C(\phi)', 'fontsize', 14)
plot([0 Cx(end)], [0, Cy(end)], 'k-')
text(1, -0.2, 'R(\phi)', 'fontsize', 14)
axis off
set(gca, 'fontsize', 14)
function [L, dLdphi] = CamProfile(phi, rb, h, beta)
arg = 2*pi*phi/beta;
L = rb+h*(phi/beta-sin(arg)/2/pi);
dLdphi = (h/beta)*(1-cos(arg));
L = [L fliplr(L)];
dLdphi = [dLdphi -dLdphi];
function [Rx, Ry, Cx, Cy] = ContourFlat(phi, rb, h, beta, rc)
[L, dLdphi] = CamProfile(phi, rb, h, beta);
theta = atan2(dLdphi, L);
R = L./cos(theta);
ph = [phi, beta+phi];
Ry = R.*sin(theta+ph);
Rx = R.*cos(theta+ph);
gama = atan(dLdphi./(L+rc));
C = (L+rc)./cos(gama);
Cy = C.*sin(gama+ph);
Cx = C.*cos(gama+ph);
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 a21
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.
C( )
>
R( )
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 a22
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.
Solution to Exercises
Chapter 7
7.1
% Spherical helix
t = linspace(0, 10*pi, 300);
x = t/(2*5);
plot3(sin(x).*cos(t), sin(x).*sin(t), cos(x), 'k-')
axis equal
Answer:
1
0.5
-0.5
-1
0.5
0.5
0
0
-0.5
-0.5
% Toroidal spiral
a = 0.2; b = 0.8; c = 20;
t = linspace(0, 2*pi, 400);
plot3((b+a*sin(c*t)).*cos(t), (b+a*sin(c*t)).*sin(t), a*cos(c*t), 'k-')
axis equal
Answer:
0.2
0.1
0
-0.1
0.8
0.6
0.4
0.8
0.2
0.6
0.4
0.2
-0.2
-0.4
-0.2
-0.4
-0.6
-0.8
-0.6
-0.8
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.
0.2
0.1
0
-0.1
-0.2
0.8
0.6
0.4
0.8
0.2
0.6
0.4
0.2
-0.2
0
-0.4
-0.2
-0.4
-0.6
-0.6
-0.8
-0.8
% Concho-spiral
a = 1; b = 1.05; c = 3;
u = linspace(0, 12*pi, 200);
bu = b.^u;
plot3(a*bu.*cos(u), a*bu.*sin(u), c*bu, 'k-')
axis equal
Answer:
18
16
14
12
10
8
6
4
4
2
5
0
-2
0
-4
-5
0.5
0
-0.5
-0.8
-0.6
-0.4
-0.2
0.2
0.4
0.6
0.8
% Baseball seam
a = 0.4;
t = linspace(0, 4*pi, 200);
g = pi/2-(pi/2-a)*cos(t);
h = t/2+a*sin(2*t);
plot3(sin(g).*cos(h), sin(g).*sin(h), cos(g), 'k-')
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.
axis equal
Answer:
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
0.5
0.5
0
0
-0.5
-0.5
% Spherical spiral
a = 0.08;
phi = linspace(-12*pi, 12*pi, 400);
p = atan(a*phi);
plot3(cos(phi).*cos(p), sin(phi).*cos(p), -sin(p), 'k-')
axis equal
Answer:
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
0.5
0.5
0
0
-0.5
-0.5
7.2
% Seashell
vv = linspace(0, 2*pi, 25); uu = linspace(0, 6*pi, 45);
[u, v] = meshgrid(uu, vv);
E = exp(u/6/pi); C2 = cos(0.5*v).^2;
x = 2*(1-E).*cos(u).*C2;
y = 2*(-1+E).*sin(u).*C2;
z = 1-exp(u/3/pi)-sin(v)+E.*sin(v);
surf(x, y, z)
axis vis3d equal
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.
0
-1
-2
-3
-4
-5
-6
-7
-8
2
2
1
1
-1
-1
-2
-2
-3
1
0.5
0
-0.5
-1
1.5
2
1
1
0.5
0
0
-0.5
-1
-1
-1.5
-2
% Helical spring
r1 = 0.25; r2 = 0.25; T = 2.0; n = 6;
[u, v] = meshgrid(linspace(0, 2*n*pi, 140), linspace(0, 2*pi, 25));
x = [1-r1.*cos(v)].*cos(u);
y = [1-r1*cos(v)].*sin(u);
z = r2*[sin(v)+T*u/pi];
surf(x, y, z)
view([-64 0])
surf(x, y, z)
axis vis3d equal off
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 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.
% Cornucopia
a = 0.3; b = 0.5;
[u, v] = meshgrid(linspace(0, 2*pi, 22), linspace(-3, 3, 20));
x = exp(b*v).*cos(v)+exp(a*v).*cos(v).*cos(u);
y = exp(b*v).*sin(v)+exp(a*v).*sin(v).*cos(u);
z = exp(a*v).*sin(u);
surf(x, y, z)
Answer:
% Astroidal ellipsoid
[u, v] = meshgrid(linspace(-pi/2, pi/2, 40), linspace(-pi, pi, 40));
a = 1; b = 1; c = 1;
x = (a*cos(u).*cos(v)).^3;
y = (b*sin(u).*cos(v)).^3;
z = (c*sin(v)).^3;
surf(x, y, z)
axis vis3d equal off
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 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.
% Mobius strip
[s, t] = meshgrid(linspace(0, 2*pi, 30), linspace(-0.4, 0.4, 15));
x = cos(s)+t.*cos(s/2).*cos(s);
y = sin(s)+t.*cos(s/2).*sin(s);
z = t.*sin(s/2);
surf(x, y, z)
axis vis3d equal off
Answer:
% Bow curve
T = 0.7;
[u, v] = meshgrid(linspace(0, 2*pi, 20), linspace(0, 2*pi, 40));
x = (2+T*sin(u)).*sin(2*v);
y = (2+T*sin(u)).*cos(2*v);
z = T*cos(u)+3*cos(v);
surf(x, y, z)
axis off equal vis3d
shading interp
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 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.
% Hyperbolic helicoid
tau = 7;
[u, v] = meshgrid(linspace(-pi, pi, 100), linspace(0, 0.5, 8));
D = 1+cosh(u).*cosh(v);
x = sinh(v).*cos(tau*u)./D;
y = sinh(v).*sin(tau*u)./D;
z = sinh(u).*cosh(v)./D;
surf(x, y, z)
axis vis3d equal off
Answer:
% Apple surface
[u, v]= meshgrid(linspace(0, 2*pi, 30), linspace(-pi, pi, 50));
x = cos(u).*(4 + 3.8*cos(v));
y = sin(u).*(4 + 3.8*cos(v));
z = (cos(v) + sin(v) - 1).*(1 + sin(v)).* log(1 - pi*v / 10) + 7.5*sin(v);
h = surf(x, y, z);
set(h, 'FaceAlpha', 0.4)
axis off equal vis3d
shading interp
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 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.
7.3
function Exercise7_3
the = linspace(0, 2*pi, 30);
rad = linspace(0, 1, 15)';
xc = rad*cos(the);
yc = rad*sin(the);
options = optimset('display','off');
nm = 2; nk = 3; n = 0;
for m = 0:1:nm
vs = m+2.8;
for k = 1:nk
v = fzero(@circularplate, [vs vs+3], options, m);
mode = circularplatemode(m, v, rad, the);
vs = 1.2*v;
n = n+1;
subplot(nm+1, nk, n)
meshc(yc, xc, mode)
colormap([0 0 1])
title([num2str(v) ' m=' num2str(m) ' n=' num2str(k)])
axis off
end
end
function d = circularplate(x, n)
d = besselj(n, x)*besseli(n+1, x)+besseli(n, x)*besselj(n+1, x);
function [mod]= circularplatemode(m, omn, rad, the)
c1mn = -besseli(m, omn)/besselj(m, omn);
mod = (c1mn*besselj(m, omn*rad)+ besseli(m, omn*rad))*cos(the*m);
mod = mod/max(max(abs(mod)));
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 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.
7.4
function Exercise7_4
heatslab = inline('cos(x)-x.*sin(x)/b', 'x', 'b');
tau = [linspace(0, 0.5, 9) linspace(0.6, 2, 9)];
eta = linspace(0, 1, 11);
bi = 0.7; Nroot = 20; %x = linspace(0, 20*pi, 200);
r = FindZeros(heatslab, Nroot, linspace(0, 20*pi, 200), bi);
s = meshgrid(sin(r)./(r+sin(r).*cos(r)), eta);
th = (2*cos(r*eta).*s')'*exp(-r.^2*tau);
surf(tau, eta, th)
xlabel('\tau')
ylabel('\eta')
zlabel('\theta/\theta_i')
title(['Boit number = ',num2str(bi)])
axis vis3d
view(-32.5, 36)
function Rt = FindZeros(FunName, Nroot, x, w)
f = feval(FunName, x, w);
indx = find(f(1:end-1).*f(2:end)<0);
L = length(indx);
if L<Nroot
Nroot = L;
end
Rt = zeros(Nroot, 1);
for k = 1:Nroot
Rt(k) = fzero(FunName, [x(indx(k)), x(indx(k)+1)], [], w);
end
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 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.
1
0.9
0.8
0.7
#/
#
0.6
0.5
0.4
0.3
1
0.8
2
0.6
1.5
0.4
1
0.2
0.5
0
7.5
[x, y] = meshgrid(linspace(0, 1, 25), linspace(0, 1, 25));
surf(x, y, sin(2*pi*x).*sin(3*pi*y))
Answer:
0.5
-0.5
-1
1
0.8
1
0.6
0.8
0.6
0.4
0.4
0.2
0.2
0
7.6
[re, pr] = meshgrid(logspace(5.699, 7, 10), logspace(-0.2218, 3.301, 15));
nu = 0.037*re.^.8.*pr./(1+2.443*re.^-.1.*(pr.^(2/3)-1));
surf(log10(re), log10(pr), log10(nu))
xlabel('log_{10}(Re)')
ylabel('log_{10}(Pr)')
zlabel('log_{10}(Nusselt)')
hold on
xc = [5.699, 5.699, 7 7];
yc = [-0.2218, 3.301, -0.2218, 3.301];
zc = log10([nu(1,1), nu(end,1), nu(1,end), nu(end,end)]);
plot3([xc; xc], [yc; yc], [repmat(2, 1, 4); zc], 'k')
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 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.
6
5.5
)
t
l
e
s
s
u
N
(0
g1
o
l
5
4.5
4
3.5
3
2.5
2
4
3
7
2
6.5
1
6
0
log
10
-1
(Pr)
5.5
log 10 (Re)
7.7
n = linspace(6, 12, 10);
rho = [0.001:0.002:0.009 linspace(0.01, 0.1, 10)];
[nn rr] = meshgrid(n, rho);
rn = nn.*rr;
surf(nn, rr, -rn+sqrt(rn.^2+2*rn))
xlabel('n')
ylabel('\rho')
zlabel('k')
title('Location of neutral axis in a steel reinforced concrete beam')
Answer:
Location of neutral axis in a steel reinforced concrete beam
0.8
0.7
0.6
0.5
k
0.4
0.3
0.2
0.1
0.1
0.08
12
11
0.06
10
0.04
9
8
0.02
7
0
6
n
7.8
% function Exercise7_10
x = stem3data;
stem3(x(:,1), x(:,2), x(:,3), 'ks', 'fill');
view(-30, 7);
hold on
x1 = 0:5:20;
x2 = 0:200:600;
mesh(x1, x2, zeros(length(x2), length(x1)));
view([-30, 7])
colormap([0 0 1])
title('Deviations from mean output response')
xlabel('x_1')
ylabel('x_2')
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.
zlabel('Deviations')
box off
function dat1 = stem3data
dev = [1.5713, -1.1460, -2.2041, -1.5968, -2.8937, 1.1136, 1.9297, 1.1962, -3.8650, -0.4763,- 1.3223,...
-0.4619, 0.4911, -0.6023, 5.8409, -0.3620, 4.3341, -2.0368, -1.5415, 0.0302, -2.1809, 1.5587,...
0.3222, 2.1478, 0.1537];
x1 = [2, 8, 11, 10, 8, 4, 2, 2, 9, 8, 4, 11, 12, 2, 4, 4, 20, 1, 10, 15, 15, 16, 17, 6, 5];
x2 = [50, 110, 120, 550, 295, 200, 375, 52, 100, 300, 412, 400, 500, 360, 205, 400, 600, 585, 540, 250,...
290, 510, 590, 100, 400];
dat1 = [x1', x2', dev'];
Answer:
Deviations from mean output response
6
5
4
3
s
n
o
i
t
a
i
v
e
D
2
1
0
-1
-2
-3
-4
600
400
200
0
x2
10
15
20
7.9
eta = linspace(1, 3, 100); th = linspace(-pi, pi, 80);
x = eta'*cos(th);
y = eta'*sin(th);
[t, et] = meshgrid(th, eta);
sigr = 1-1./et.^2+(1+3./et.^4-4./et.^2).*cos(2*t);
sigt = 1+1./et.^2-(1+3./et.^4).*cos(2*t);
shear = -(1-3./et.^4+2./et.^2).*sin(2*t);
z = sqrt(((sigr-sigt).^2+sigr.^2+sigt.^2)/2+3*shear.^2);
[c, h] = contour(x, y, z, 15);
set(h, 'LineColor','k')
axis equal off
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 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.
Solution to Exercises
Chapter 8
8.1
%(a)
disp(['probability of 8 calls = ' num2str(poisspdf(8, 5))])
disp(['probability of 2 calls = ' num2str(poisspdf(2, 5))])
%(b)
disp(['probability of a busy signal = ' num2str(1-poisscdf(10, 5))])
Answers: probability of 8 calls = 0.065278
probability of 2 calls = 0.084224
probability of a busy signal = 0.013695
8.2
disp(['Probability that at least 12 withstand load = ' num2str(1-binocdf(11, 15, 0.7))])
Answer: Probability that at least 12 withstand load = 0.29687
8.3
dat = [88.4, 93.2, 87.4, 94.3, 93.0, 94.3, 89.0, 90.5, 90.8, 93.1, 92.8, 91.9;...
92.6, 93.2, 89.2, 94.8, 93.3, 94.0, 93.2, 91.7, 91.5, 92.0, 90.7, 93.8];
for k = 1:2
el = var(dat(k,:))+(mean(dat(k,:))-92)^2;
disp(['L' int2str(k) ' = ' num2str(el)])
end
Answers: L1 = 5.5904
L2 = 2.6936
8.4
p = 0.2; n = 24; m = 0:n;
disp(['Expected value = ' num2str(n*p) ' variance = ' num2str(n*p*(1-p))])
disp(['Probability that no more than 2 are underweight = ' num2str(binocdf(2, n, p))])
disp(['Probability that none is underweight = ' num2str(binopdf(0, n, p)) ])
plot([m; m], [zeros(1, n+1); binopdf(m, n, p)], 'k', m, binocdf(m, n, p), 'k*')
Answers: Expected value = 4.8 variance = 3.84
Probability that no more than 2 are underweight = 0.11452
Probability that none is underweight = 0.0047224
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.
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0
10
15
20
25
8.5
figure(1)
t = linspace(0, 1.5);
r = 1-expcdf(t);
plot(t, exppdf(t)./r, 'k-', t, r, 'k--')
title('Hazard rate and reliability for exponential distribution')
legend('Hazard rate', 'Reliability')
figure(2)
b = [0.5, 1, 2, 4];
for k = 1:4
subplot(2, 2, k)
r = 1-weibcdf(t, 1, b(k));
plot(t, weibpdf(t, 1, b(k))./r, 'k-', t, r, 'k--')
title(['Weibull: beta = ' num2str(b(k))])
legend('Hazard rate', 'Reliability')
end
Answers:
Weibull: beta = 1
1.2
Hazard rate
Hazard rate
Reliability
Reliability
1.1
Hazard rate
Reliability
0.8
0.6
0.4
0.9
0.8
0.5
1.5
0.2
0.5
1.5
0.7
Weibull: beta = 2
Weibull: beta = 4
14
0.6
Hazard rate
2.5
0.5
Hazard rate
12
Reliability
Reliability
10
8
1.5
0.4
6
1
0.3
0.5
0.2
0
0.5
1.5
0
0
0.5
1.5
0.5
1.5
8.6
dat = [1.55, 3.05, 3.65, 5.20, 7.75, 10.45, 10.85, 10.90, 12.65, 15.25 ...
15.70, 16.35, 17.70, 17.95, 19.45, 19.80, 20.05, 32.75, 35.45, 49.35];
k = 1:length(dat);
ft = norminv((k-0.5)/length(dat));
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.
figure(1)
plot(log(dat), ft, 'k-*')
beta = polyfit(log(dat), ft, 1);
disp(['curve fit: mean = ' num2str(-beta(2)/beta(1)) ' std dev = ' num2str(1/beta(1))])
disp(['Eq.(a): mean = ' num2str(mean(log(dat))) ' std dev = ' num2str(std(log(dat)))])
hold on
plot([log(dat(1)) log(dat(length(dat)))], [beta(2)+beta(1)*log(dat(1)) beta(2)+ ...
beta(1)*log(dat(length(dat)))], 'k')
title('Fit assuming data are lognormal')
ylabel('F(t)')
xlabel('ln(t)')
text(1.25, 1.5, ['F(t) = ' num2str(beta(2)) ' + ' num2str(beta(1)) 'ln(t)'])
figure(2)
normplot(log(dat)-(beta(2)+beta(1)*log(dat)))
Answers: curve fit: mean = 2.5072 std dev = 0.88841
Eq.(a): mean = 2.5072 std dev = 0.85441
Normal Probability Plot
0.98
1.5
0.95
0.90
1
y
t
i
l
i
b
a
b
o
r
P
0.5
)
t
(
F
-0.5
0.75
0.50
0.25
-1
-1.5
0.10
0.05
-2
0.02
-2.5
0
0.5
1.5
2
ln(t)
2.5
3.5
2.35
2.4
2.45
2.5
2.55
Data
2.6
2.65
2.7
2.75
8.7
dat = [2.5629, 2.5630, 2.5628, 2.5634, 2.5619, 2.5613, 2.5630, 2.5628, 2.5623, 2.5631, 2.5635, 2.5623];
[p, cp, cpk] = capable(dat, [2.560 2.565])
Answers: p = 1.5351e-004 cp = 1.3103 cpk = 1.2099
8.8
dat = [ 1115, 1310, 1540, 1502, 1258, 1315, 1085, 1567, 1883, 1203, 1270, 1015, 845, 1674; ...
1223, 375, 2265, 1910, 1018, 1452, 1890, 1782, 1522, 1792, 1000, 1820, 1940, 1120; ...
1055, 1764, 1330, 1608, 1535, 1781, 1750, 798, 1020, 865, 2130, 1421, 1109, 1481; ...
1016, 1102, 1605, 706, 2215, 785, 885, 2100, 1594, 2023, 1315, 1269, 1260, 1888; ...
910, 1730, 1102, 1578, 758, 1416, 1560, 1501, 1238, 990, 1468, 1512, 1750, 1642];
s0 = [dat(1,:), dat(2,:), dat(3,:), dat(4,:), dat(5,:)];
disp(['data set #0: geometric mean = ' num2str(geomean(s0))])
disp(['data set #0: harmonic mean = ' num2str(harmmean(s0))])
xbar0 = mean(s0);
var0 = var(s0);
disp(['dataset #0: mean = ' num2str(xbar0) ' std. dev. = ' num2str(sqrt(var0))])
n1 = length(s0); n2 = n1/5; nn = n1+n2-2;
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.
co = sqrt(1/n1+1/n2); c1 = (n1-1)*var0;
for k = 1:5
me = mean(dat(k,:));
st = std(dat(k,:));
disp(['dataset #' int2str(k) ': mean = ' num2str(me) ' std. dev. = ' num2str(st)])
[h(k), p(k), ci(k,:)] = ttest2(s0, dat(k,:), 0.025);
dmean(k) = xbar0-me;
end
for k = 1:5
disp(['set #' num2str(k) ' lcl = ' num2str(ci(k,1)) ' diff in mean = ' num2str(dmean(k)) ...
' ucl = ' num2str(ci(k,2)) ' p_value = ' num2str(p(k)) ' hyp: ' num2str(h(k))])
end
boxplot(dat')
Answers: data set #0: geometric mean = 1339.9309
data set #0: harmonic mean = 1264.6733
dataset #0: mean = 1403.6571 std. dev. = 402.3852
dataset #1: mean = 1327.2857 std. dev. = 280.1281
dataset #2: mean = 1507.7857 std. dev. = 506.6656
dataset #3: mean = 1403.3571 std. dev. = 392.5288
dataset #4: mean = 1411.6429 std. dev. = 501.0445
dataset #5: mean = 1368.2143 std. dev. = 315.758
set #1 lcl = -181.3939 diff in mean = 76.3714 ucl = 334.1367 p_value = 0.50062 hyp: 0
set #2 lcl = -385.323 diff in mean = -104.1286 ucl = 177.0658 p_value = 0.40028 hyp: 0
set #3 lcl = -267.654 diff in mean = 0.3 ucl = 268.254 p_value = 0.99797 hyp: 0
set #4 lcl = -288.4656 diff in mean = -7.9857 ucl = 272.4942 p_value = 0.94832 hyp: 0
set #5 lcl = -225.2238 diff in mean = 35.4429 ucl = 296.1095 p_value = 0.757 hyp: 0
2200
2000
1800
1600
1400
1200
1000
800
600
400
1
8.9
dat = [88, 79, 84, 89, 81, 83, 82, 79, 82, 85, 81, 83, 90, 87, 78, 80, 87, 85, 80, 88;...
76, 83, 78, 80, 84, 86, 77, 75, 81, 78, 79, 85, 76, 80, 82, 78, 78, 77, 81, 80];
boxplot(dat')
std2 = var(dat');
pvalue = 2*(1-fcdf(std2(1)/std2(2), length(dat(1,:))-1, length(dat(1,:))-1));
disp(['p-value from F-test on ratio of variances = ' num2str(pvalue)])
% Since pvalue > 0.1 use ttest2
[h, p, ci] = ttest2(dat(1,:), dat(2,:), 0.025);
disp(['p-value of t-test for difference in means = ' num2str(p)])
boxplot(dat')
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.
85
80
75
1
8.10
function Exercise8_10
% (a)
xy1 = [18, 24, 12, 30, 30, 26, 26, 22, 22, 14, 10, 10, 6, 6]';
xy2 = [52, 40, 40, 48, 32, 56, 24, 64, 16, 64, 56, 24, 48, 32]';
y = [144, 142, 124, 64 96, 74, 136, 54, 92, 96, 92, 82, 76, 68]';
x = [ones(length(y),1) xy1 xy2 xy1.^2 xy2.^2 xy1.*xy2];
[b, bi, res] = regress(y, x);
disp([repmat('b(', 6, 1) int2str((1:6)') repmat(') = ', 6, 1) num2str(b)])
figure(1)
normplot(res)
%(b)
xx1 = linspace(6, 30, 20);
xx2 = linspace(16, 64, 20);
[x1, x2] = meshgrid(xx1, xx2);
z = fittedsurface([x1; x2], b);
figure(2)
surf(x1, x2, z)
xlabel('x_1')
ylabel('x_2')
figure(3)
[c h] = contour(x1, x2, z, [20:20:140 150 155]);
clabel(c, h)
xlabel('x_1')
ylabel('x_2')
%(c)
opt = optimset('Display', 'off');
fitsurf = inline('-(b(1)+b(2)*x(1)+b(3)*x(2)+b(4)*x(1).^2+b(5)*x(2).^2+b(6)*x(1).*x(2))', 'x','b');
coord = fminunc(fitsurf, [10, 20]', opt, b);
disp(['x1 = ' num2str(coord(1)) ' x2 = ' num2str(coord(2))])
function z = fittedsurface(x, b)
[nr, nc] = size(x);
x1 = x(1:nr/2,: );
x2 = x(nr/2+1:nr,: );
z = b(1)+b(2)*x1+b(3)*x2+b(4)*x1.^2+b(5)*x2.^2+b(6)*x1.*x2;
Answers: b(1) = -288.2799
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.
b(2) = 24.16421
b(3) = 11.51143
b(4) = -0.5072724
b(5) = -0.118116
b(6) = -0.1348869
x1 = 18.7635 x2 = 38.0155
Normal Probability Plot
0.98
0.95
0.90
y
t
i
l
i
b
a
b
o
r
P
0.75
0.50
0.25
0.10
0.05
0.02
-10
-5
10
15
Data
60
80
60
60
100
80
100
20
200
120
55
40
120
150
140
50
0
100
45
50
x
40
35
-50
70
30
8
0
30
50
25
25
40
20
0
5
1
1
2
0
30
15
20
20
x1
1
4
0
150
12
0
1
2
0
0
2
1
0
0
1
140
8
0
2
0
120
10
0
8
100
60
15
0
5
15
6
0
10
10
14
0
155
1
4
0
4
0
6
0
8
0
1
00
60
10
0
0
0
1
15
20
100
25
30
x1
8.11
function Exercise8_11
[x, y] = regressdata1;
[beta, betacl, e, ecl, stat] = regress(y, x);
disp(['beta0 = ' num2str(beta(1)) ' beta1 = ' num2str(beta(2))])
figure(1)
plot(1./x(:,2), beta(1)+beta(2)*x(:,2), 'k-', 1./x(:,2), y, 'k*')
xlabel('x')
ylabel('y')
figure(2)
normplot(e)
r = sqrt(stat(1));
t0 = r*sqrt(length(y)-2)/sqrt(1-stat(1));
disp(['t0 = ' num2str(t0) ' p_value = ' num2str(1-tcdf(t0,length(y)-2)) ' dof = ' ...
num2str(length(y)-2)])
disp('r and its confidence limits:')
za2 = norminv(.975)/sqrt(length(y)-3);
disp([num2str(tanh(atanh(r)-za2)) ' <= ' num2str(r ) ' <= ' num2str(tanh(atanh(r) +za2))])
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.
0.99
0.98
7
0.95
0.90
6
y
t
i
l
i
b
a
b
o
r
P
4
y
0.75
0.50
0.25
2
0.10
0.05
0.02
0
4
10
12
14
16
18
20
22
0.01
-0.6
-0.5
-0.4
-0.3
-0.2
-0.1
Data
0.1
0.2
0.3
8.12
function Exercise8_12
[y, x] = DataMultiRegress1;
[b, bcl, e, ecl, stat] = regress(y, x, 0.05);
[n, k] = size(x);
sigmabar = sqrt((y'*y-b'*x'*y)/(n-k-1));
d = e/sigmabar;
r = e./sqrt(1-diag(x*inv(x'*x)*x'))/sigmabar;
plot(y-e, d, 'k*', y-e, r, 'ks')
v = axis;
hold on
plot([v(1) v(2)], [0 0], 'k--')
title('Residuals')
ylabel('Residuals')
xlabel('Average output')
legend('Standardized residuals', 'Studentized residuals')
function [y, X] = DataMultiRegress1
y = [0.22200, 0.39500, 0.42200, 0.43700, 0.42800, 0.46700, 0.44400, 0.37800, 0.49400, ...
0.45600, 0.45200, 0.11200, 0.43200, 0.10100, 0.23200, 0.30600, 0.09230, 0.11600, ...
0.07640, 0.43900, 0.09440, 0.11700, 0.07260, 0.04120, 0.25100, 0.00002]';
x1 = [7.3, 8.7, 8.8, 8.1, 9.0, 8.7, 9.3, 7.6, 10.0, 8.4, 9.3, 7.7, 9.8, 7.3, 8.5, 9.5, 7.4, 7.8, 7.7, 10.3, ...
7.8, 7.1, 7.7, 7.4, 7.3, 7.6]';
x2 = [0.0, 0.0, 0.7, 4.0, 0.5, 1.5, 2.1, 5.1, 0.0, 3.7, 3.6, 2.8, 4.2, 2.5, 2.0, 2.5, 2.8, 2.8, 3.0, 1.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 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.
2.5
1.5
s
l
a
u
d
i
s
e
R
0.5
-0.5
-1
-1.5
-2
-0.1
0.1
0.2
0.3
Average output
0.4
0.5
0.6
8.13
y = [85, 76, 114, 143, 164, 281, 306, 358, 437, 470, 649, 702];
x = 90:10:200;
plot(x, y, 'ko')
hold on
[cl, sl] = polyfit(x, y, 1);
[cq, sq] = polyfit(x, y, 2);
plot(x, cl(2)+cl(1)*x, 'k-',x, cq(3)+cq(2)*x+cq(1)*x.^2, 'b--')
figure(2)
normplot(y-( cl(2)+cl(1)*x))
figure(3)
normplot(y- (cq(3)+cq(2)*x+cq(1)*x.^2))
Answers:
800
700
600
500
400
300
200
100
-100
80
100
120
140
160
180
200
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.
0.95
0.95
0.90
0.90
y
t
i
l
i
b
a
b
o
r
P
y
t
i
l
i
b
a
b
o
r
P
0.75
0.50
0.75
0.50
0.25
0.25
0.10
0.10
0.05
0.05
-60
-40
-20
20
Data
40
60
80
-50
-40
-30
-20
-10
10
20
30
40
Data
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.
Solutions to Exercises
Chapter 9
9.1
function Exercise9_1
initcond = [2.0, 0.0, 0.0, 0.5];
ti = 0.0; tf = 20.0;
spacing = [400; 4000];
options(1)=odeset('RelTol', 1e-3, 'AbsTol', [1e-3, 1e-3, 1e-3, 1e-3]);
options(2)=odeset('RelTol', 1e-6, 'AbsTol', [1e-6, 1e-6, 1e-6, 1e-6]);
for i = 1:2
tspan = linspace(ti, tf, spacing(i));
[t, x] = ode45(@orbit, tspan, [initcond]', options(i));
angmom = x(:,1).^2.*x(:,4);
subplot(2, 2, 2*i-1)
polar(x(:,3), x(:,1), 'k-')
subplot(2, 2, 2*i)
plot(t, angmom, 'k-')
axis([0 20 1.6 2.2]);
xlabel('Time')
ylabel('Angular Momentum/Unit Mass');
end
function xdot = orbit(t, x)
xdot = [x(2); x(1)*x(4)^2-4.0*pi^2/x(1)^2; x(4); -2.0*x(2)*x(4)/x(1)];
Answers:
90
120
60
1
150
30
180
210
r
a
l
u
s
g
s
n
a
A
M
330
240
300
270
90
120
60
2
150
30
180
210
330
240
300
270
n
U
/
m
u
t
n
e
m
o
M
t
i
n
U
/
m
u
t
n
e
m
o
M
r
a
l
u
g
n
A
2.2
2.1
2
1.9
1.8
1.7
1.6
10
15
20
15
20
Time
2.2
2.1
2
1.9
1.8
1.7
1.6
0
10
Time
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.
9.2
ro = [2.0, 2.0]; tho = [ 2, 0.2];
for i = 1:2
r = roots([tho(i)^2-8*pi^2/ro(i), 8*pi^2, -ro(i)^2*tho(i)^2])
end
Answers: r =
2.0000
0.2255
r=
2.0000
0.0020
9.3
% (a)
Om = [linspace(0.0, 0.8, 10), linspace(0.8, 1.2, 25), linspace(1.2, 2, 10)];
zet = linspace (0.05, 0.99, 15);
[Omm, zeta] = meshgrid(Om, zet);
AmAt = 1./sqrt((1-Omm.^2).^2+(2*zeta.*Omm).^2);
mesh(Omm, zeta, AmAt);
colormap([0 0 0])
xlabel('\Omega');
ylabel('\zeta');
zlabel('A_m/A_t')
% (b)
e = [-2, 2]; err = 1-e/100;
Omega = (6000/60)/150;
for i = 1:2
zetta(i) = sqrt((-(1-Omega^2)^2+1/err(i)^2))/2/Omega;
end
disp(['At -2%, zeta = ' num2str(zetta(1))])
disp(['At +2%, zeta = ' num2str(zetta(2))])
Answers: At -2%, zeta = 0.60584
At +2%, zeta = 0.64194
10
6
At
/m
A
0
1
0.8
2
0.6
1.5
0.4
1
0.2
0.5
0
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.
9.4
% (a)
Om = [linspace(0.0, 0.8, 10), linspace(0.8, 1.2, 25), linspace(1.2, 2, 10)];
zet = linspace (0.05, 0.99, 15);
[Omm, zeta] = meshgrid(Om, zet);
dmdt = Omm.^2./sqrt((1-Omm.^2).^2+(2*zeta.*Omm).^2);
mesh(Omm, zeta, dmdt);
colormap([0 0 0])
xlabel('\Omega');
ylabel('\zeta');
zlabel('d_m/d_t')
% (b)
e = [-2, 2]; d = 1-e/100; z = 0.1; w = 1500/60;
for k = 1:2
Omega = abs((roots([(1-1/d(k)^2) (-2+4*z^2) 1])));
f(k) = w./sqrt(min(Omega));
end
disp(['At -2%, f = ' num2str(f(1)) ' Hz'])
disp(['At +2%, f = ' num2str(f(2)) ' Hz'])
disp(['Maximum frequency is ' num2str(max(f)) ' Hz'])
Answers: At -2%, f = 34.8208 Hz
At +2%, f = 35.1854 Hz
Maximum frequency is 35.1854 Hz
10
6
dt
/
m
d
0
1
0.8
2
0.6
1.5
0.4
1
0.2
0.5
0
9.5
function Exercise9_5
tspan = linspace(0, 20, 200); xo = 1; vo = 1;
zet = [0.1, 1, 2];
for k = 1:3
[t, x] = ode45(@FreeOscill, tspan, [xo, vo]', [], zet(k));
subplot(3, 2, 2*k-1),
plot(t , x(:,1), 'k-');
xlabel('\tau')
ylabel('x(\tau)')
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.
Analytical:
2
1
)(
x
)(
x
-1
-2
0
-1
-2
10
15
20
ode45 = 1
Analytical:
0.5
20
15
20
0.5
10
15
20
10
ode45 = 2
Analytical:
1.5
= 2
1.5
)(
0.5
0
15
= 1
0
0
20
)(
)(
15
1.5
1
x
10
1.5
)(
= 0.1
10
15
20
0.5
0
10
9.6
function Exercise9_6
[t, amp] = Dat;
plot(t, amp, 'ks');
hold on
xo = [0.1, 1.1, 0.9];
opt = optimset('display', 'off');
x = lsqcurvefit(@xdamped, xo, t, amp, [], [], opt);
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.
= 0.122
0.6
X = 0.824 units
o
= 1.6 rad/s
n
e
d
u
t
i
l
p
m
A
0.4
0.2
-0.2
-0.4
-0.6
0
10
15
Time
20
25
30
9.7
function Exercise9_7
initcond = [1.0, 0.0, 0.0];
tspan = linspace(0, 1, 100);
xmu = 0.2; omega = 6.0; L = 3.0;
[t, x] = ode45(@rod, tspan, [initcond]', [], xmu, omega);
indx = find(x(:,1) <= L);
polar(x(indx, 3), x(indx, 1));
t3 = interp1(x(:,1), t, L);
disp(['Time at which mass leaves rod is ' num2str(t3, 3) ' s'])
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.
120
60
2
150
30
1
180
210
330
240
300
270
9.8
function Exercise9_8
zet = 0.1; omegan = 4;
omega = linspace(0, 10, 100);
[mag2, phas2] = Anal(omega, omegan, zet);
sys = freqresp(zet, omegan);
[mag1, phas1] = bode(sys, omega);
subplot(2, 2, 1)
plot(omega,mag1(1,:), '-k')
xlabel('Excitation frequency (rad/s)');
ylabel('Magnitude');
title(['Bode']);
subplot(2, 2, 3),
plot(omega, phas1(1,:),'k-');
xlabel('Excitation frequency (rad/s)');
ylabel('Phase (Degrees)')
subplot(2, 2, 2)
plot(omega, mag2, '-k')
xlabel('Excitation frequency (rad/s)');
ylabel('Magnitude')
title('Analytical');
subplot(2,2,4)
plot(omega, phas2, 'k-')
xlabel('Excitation frequency (rad/s)');
ylabel('Phase (Degrees)')
function sys = freqresp(zet, omegan)
N = [2*zet*omegan, omegan^2];
D = [1, 2*zet*omegan, omegan^2];
sys = tf(N, D);
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.
Analytical
e
d
u
t
i
n
g
a
M
e
d
u
t
i
n
g
a
M
4
3
2
1
0
5
4
3
2
1
10
10
10
-50
-100
e
s
a
h
P
-150
-200
-50
-100
-150
-200
0
2
4
6
Excitation frequency (rad/s)
10
2
4
6
Excitation frequency (rad/s)
9.9
function Exercise9_9
z = 0.1; to = [15, 6, 0.7];
for k=1:length(to)
figure(k)
[t, y] = ode45(@Ramp, [0 30], [0 0]', [], z, to(k));
plot(t, y(:,1), 'k-', [0, to(k), 30], [0, 1, 1], 'k--')
xlabel('\tau')
ylabel('y(\tau)')
title(['\tau_o = ' num2str(to(k)) ' \zeta = ' num2str(z)])
end
function xdot = Ramp(t, x, z, to)
h = (t - (t-to).*(t>to))/to;
xdot = [x(2); -2*z*x(2)-x(1)+h];
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 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.
= 6 = 0.1
o
= 15 = 0.1
o
1.4
1.4
1.2
1.2
0.8
0.8
)(
)(
y
0.6
0.6
0.4
0.4
0.2
0.2
0
0
10
15
20
25
30
10
15
20
25
30
= 0.7 = 0.1
o
1.8
1.6
1.4
1.2
)(
0.8
0.6
0.4
0.2
0
0
10
15
20
25
30
9.10
function Exercise9_10
m = 10.0; k = 150*10^3; c = 50;
b = [1*10^-6, 1000*10^-6];
forceampl = 0; forcefreq = 0;
figure(1)
for i = 1:2
[t, x]=ode45(@sdofstops, [0 1.4], [0, 2]', [], m, k, c, b(i), forceampl, forcefreq);
subplot(2,1,i)
plot(t, x(:,1), 'k-')
xlabel('Time t');
ylabel('x(t)');
title(['Dead zone b =' num2str(b(i)*10^6) ' um'])
end
figure(2)
forceampl = 20; forcefreq = 12;
b = 5e-6;
[t, x] = ode45(@sdofstops, [0 2], [0 0]', [], m, k, c, b, forceampl, forcefreq);
plot(t, x(:,1), 'k-')
xlabel('Time t')
ylabel('x(t)')
title('Forced Response')
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.
x 10
-4
Forced Response
0.015
0.01
)
t
(
x
0.005
0
-0.005
-0.01
-0.015
0.2
0.4
0.6
0.8
1.2
1.4
)
t
(
x
Time t
Dead zone b =1000 um
0.02
0.015
0
0.01
)
t
(
x
0.005
0
-1
-0.005
-0.01
-0.015
0
0.2
0.4
0.6
0.8
1.2
1.4
Time t
-2
0
0.2
0.4
0.6
0.8
1
Time t
1.2
1.4
1.6
1.8
9.11
function Exercise9_11
L = 2.0; b = [10, 0.2];
tspan=[0.0:0.1:10];
for i = 1:2
[t, x] = ode45(@Freeosc, [0, 10], [0.2, 0]', [], b(i), L);
subplot(2,1,i)
plot(t, x(:,1), 'k-');
xlabel('Time (s)')
ylabel('\theta');
title(['b = ' num2str(b(i)) ' m/s^2']);
end
function xdot = Freeosc(t, x, b, L)
xdot = [x(2); -b/L*cos(x(1))-9.81/L*sin(x(1))];
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 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.
b = 10 m/s 2
0.5
0
-0.5
-1
-1.5
-2
5
Time (s)
b = 0.2 m/s
10
10
0.3
0.2
0.1
0
-0.1
-0.2
-0.3
-0.4
0
5
Time (s)
9.12
function exercise9_12
gam = 1; zet = 0.15; a = 30; Dst = 0.3;
[t, zn] = ode45(@NonLinearSpring, [0 25], [0 0], [], zet, a, gam, Dst);
plot(t, (zn(:,1)+Y(t, gam)), 'k-')
hold on
plot(t, Y(t, gam), 'k-')
xlabel('\tau')
ylabel('x(\tau)/y_{max}')
function Out = NonLinearSpring(t, z, zet, a, g, Dst)
yinacc = g^2*(1-g*t).*exp(-g*t);
Out = [z(2); -2*zet*z(2)-z(1)-a*(z(1)-Dst)^3-yinacc-a*Dst^3];
function yin = Y(t, g)
yin = 1-(1+g*t).*exp(-g*t);
Answer:
1.4
1.2
0.8
x
ya
/m
)(
0.6
0.4
0.2
0
0
10
15
20
25
9.13
function Exercise9_13
wr = 1; mr = 0.05; z1 = 0;
z2 = 0.05:0.05:0.3;
Om = linspace(0.6, 1.4, 200);
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.
for k = 1:length(z2)
plot(Om, H11(Om, wr, mr, z1, z2(k)), 'k-')
hold on
end
xlabel('\Omega')
ylabel('H_{11}(\Omega)')
xlim([0.6, 1.4])
A = sqrt((wr^2-1)^2+mr*(2+mr));
B = 1+wr^2*(1+mr);
Om1 = sqrt((B-A)/(2+mr))
Om2 = sqrt((B+A)/(2+mr))
function h = H11(Om, wr, mr, z1, z2)
D = Om.^4-j*2*(z1+z2*wr*mr+z2*wr)*Om.^3 ...
-(1+mr*wr^2+wr^2+4*z1*z2*wr)*Om.^2+j*2*(z2*wr+z1*wr^2)*Om+wr^2;
E = wr^2+j* 2*z2*wr*Om-Om.^2;
h = abs(E./D);
Answers: Om1 = 0.9186
Om2 = 1.0753
16
14
12
10
)
(1
H
6
0
0.6
0.7
0.8
0.9
1.1
1.2
1.3
1.4
9.14
k1 = 14600; k2 = 21900; L1 = 1.520; L2 = 1.22; m = 730; Ic = 1360;
K = [k1+k2, (L2*k2-L1*k1); (L2*k2-L1*k1), (k1*L1^2+k2*L2^2)];
M = [m, 0; 0, Ic];
[Modes, Eval] = eig(K, M);
NatFreq = sqrt(diag(Eval));
disp(['omega1 = ' num2str(NatFreq(1)) ' rad/s omega2 = ' num2str(NatFreq(2)) ' rad/s'])
disp(' ')
disp(['Mode shapes are:'])
disp(Modes)
Answers: omega1 = 6.6934 rad/s omega2 = 7.3464 rad/s
Mode shapes are:
0.0244 -0.0279
-0.0204 -0.0178
9.15
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
-0.02
-0.04
10
20
30
40
50
Time
60
70
80
90
100
60
70
80
90
100
= 0.25
r
0.3
0.2
0.1
T
0
-0.1
-0.2
0
10
20
30
40
50
Time
9.16
m1 = 10; m2 = 40; JG = 8;
k1 = 10000; k2 = 35000; k3 = 8100;
L1 = 1; L2 = 0.3; g = 9.81;
L3 = (L1-L2)/2;
A(1,1) = k1+k2+k3; A(1,2) = -k3; A(1,3) = k1*L1-k2*L2+k3*L3;
A(2,1) = A(1,2); A(2,2) = k3; A(2,3) = -k3*L3;
A(3,1) = A(1,3); A(3,2) = A(2,3); A(3,3) = k1*L1^2+k2*L2^2+k3*L3^2;
xt = A\[m1*g, m2*g, 0]';
tho = asin(xt(3));
M = diag([m1, m2, JG]);
A(3,3) = -A(1,3)*xt(1)*sin(tho)+k3*L3*xt(2)*sin(tho)+A(3,3)*(cos(tho)^2-sin(tho)^2);
A(1,3) = A(1,3)*cos(tho); A(3,1) = A(1,3);
A(2,3) = A(2,3)*cos(tho); A(3,2) = A(2,3);
K = A;
[Modes, EVal] = eig(K,M);
NF = sqrt(diag(EVal))
Modes
Answers: NF = 12.5989 41.9371 73.2299
Modes =
0.0233 -0.0260 0.3143
0.1571 -0.0126 -0.0127
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.
0.0304
0.3512
0.0268
9.17
M = diag([21 21 21 21 21 21 98 49]);
K = [51 -51 0 0 0 0 0 0
-51 102 -51 0 0 0 0 0
0 -51 102 -51 0 0 0 0
0 0 -51 102 -51 0 0 0
0 0 0 -51 102 -51 0 0
0 0 0 0 -51 117 -66 0
0 0 0 0 0 -66 81 -15
0 0 0 0 0 0 -15 15]*10^6;
rnk = rank(K)
[modes E] = eig(K,M);
w = sqrt(E);
hold on
w(1,1) = 0;
for n = 1:8
plot([1 8], [2*n-1, 2*n-1], 'k--')
plot(1:8, 2*n-1+modes(:,n)/max(abs(modes(:,n))), 'sk-')
text(-.4, 2*n-1, ['\omega_{' num2str(n) '}=' num2str(w(n,n),4)], 'fontsize', 14, 'HorizontalAlignment', 'left')
end
v = axis; v(1) = 0.5;
axis(v); axis off
Answer:
8=3041
7=2805
6=2406
5=1862
4=1219
3=704.8
2=458.3
1=0
9.18
Jp = 2; Jt = 1.2; k1 = 2.5e6; k2 = k1; m = 10;
M = diag([m, Jt, m, Jt]);
IM = inv(M);
K = diag([k1, k2, k1, k2]);
G = zeros(4,4);
Mstar = [K, G; G, M];
Ks11 = K*IM*K;
omega = linspace(0, 1500, 10);
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 a13
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.
for n = 1:length(omega)
G(2,4) = -Jp*omega(n);
G(4,2) = Jp*omega(n);
Kstar = [Ks11, K*IM*G; G'*IM*K, K+G'*IM*G];
Lambda(n,:) = sort(sqrt(eig(Kstar, Mstar)))';
end
plot(omega', Lambda, 'k-s')
v = axis;
axis([v(1) v(2) 0 v(4)])
xlabel('\omega')
ylabel('\Omega')
Answers:
3500
3000
2500
2000
1500
1000
500
0
0
500
1000
1500
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 a14
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.
Solutions to Exercises
Chapter 10
10.1
% Parts a and b
theta = linspace(0, 2*pi, 11);
k = 1;
p = 2*pi*k*[cos(theta(6))
cos(theta(4))+sqrt(-1)*sin(theta(4))
cos(theta(4))-sqrt(-1)*sin(theta(4))
cos(theta(5))+sqrt(-1)*sin(theta(5))
cos(theta(5))-sqrt(-1)*sin(theta(5))];
z = -p;
figure(1);
plot(real(p), imag(p), 'bx', real(z), imag(z), 'ro');
title('Map of delay approximation');
dplant = zpk(z,p,1);
dplant = 1/(dcgain(dplant))*dplant;
gplant = tf(1, [1 1]);
[y1, t1] = step(dplant*gplant);
[y0] = step(gplant, t1);
figure(2);
plot(t1, y0, 'k-', t1, y1, 'k--');
legend('Orginal', 'Delayed');
title('Step response, original and delayed system');
% Part c
p2 = 0.5*p; z2 = -p2;
dplant2 = zpk(z2,p2,1);
dplant2 = 1/(dcgain(dplant2))*dplant2;
[y2,t2] = step(dplant2*gplant);
[y0] = step(gplant,t2);
% Increase k to 2
p3 = 2*p;
z3 = -p3;
dplant3 = zpk(z3, p3, 1);
dplant3 = 1/(dcgain(dplant3))*dplant3;
[y3,t3] = step(dplant3*gplant);
[y0] = step(gplant,t3);
figure(3);
plot(t3, y0,t1, y1, t2, y2, t3, y3);
legend('Org', 'k=1', 'k=0.5', 'k=2', 'Location', 'SouthEast');
title('Step response for variety of delays');
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 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.
1.2
Orginal
Delayed
1
4
0.8
2
0.6
0
0.4
-2
0.2
-4
-6
-8
-0.2
-6
-4
-2
1
1
0.8
0.8
0.6
0.6
0.4
0.4
0.2
0.2
Org
k=1
k=0.5
0
5
3
k=2
-0.2
0
-0.2
0
10.2
m1 = 500; m2 = 100; b = 1000;
k1 = 2000; k2 = 1e4;
num = [b*k2 k1*k2];
den = [m1*m2, b*(m1+m2), k1*(m1+m2)+k2*m1, k2*b, k1*k2];
[mag, phs, w] = bode(num, den);
logW = log10(w/(2*pi));
logmag = 20*log10(mag);
[mx, inmx] = max(20*log10(mag));
fa = 10^(interp1(logmag(inmx:end), logW(inmx:end), 20*log10(0.9)));
fc = 10^(interp1(logmag(inmx:end), logW(inmx:end), 20*log10(0.1)));
disp(['frequency @ 0.1e = ' num2str(fa) ' Hz frequency @ 0.9e = ' num2str(fc) ' Hz'])
mload = linspace(500, 1000, 20);
z = zeros(length(w), 20);
for i = 1:length(mload)
m1 = mload(i);
den = [m1*m2, b*(m1+m2), k1*(m1+m2), k2*m1, k2*b, k1*k2];
[mag] = bode(num, den, w);
z(:,i) = 20*log10(mag);
end
mesh(mload, logW, z)
xlabel('Load (kg)')
ylabel('log_{10}(freqency in Hz)')
zlabel('Response (dB)')
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.
50
)
B
d
(
e
s
n
o
p
s
e
R
-50
-100
-150
-200
-250
3
2
1000
1
900
800
0
700
-1
log
10
(freqency in Hz)
600
-2
500
Load (kg)
10.3
g0 = tf(1, [1, 1]);
g1 = tf(3.7, [0.75, 0.6]);
g2 = tf(1.63, [0.94, 0.92]);
g3 = tf([0.7, 7, 17], [1, 2, 5.2, 4]);
t = linspace(0, 2, 200);
y0 = step(g0, t);
y1 = step(g1, t);
y2 = step(g2, t);
y3 = step(g3, t);
figure(1)
plot(t, y0, t, y1, t, y2, t, y3)
legend('g0', 'g1', 'g2', 'g3')
title('Open loop response')
xlabel('Time (s)')
r0 = step(feedback(g0, 20), t);
r1 = step(feedback(g1, 20), t);
r2 = step(feedback(g2, 20), t);
r3 = step(feedback(g3, 20), t);
figure(2)
plot(t, r0, t, r1, t, r2, t, r3)
legend('g0', 'g1', 'g2', 'g3')
title('Closed loop response')
xlabel('Time (s)')
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 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.
0.07
g0
g1
g2
g3
4.5
g0
g1
g2
g3
0.06
0.05
3.5
3
0.04
2.5
0.03
1.5
0.02
1
0.01
0.5
0
0
0.2
0.4
0.6
0.8
1
Time (s)
1.2
1.4
1.6
1.8
0
0
0.2
0.4
0.6
0.8
1
Time (s)
1.2
1.4
1.6
1.8
10.4
function Exercise10_4
for m = 1:3
[t0, y0] = ode45(@f, [0 8], [0], [], 10^(m-1), 0, 1);
[t1, y1] = ode45(@f, [0 8], [0], [], 10^(m-1), 1, 1);
[t2, y2] = ode45(@f, [0 8], [0], [], 10^(m-1), 2, 1);
[t3, y3] = ode45(@f, [0 8], [0], [], 10^(m-1), 3, 1);
figure(m)
plot(t0, y0, t1, y1, t2, y2, t3, y3);
legend('none', '(a)', '(b)', '(c)');
title(['Step response with gain = ' num2str(10^(m-1))]);
end
function ydot = f(t, y, p1, p2, p3)
% p1 = gain k
% p2 = nonlinearity type
% p3 = time at step response
e = -y;
if(t > p3)
e = 3-y;
end
switch p2
case 1
v = 0.2*(e^3 - e);
case 2
if(abs(e) > 1)
v = e + sin(e);
else
v = 0;
end
case 3
v = atan(e);
otherwise
v = e;
end
ydot = -y + p1*v;
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 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.
none
none
(a)
(b)
(a)
(b)
(c)
2.5
(c)
1.5
1
1.5
0.5
0.5
0
0
-0.5
0
-0.5
0
2.5
1.5
0.5
0
0
10.5
Lead = tf([1, 6], [1, 50]);
Notch0 = zpk([-3+30i, -3-30i], [-60, -60], 1);
Notch0 = 1/(dcgain(Notch0))*Notch0;
Notch1 = zpk([-3+28i, -3-28i], [-60, -60], 1);
Notch1 = 1/(dcgain(Notch1))*Notch1;
Notch2 = zpk([-3+34i, -3-34i], [-60, -60], 1);
Notch2 = 1/(dcgain(Notch2))*Notch2;
t = linspace(0, 3, 200);
y0 = step(feedback(10.0*Notch0*Lead*Pointer,1), t);
y1 = step (feedback(10.0*Notch1*Lead*Pointer,1), t);
y2 = step (feedback(10.0*Notch2*Lead*Pointer,1), t);
plot(t, y0, t, y1, t, y2)
legend('No notch', 'Notch 1', 'Notch 2')
xlabel('Time (s)')
ylabel('Step response')
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 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.
1.4
No notch
Notch 1
Notch 2
1.2
e
s
n
o
p
s
e
r
p
e
t
S
0.8
0.6
0.4
0.2
0
0
0.5
1.5
Time (s)
2.5
10.6
g0 = tf(9, [1, 0, -9]);
lead = tf([1, 2], [1, 6]);
figure(1)
rlocus(lead*g0)
% Use
% [k, p] = rlocfind(lead*g0)
% to determine suitable gain k
k = 5;
% Now find a range of kd off nominal
kd = linspace(-1, -20, 50);
pMax = zeros(length(kd),1);
for i = 1:length(kd)
g0 = tf(9, [1 0 kd(i)]);
clSys = feedback(k*lead*g0, 1);
pMax(i) = max(real(pole(clSys)));
end
figure(2)
plot(sqrt(-kd), pMax, sqrt(-kd), zeros(length(kd), 1), 'r:')
xlabel('Pole location')
ylabel('Maximum pole')
title('Stability of rocket')
Answers:
Root Loc us
Stability of rocket
1
25
20
0.5
15
s
i
x
A
y
r
a
n
i
g
a
m
I
10
e
l
o
p
m
u
m
i
x
a
M
-5
-0.5
-1
-10
-15
-1.5
-20
-25
-8
-6
-4
-2
Real Ax is
-2
1
1.5
2.5
Pole location
3.5
4.5
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.
10.7
m = 1200; b = 70; kp = 100;
g = tf(1, [m, b]);
% (a)
[y1, t1] = step(feedback(g, kp));
figure(1)
plot(t1, y1)
title('(a) Step response disturbance to ride');
% (b)
[y2, t2] = step(feedback(kp*g, 1));
figure(2)
plot(t2, y2)
title('(b) Step response command to ride');
%(c) - disturbance
figure(3)
hold on
kp = linspace(50, 150, 10);
t = linspace(0, 50, 200);
for i = 1:length(kp)
[y] = step(feedback(g, kp(i)), t);
plot(t, y)
end
title('(c) Step response disturbance to ride');
% (c)- command
figure(4)
hold on
for i = 1:length(kp)
y = step(feedback(kp(i)*g, 1), t);
plot(t, y);
end
title('(c) Step response command to ride');
Answers:
6
x 10
-3
0.7
0.6
0.5
4
0.4
3
0.3
0.2
0.1
0
0
10
15
20
25
30
35
40
45
10
15
20
25
30
35
40
45
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.
x 10
-3
8
0.6
7
0.5
0.4
0.3
3
0.2
2
0.1
0
0
10
15
20
25
30
35
40
45
50
0
0
10
15
20
25
30
35
40
45
50
10.8
m = 5000; k = 8e5; b = 1.2e4;
% (a)
num = [1, 0];
den = [m, b, k];
rlocus(tf(num, den))
% Use
% k = rlocfind(tf(num, den))
% to find stable value of k
k = 114.5e3;
% (b)
plant = tf([b, k], [m, b, k]);
figure(1)
step(plant);
title('Step response of uncontrolled suspension')
figure(2)
bode(plant)
title('Bode plot of uncontrolled suspension')
% (c)
kval = linspace(4e5, 10e5, 20);
t = linspace(0 ,5, 100);
z = zeros(length(kval), length(t));
for i = 1:length(kval)
plant = tf([b, kval(i)], [m, b, kval(i)]);
y = step(plant, t);
z(i,:) = y';
end
figure(3)
mesh(t, kval, z)
xlabel('Time (s)')
ylabel('k (N/m)')
title('Response for various spring constants')
colormap([0 0 0 ])
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 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.
10
1.6
)
B
d
(
1.4
e
d
u
t
i
n
g
a
M
1.2
-10
-20
-30
e
d
u
t
i
l
p
m
A
-40
-50
0.8
0.6
)
g
e
d
(
0.4
e
s
a
h
P
0.2
-45
-90
-135
0
0
0.5
1.5
2.5
3.5
4.5
10
-1
Time (s ec )
10
10
10
10
Frequenc y (rad/s ec )
1.8
1.6
1.4
1.2
1
0.8
0.6
0.4
0.2
0
10
9
8
x 10
4
7
3
6
2
5
k (N/m)
1
4
0
Time (s)
10.9
num = [1, 0.03];
den = conv([1, 0], conv([1, 0.09], conv([1, 0.04], [1, -0.0004])));
g = tf(num, den);
figure(1)
rlocus(g)
title('Root locus of ship system');
% (b)
z = 0.003; p = 10*z;
lead = tf([1 z], [1 p]);
figure(2)
rlocus(lead*g)
% k = rlocfind(lead*g)
k = 3.5e-5; % From the above result
title('Finding a lead controller')
figure(3)
step(feedback(k*lead*g, 1))
title('Step response of lead controller');
% (c)
p = 0.0001;
numPD = conv([1 p], num);
gPD = tf(numPD, den);
figure(4)
rlocus(gPD)
title('Root locus of PD control system');
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.
% k = rlocfind(gPD)
k = 0.0075; % From the above result
kp = p*k;
kd = k;
figure(5)
t = linspace(1, 500, 500);
step(feedback(k*gPD,1),t)
title(['Step response with kp = ' num2str(kp) ' kd = ' num2str(kd)])
Answers:
Finding a lead c ontroller
0.4
0.3
0.3
0.2
0.2
s
i
x
A
y
r
a
n
i
g
a
m
I
s
i
x
A
0.1
0.1
y
r
a
n
i
g
a
m
I
-0.1
-0.1
-0.2
-0.2
-0.3
-0.3
-0.4
-0.35
-0.3
-0.25
-0.2
-0.15
-0.1
-0.05
0.05
0.1
-0.4
-0.4
0.15
-0.3
-0.2
-0.1
0.1
0.2
0.3
Real Ax is
Real Ax is
1.4
0.2
1.2
0.15
0.1
e
d
u
t
i
l
p
m
A
s
i
x
A
y
r
a
n
i
g
a
m
I
0.8
0.6
0.05
-0.05
0.4
-0.1
0.2
-0.15
0
0
200
400
600
800
1000
1200
1400
Time (s ec )
-0.2
-0.1
-0.08
-0.06
-0.04
-0.02
0.02
Real Ax is
1.2
e
d
u
t
i
l
p
m
A
0.8
0.6
0.4
0.2
0
50
100
150
200
250
300
350
400
450
500
Time (s ec )
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.
10.10
G = tf(4, [1 4]);
[nd, dd] = pade(0.2, 10); % Pad approximation of models with time delays
plant = tf(nd, dd)*G;
% (a) PI control
control = tf([1, 2], [1, 0]);
figure(1)
rlocus(control*plant)
% kp = rlocfind(control*plant);
title('Root locus of A/F ratio system');
kp = 1.384;
figure(2);
step(feedback(kp*control*plant, 1))
title(['Step response of PI controller with kp = ' num2str(kp)])
% (b) Smith predictor
% We pick a simple PE control with gain = 10
t = linspace(0, 1, 200);
smith = feedback(10, G*(1-tf(nd, dd)));
figure(3)
step(feedback(smith*plant, 1), t);
title('Step response of ideal smith predictor with kp = 10');
% (c) Smith predictor with incorrect time delays and system model
% First compute the effect of system delay mismatch
figure(4)
hold on
dels = linspace(0.1, 0.3, 10);
for i = 1:length(dels);
[nd, dd] = pade(dels(i),10);
plant1 = tf(nd,dd)*G;
step(feedback(smith*plant1, 1), t)
end
title('Step response with system delay mismatch');
% Now show the effect of system mismatch
G2 = tf(6, [1, 5]);
[nd, dd] = pade(0.2, 10);
plant2 = tf(nd, dd)*G2;
figure(5)
step(feedback(smith*plant2, 1), t)
title('Step response with system mismatch')
Answers:
Step res pons e of PI c ontroller with k p = 1.384
1.4
300
1.2
200
1
s
i
x
A
100
y
r
a
n
i
g
a
m
I
e
d
u
t
i
l
p
m
A
0.8
0.6
0.4
-100
0.2
-200
-300
-300
-0.2
-250
-200
-150
-100
Real Ax is
-50
50
100
150
0.5
1.5
2.5
3.5
4.5
Time (s ec )
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.
1.2
0.8
e
d
u
t
i
l
p
m
A
e
d
u
t
i
l
p
m
A
0.6
0.4
0.2
-1
-2
-0.2
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
-3
Time (s ec )
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
Time (s ec )
1.2
e
d
u
t
i
l
p
m
A
0.8
0.6
0.4
0.2
-0.2
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
Time (s ec )
10.11
w = 250*pi; xi = 20/w;
g = tf(9, [1, 0, 9]);
f = tf(w^2, [1, 2*xi*w, w^2]);
plant = f*g;
z = 8; p = 5*z;
control = tf([1, z], [1, p]);
figure(1)
rlocus(control*plant)
% pause; % readjust scale
% k = rlocfind(control*plant)
k = 75;
figure(2)
step(feedback(k*control*plant,1))
title('Step response of motor cycle system under lead control')
% The effect of the inclinometer's bandwidth limitations
% is negligible on the system right now. If it is shifted
% to a much lower frequency, the control design is much harder
% and the performance unacceptably low
w = 14.8*pi; xi = 0.4;
fp = tf(w^2, [1, 2*xi*w, w^2]);
plantP = fp*g;
figure(3)
rlocus(control*plantP)
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.
% k = rlocfind(control*plantP)
k = 42;
figure(4);
step(feedback(k*control*plantP, 1))
title('Step response with low bandwidth sensor')
Answers:
Root Loc us
4000
1.4
3000
1.2
2000
1
s
i
x
A
1000
y
r
a
n
i
g
a
m
I
e
d
u
t
i
l
p
m
A
0.8
0.6
-1000
0.4
-2000
0.2
-3000
-4000
-4000
0
-3000
-2000
-1000
1000
2000
3000
4000
0.1
0.2
Real Ax is
0.3
0.4
0.5
0.6
Time (s ec )
Root Loc us
Step res pons e with low bandwidth s ens or
200
1.6
150
1.4
100
1.2
s
i
x
A
y
r
a
n
i
g
a
m
I
50
e
d
u
t
i
l
p
m
A
-50
0.8
0.6
-100
0.4
-150
-200
-200
0.2
-150
-100
-50
0
Real Ax is
50
100
150
0
0
0.2
0.4
0.6
0.8
1.2
1.4
Time (s ec )
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 a13
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.
Solution to Exercises
Chapter 11
11.1
function Exercise11_1
g = 9.81; nu = 1.3e-6; k = 0.00026; L = 25.0;
Q = 0.003; h = 3.0; SumKml = 0.5+0.3+0.3+0.15+1.0;
D = fzero(@ColebrookFriction, [0.05], [], g, nu, k, L, Q, h, SumKml);
disp(['D = ' num2str(D)])
function value = ColebrookFriction(D, g, nu, k, L, Q, h, SumKml)
lambda = D^5*h*g*pi^2/(8.0*Q^2*L)-SumKml*D/L;
Re = 4.0*Q/(pi*D*nu);
value = 1/sqrt(lambda)+2*log10((k/D)/3.7+2.51/(sqrt(lambda)*Re));
Answer: D = 0.046979
11.2
function Exercise11_2
p = 0.375; q = 7.43e-4; Z = 5:5:50;
zer = zeros(length(Z),1);
for k = 1:length(Z)
[t, y] = ode45(@ReservoirOsc, [0 500], [Z(k) 0], [], p, q);
ind = min(find(y(:,1)<0));
zer(k) = interp1(y(ind-5:ind+4,1), t(ind-5:ind+4), 0);
end
plot(Z, zer, 'k-')
xlabel('Initial height [Z(0)]')
ylabel('Time to first zero crossing (s)')
function c = ReservoirOsc(t, y, p, q )
c = [y(2); -p*sign(y(2))*y(2)^2-q*y(1)];
Answer:
)
s
(
g
n
i
s
s
o
r
c
o
r
e
z
t
s
r
i
f
280
260
240
220
200
180
o
t
160
e
m
i
T
140
120
100
80
5
10
15
20
25
30
Initial height [Z(0)]
35
40
45
50
11.3
function Exercise11_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 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.
)
s
/
m
(
y
t
i
c
o
l
e
V
l
a
c
i
t
r
e
V
1.4
1.2
1
t = 0.4 s
0.8
0.6
0.4
0.2
-0.2
0
0.001
0.002
0.003
0.004
0.005
y (m)
0.006
0.007
0.008
0.009
0.01
11.4
function Exercise11_4
mu = 0.02; rho = 800.0; nu = mu/rho;
h = 0.02; tau = 0.01; ny = 100; ymax = h;
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.
0.008
0.006
t=1 s
0.004
0.002
0
0
0.5
1
1.5
Horizontal Velocity (m/s)
2.5
11.5
function Exercise11_5
mu = 0.02; rho = 800.0; nu = mu/rho;
h = 0.003; dPdz = 10000; Utop = 1.5;
ny = 100; ymax = h;
y = linspace(0, ymax, ny);
nt = 50; tmax = 1.0;
t = tmax/(nt^2)*(1:nt).^2;
u = pdepe(0, @pdfslpde, @pdfslic, @pdfslbc, y, t, [], nu, dPdz, rho, Utop);
hold on
for ijd = 2:nt
plot(u(ijd,:),y*1000,'k')
end
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
)
m
m
(
1.5
t = 1s
0.5
0
0
0.2
0.4
0.6
0.8
Horizontal Velocity (m/s)
1.2
1.4
1.6
11.6
function Exercise11_6
c = 2; Vinfty = 100;
a = 10; alpha = a*pi/180;
[x, y ]= meshgrid(linspace(-1.0, 3.0, 100), linspace(-1.5, 1.5, 100));
m = 100;
xf = linspace(0.01, c, m);
thetaf = 1.0 - 2.0 .*xf./c;
thetaf = acos(thetaf);
gammaf = 2.0*alpha*Vinfty.*(1.0 + cos(thetaf))./sin(thetaf);
psi = Vinfty*cos(alpha).*y-Vinfty*sin(alpha).*x;
for i = 1:m
r = sqrt((x-xf(i)).^2 + y.^2);
psi = psi + (c/m)*(gammaf(i)/2.0/pi).*log(r);
end
contour(x,y, psi,60 , 'k')
axis equal
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.
Answer:
1.5
0.5
-0.5
-1
-1.5
-1
-0.5
0.5
1.5
2.5
11.7
function Exercise11_7
nx = 100; xmin = -2.5; xmax = 2.5;
ny = 100; ymin = -2.0; ymax = 2.0;
x = linspace(xmin, xmax, nx);
y = linspace(ymin, ymax, ny)';
[x, y]=meshgrid(x ,y);
U0 = 1.0; D = 1.0;
K1 = U0*D^2/4;
xK1 = 0.0; yK1 = 0.75;
K2 = U0*D^2/4; xK2 = 0.0; yK2 = -0.75;
thetaK1 = atan2(y-yK1, x-xK1);
rK1 = sqrt((x-xK1).*(x-xK1)+(y-yK1).*(y-yK1) );
thetaK2 = atan2(y-yK2,x-xK2);
rK2 = sqrt((x-xK2) .* (x-xK2) + (y-yK2) .* (y-yK2) );
StreamFunction = U0.*y - K1.*sin(thetaK1)./ rK1-K2.*sin(thetaK2)./ rK2 ;
levmin = StreamFunction(1,nx);
levmax = StreamFunction(ny,nx/2);
levels = linspace(levmin,levmax,51)';
figure(1)
contour(x,y,StreamFunction,levels)
axis equal
axis([xmin,xmax,ymin,ymax])
ylabel('y')
xlabel('x')
colormap([0 0 0])
x = linspace(xmin,xmax,nx);
thetaK2 = atan2(0.0-yK2,x-xK2);
rK2 = sqrt((x-xK2).*(x-xK2)+(0.0-yK2).*(0.0-yK2));
thetaK1 = atan2(0.0-yK1,x-xK1);
rK1 = sqrt((x-xK1).*(x-xK1)+(0.0-yK1).*(0.0-yK1));
phi=U0*x+K1*cos(thetaK1)./rK1+K2*cos(thetaK2)./rK2;
delx=x(2)-x(1);
figure(2)
plot(x(2:nx), diff(phi)/delx, 'k-')
ylabel('horizontal velocity along the x axis')
xlabel('x')
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.
Answers:
a
x
e
h
t
1.5
g
n
o
l
a
y
t
i
c
o
l
e
v
0.5
l
a
t
n
o
z
i
r
o
h
-0.5
-1
1.8
1.6
1.4
1.2
-1.5
-2
-2.5
-2
-1.5
-1
-0.5
0
x
0.5
1.5
2.5
0.8
-2.5
-2
-1.5
-1
-0.5
0
x
0.5
1.5
2.5
11.8
function Exercise11_8
modes = 20; alpha = 4.*pi/180.0; Vinfty = 100;
chord = 2.0; a = zeros(modes,1); m = 100; n = 200;
tb = acos(1.0-0.2025*2);
a0 = alpha-quadl(@camber1, 0, tb, 1.e-5, [], 0)/pi...
-quadl(@camber2, tb, pi, 1.e-5, [], 0)/pi;
for i = 1:modes
a(i) = 2/pi*quadl(@camber1, 0, tb, 1.e-5, [], i)...
+2/pi*quadl(@camber2, tb, pi, 1.e-5, [], i);
end
q = 1:modes;
disp(['A(0) = ' num2str(a0, '%8.6f')])
fprintf(1, 'A(%2.0f) = %8.6f\n', [q; a'])
xf = linspace(0.001, chord, m);
thetaf = acos(1-2.*xf/chord);
summ = a'*sin(q'*thetaf);
gammaf = 2.0*Vinfty*(a0*(1.0 + cos(thetaf))./sin(thetaf)+summ);
figure(1)
plot(xf, gammaf, 'k-')
hold on
plot(xf, 2.0*Vinfty*summ, 'r--')
[x, y] = meshgrid(linspace(-1.0, 3, n), linspace(-1.5, 1.5, n));
psi = Vinfty*cos(alpha).*y-Vinfty*sin(alpha).*x;
for i = 1:m
r = sqrt((x-xf(i)).^2 + y.^2);
psi = psi + (chord/m)*(gammaf(i)/2.0/pi).*log(r);
end
figure(2)
contour(x, y, psi, 50, 'k')
axis([-1, 2.5, -0.4, 0.4]);
hold on
x = linspace(0.0, 0.2025, m);
z = 2.6595*x.*(x.*x-0.6075*x+0.1147);
h = plot(chord*x, chord*z, 'k-');
set(h, 'LineWidth', 2)
x= linspace(0.2025, 1.0, m);
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.
z= 0.02208*(1.0-x);
h = plot(chord*x, chord*z, 'k-');
set(h, 'LineWidth', 2)
function func = camber1(theta, n)
x = 0.5*(1-cos(theta));
dzdx = 2.6595*(3*x.^2-0.6075*2*x+0.1147);
func = dzdx.*cos(n*theta);
function func = camber2(theta, n)
func = -0.02208*cos(n*theta);
Answers:
A(0) = 0.041156
A( 1) = 0.095484
A( 2) = 0.079150
A( 3) = 0.056780
A( 4) = 0.033789
A( 5) = 0.014870
A( 6) = 0.002613
A( 7) = -0.002884
A( 8) = -0.003450
A( 9) = -0.001674
A(10) = 0.000231
A(11) = 0.001114
A(12) = 0.000910
A(13) = 0.000197
A(14) = -0.000378
A(15) = -0.000499
A(16) = -0.000242
A(17) = 0.000098
A(18) = 0.000269
A(19) = 0.000205
A(20) = 0.000014
400
0.4
350
0.3
300
0.2
250
0.1
200
150
-0.1
100
-0.2
50
-0.3
0
0
0.2
0.4
0.6
0.8
1.2
1.4
1.6
1.8
-0.4
-1
-0.5
0.5
1.5
2.5
11.9
function Exercise11_9
R = 1.0; Q = 1.0; nn = 5;
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.
ylabel('b/L')
Answers:
0.3
0.02
0.018
0.25
0.016
0.014
0.2
0.012
L
/
t
L
/
b
0.15
0.01
0.008
0.1
0.006
0.004
0.05
0.002
0
-0.2
0
-0.15
-0.1
off
-0.05
0.01
0.02
0.03
0.04
off
11.10
function Exercise11_10
R = 1.0; Q = 1.0; alpha = 6.0*pi/180;
ksioff = -0.093*R; etaoff = 0.08*R; zetaoff = complex(ksioff,etaoff);
thetaTE = -asin(etaoff/R);
Gamma = 4*pi*Q*R*sin(alpha-thetaTE);
theta = linspace(0, 2*pi, 1000);
zetac = R*exp(1i*theta)+zetaoff;
ksiTE = ksioff + sqrt(R^2-etaoff^2);
ksiLE = ksioff - sqrt(R^2-etaoff^2);
lambda = ksioff + sqrt(R^2-etaoff^2);
thetaLE = pi-thetaTE;
nplot = 200;
thetatop = linspace(thetaTE,thetaLE,nplot);
thetatemp = zeros(nplot,1);
for ijd = 1:nplot
thetatemp(ijd) = thetatop(nplot+1-ijd);
end
thetatop = thetatemp;
thetabottom = linspace(thetaLE, 2*pi+thetaTE, nplot);
zetatop = R*exp(1i*thetatop)+zetaoff;
zetabottom = R*exp(1i*thetabottom)+zetaoff;
ztop = zetatop+lambda^2./zetatop;
zbottom = zetabottom+lambda^2./zetabottom;
ytop = imag(ztop);
xtop = real(ztop);
plot(ztop, 'k-')
hold on
plot(zbottom, 'k-')
hold on
axis([xtop(1)-0.5, xtop(nplot)+0.5, -3, 2])
xlabel('x')
ylabel('y or C_p')
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.
w = (Q*exp(-1i*alpha)-Q*exp(1i*alpha)*R^2./(zetatop-zetaoff).^2+ ...
1i*Gamma/(2*pi)./(zetatop-zetaoff))./(1.0-lambda^2./zetatop.^2);
qsquared = w.*conj(w);
Cptop = 1.0-qsquared/Q^2;
plot(real(ztop(1:nplot-1)), Cptop(1:nplot-1), 'k:')
hold on
w = (Q*exp(-1i*alpha)-Q*exp(1i*alpha)*R^2./(zetabottom-zetaoff).^2+ ...
1i*Gamma/(2*pi)./(zetabottom-zetaoff))./(1.0-lambda^2./zetabottom.^2);
qsquared = w.*conj(w);
Cpbottom = 1.0-qsquared/Q^2;
plot(real(zbottom(1:nplot-1)), Cpbottom(1:nplot-1), 'k--')
Answer:
2
1.5
0.5
0
C
rp
o
-0.5
y
-1
-1.5
-2
-2.5
-3
-2
-1.5
-1
-0.5
0
x
0.5
1.5
11.11
function Exercise11_11
R = 1.0; Q=1.0;
nalpha = 21; alphamin = -10; alphamax = 10;
alpha = linspace(alphamin, alphamax, nalpha)*pi/180;
ksioff = -0.093*R; neta = 5;
etaoffarray = linspace(0.0,0.08,neta)*R;
maxthick = zeros(neta,1);
maxcamber = zeros(neta,1);
hold on
for in = 1:neta
%foil geometry
etaoff = etaoffarray(in);
thetaTE = -asin(etaoff/R);
Gamma = 4*pi*Q*R*sin(alpha-thetaTE);
lambda = ksioff+sqrt(R^2-etaoff^2);
ksiTE = ksioff+sqrt(R^2-etaoff^2);
ksiLE = ksioff-sqrt(R^2-etaoff^2);
zetaTE = complex(ksiTE,0);
zetaLE = complex(ksiLE,0);
zTE = zetaTE+lambda^2/zetaTE;
zLE = zetaLE+lambda^2/zetaLE;
chord = real(zTE-zLE);
thetaLE = pi-thetaTE;
nplot = 200;
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.
thetatop = linspace(thetaTE,thetaLE,nplot);
thetatemp = zeros(1,nplot);
for ijd = 1:nplot
thetatemp(ijd) = thetatop(nplot+1-ijd);
end
thetatop = thetatemp;
thetabottom = linspace(thetaLE, 2*pi+thetaTE, nplot);
zetaoff = complex(ksioff,etaoff);
zetatop = R*exp(1i*thetatop)+zetaoff;
zetabottom = R*exp(1i*thetabottom)+zetaoff;
ztop = zetatop+lambda^2./zetatop;
zbottom = zetabottom+lambda^2./zetabottom;
ytop = imag(ztop);
xtop = real(ztop);
xtopeven = linspace(xtop(1),xtop(nplot),nplot);
ytopeven = interp1(xtop,ytop,xtopeven);
ybottom = imag(zbottom);
xbottom = real(zbottom);
xbottomeven = linspace(xbottom(1),xbottom(nplot),nplot);
ybottomeven = interp1(xbottom,ybottom,xbottomeven);
ythickness = (ytopeven-ybottomeven);
ymidline = (ytopeven+ybottomeven)/2;
maxthick(in) = max(ythickness)/chord;
maxcamber(in) = max(ymidline)/chord;
%Lift calculation
LiftCoeff = Q*Gamma/(0.5*Q^2*chord);
plot(alpha*180/pi, LiftCoeff, 'k-')
end
axis([alphamin, alphamax, -3, 3])
grid on
box on
xlabel('\alpha (degrees)')
ylabel('C_L')
text(0.4, -0.8, ['t/L=' num2str(maxthick(1),4) ...
' b/L=' num2str(maxcamber(1), '%2.1f')])
plot([0.3,-2.8], [-0.8,-0.375], '-k')
hold on
text(-7.6, 1.2, ['t/L=' num2str(maxthick(5),4) ...
' b/L=' num2str(maxcamber(5),4)])
plot([-7.3,-3.0], [1.05,0.3], '-k')
Answer:
3
t/L=0.1215 b/L=0.04013
1
t/L=0.1205 b/L=0.0
-1
-2
-3
-10
-8
-6
-4
-2
10
(degrees)
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.
11.12
function Exercise11_12
n = 0.014; yr = 3.0; g = 9.81;
b = 1.5; m = 1.0;
ywcrit = fzero(@Channel1, 6, [], b, m, yr);
Awcrit = b*ywcrit*(2+ywcrit/(b*m));
Qcrit = Awcrit*sqrt(2*g*(yr-ywcrit));
Pwcrit = 2*(b+ywcrit*sqrt(1+1/m^2));
Rhwcrit = Awcrit/Pwcrit;
S0crit = (Qcrit*n/(1.0*Awcrit*Rhwcrit^0.666))^2;
nslope = 100;
Slope = linspace(0.00001, S0crit-0.0001, nslope);
ywflow = zeros(nslope,1);
for is = 1:nslope
S0 = Slope(is);
ywflow(is) = fzero(@Channel2, [ywcrit, yr], [], b, m, S0, n, g, yr);
end
Awflow = b*ywflow.*(2+ywflow/(b*m));
Qflow = Awflow.*sqrt(2*g*(yr-ywflow));
Smax = 0.0025;
plot(Slope*1000, Qflow, 'k')
axis([0, Smax*1000, 0, 60])
xlabel('Channel Slope \times 10^{-3}')
ylabel('Flow rate (m^3/s)')
hold on
plot(S0crit*1000, Qcrit, 'ks')
hold on
plot([Slope(nslope)*1000, S0crit*1000], [Qflow(nslope), Qcrit])
hold on
plot([S0crit*1000, Smax*1000], [Qcrit, Qcrit], 'k')
hold on
text(0.75, 30, ['Critical Flow Rate = ' num2str(Qcrit,5) ' m^3/s'])
text(0.75, 27, ['Critical Slope = ' num2str(S0crit,4)])
plot([1.65, (S0crit)*1000], [32, Qcrit], 'k')
function y = Channel1(ywc,b,m,yr)
y = ywc+0.5*b*ywc*(2+ywc/(b*m))/(2*b+2*ywc/m)-yr;
function y = Channel2(y,b,m,S0,n,g,yr)
y = (b*y*(2+y/(b*m)))*(((b*y*(2+y/(b*m)))/(2*(b+y*sqrt(1+1/m^2))))^0.6666* ...
sqrt(S0))/n-sqrt(2*g*b^2*(yr-y)*(2*y+y^2/(b*m))^2);
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 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.
60
50
m
(
)e
s
t
3/a
r
40
30
w
o
l
F
/s
20
10
0
0
0.5
1
Channel Slope
1.5
2.5
10 -3
11.13
function Exercise11_13
g = 9.81; m = 1.0; slope = 0.003; b = 1.5;
Q = 45.3336; n = 0.014;
y0 = fzero(@flow1, 6, [], Q, n, b, m, slope);
A0 = b*y0*(2+y0/(b*m));
P0 = 2*(b+y0*sqrt(1+1/m^2));
yc = fzero(@flow2, 3, [], Q, g, b, m);
[y, x] = ode45(@dchannel, [yc, 0.94*y0], 0, [], yc, y0, slope);
xmax = 1000; xmin = 0.0;
plot(x, y, 'k')
axis([0, 1000, 1.5, 2.5])
xlabel('x (m)')
ylabel('Water depth, y (m)')
hold on
plot([xmin,xmax], [y0,y0],' --k')
text((xmax-xmin)/2, y0-0.05, 'y_0')
plot([xmin,xmax], [yc,yc], '--k')
text((xmax-xmin)/2, yc+0.04, 'y_c')
function f = flow1(y, Q, n, b, m, slope)
f = Q-1.0/n*b*y*(2+y/(b*m))*(b*y*(2+y/(b*m))/(2*(b+y*sqrt(1+1/m^2))))^0.667*sqrt(slope);
function f = flow2 (y, Q, g, b, m)
f = Q^2-g*(b*y*(2+y/(b*m)))^3/(2*b+2*y/m);
function dydx = dchannel(y, x, yc, y0, slope)
dydx(1) = 1/slope*(1-(yc/y(1))^3)/(1-(y0/y(1))^(10/3));
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 a13
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.
2.5
2.4
)
m
(
2.3
2.2
,
h
t
p
e
d
2.1
y0
2
r
e
t
1.9
a
W
1.8
1.7
1.6
1.5
0
100
200
300
400
500
x (m)
600
700
800
900
1000
11.14
function Exercise1114
omega = 2*pi; nu = 5.0*10^(-6);
rho = 1000; dPdz = -1e6;
nr = 200; nt = 16; tmax = 2*2*pi/omega;
t = linspace(0, tmax, nt);
rmax = [0.001, 0.005, 0.01];
for kk = 1:3
subplot(3,1,kk)
r = linspace(0, rmax(kk),nr);
u = pdepe(1, @pulse14, @pulseic14, @pulsebc14, r, t, [], omega, nu, rho, dPdz);
hold on
for ijd = 1:nt
plot(u(ijd,:)/(dPdz/rho/omega)+(ijd-1),r/rmax(kk),'k')
plot(u(ijd,:)/(dPdz/rho/omega)+(ijd-1),-r/rmax(kk),'k')
plot([(ijd-1),(ijd-1)],[-1,1],':k')
end
xlabel('u_z/[\partialP/\partialz/(\rho\omega)]')
ylabel('r/R')
title(['R = ', num2str(rmax(kk)*1000'), ' mm'])
box on
end
function [c, f, s] = pulse14(r, t, u, DuDr, omega, nu, rho, dPdz)
c = 1.0;
f = nu*DuDr;
s = (dPdz/rho)*sin(omega*t);
function u0 = pulseic14(r, omega, nu, rho, dPd)
u0 = 0;
function [pl, ql, pr, qr] = pulsebc14(rl, ul, rr, ur, t, omega, nu, rho, dPdz)
pl = 0; ql = 1;
pr = 0; qr = ur;
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 a14
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.
R = 1 mm
1
0.5
R
/
r
0
-0.5
-1
10
15
10
15
10
15
u /[ P/ z/( )]
z
R = 5 mm
1
0.5
R
/
r
0
-0.5
-1
5
u /[ P/ z/( )]
z
R = 10 mm
1
0.5
R
/
r
0
-0.5
-1
0
5
u /[ P/ z/( )]
z
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 a15
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.
Solution to Exercises
Chapter 12
12.1
syms eta t
th = 1-erf(eta/(2*t))-exp(eta+t^2)*(1-erf(eta/(2*t)+t));
dt = simple(diff(th,t,1));
deta2 = simple(diff(th,eta,2));
Eqn = simple(deta2-dt/(2*t))
BC = simple(subs(th, eta, 0)-1-subs(diff(th,eta,1), eta, 0))
12.2
tau = @(x) (exp(x.^2).*erfc(x)-1/2);
tauHalf = fzero(tau, 0.5)
Answer: tauHalf = 0.7691
12.3
function Exercise12_3
tspan = [0, 10^5]; y0 = 5; Tamb = 30;
h = 2; A = 0.3; Tinf = 30; m = 3.5; c = 4.2;
emm = 0.5; sigma = 5.667e-8;
[t, T] = ode45(@odefun1, tspan, y0, [], h , A , Tinf, m, c);
% Convection only
[tr, Tr] = ode45(@odefun2, tspan, y0, [], h , A , Tinf, m, c, emm, sigma); % Convection and radiation
plot(t/3600, T, 'k-', tr/3600, Tr, 'k--')
xlabel('Time (hr)')
ylabel('Temperature (\circC)')
legend('Convection only','Convection + radiation', 4)
theta = (Tamb-T)/(Tamb-y0);
tau = interp1(theta, t, 0.368)/3600
thetar = (Tamb-Tr)/(Tamb-y0);
taur = interp1(thetar, tr, 0.368)/3600
function dy = odefun1(t, T, h , A , Tinf, m, c)
dy = -h*A*(T-Tinf)/(m*c*1000);
% Convection only
taur = 2.7700
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.
30
25
(
e
r
)u
C
t
20
a
r
e
p
m
e
T
15
10
Convection only
Convection + radiation
5
0
10
15
Time (hr)
20
25
30
12.4
function Exercise12_4
L = 0.1; k = 200; h = 100; P = 0.1;
Ac = 0.001; t = L/100;
Msqu = 2 *h*L^2/(k*t)*sqrt(1+(t/(2*L))^2);
solinit = bvpinit(linspace(0, 0.9999, 8), [0,0]);
sol = bvp4c(@Fin, @Finbc, solinit, [], Msqu);
x = linspace(0, 0.99);
y = deval(sol, x);
etaf = -1/Msqu*y(2,1)
M = sqrt(Msqu);
etafAnal = 1/M*besseli(1, 2*M)/besseli(0, 2*M)
subplot(2, 1, 1)
plot(x, y(1,:), 'k-')
title('1-D Triangular Fin')
xlabel('\eta')
ylabel('\theta')
subplot(2, 1, 2)
q = -k*y(2,:);
plot(x, q(:), 'k-')
xlabel('x (m)')
ylabel('q" (W/m^2)')
function dydx = Fin(x, y, Msqu)
dydx = [y(2); (y(2)+Msqu*y(1))/(1-x)];
function res = Finbc(ya, yb, Msqu)
res = [ya(1)-1; yb(2)];
Answers: etaf = 0.2900
etafAnal = 0.2900
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.
0.4
0.2
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
0.6
0.7
0.8
0.9
600
500
m 400
/
2)W
300
(
"
q
200
100
0
0
0.1
0.2
0.3
0.4
0.5
x (m)
12.5
h = 5; k = 0.1; ri = 0.01; L = 1; Ti = 100; Tinf = 20;
r0 = linspace(ri, 5*k/h, 100);
q = 2*pi*L*(Ti-Tinf)./(1/k.*log(r0./ri)+1./(r0*h));
plot(r0, q, 'k-')
xlabel('r_0 (m)')
ylabel('Heat transfer rate (W)')
Answer:
30
)
W
(
e
t
a
r
r
e
f
s
n
a
r
t
t
a
e
H
29
28
27
26
25
24
23
22
21
20
0.01
0.02
0.03
0.04
0.05
0.06
r0 (m)
0.07
0.08
0.09
0.1
0.11
12.6
function Exercise12_6
Bi = .5; Nroot = 15;
CylinderRoots = inline('x.*besselj(1, x)-Bi*besselj(0, x)', 'x', 'Bi');
d = FindZeros(CylinderRoots, Nroot, linspace(0, 50, 200), Bi);
Cn = 2*besselj(1, d)./(d.*(besselj(0, d).^2+besselj(1, d).^2));
tau = fzero(@Flip, 0.5, [], d, Cn)
function gg = Flip(t, d, Cn)
gg = 0.5-sum(Cn.*exp(-t*d.^2).*besselj(0,d));
function Rt = FindZeros(FunName, Nroot, x, w) % See Section 5.5.1
f = feval(FunName, x, w);
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.
indx = find(f(1:end-1).*f(2:end)<0);
L = length(indx);
if L<Nroot
Nroot = L;
end
Rt = zeros(Nroot, 1);
for k = 1:Nroot
Rt(k) = fzero(FunName, [x(indx(k)), x(indx(k)+1)], [], w);
end
Answer: tau = 0.6401
12.7
Bi = 0.5; Nroot = 20; ntime = 30;
timeMax = 0.5; nradial = 25;
tau = linspace(0, timeMax, ntime);
xi = linspace(0.001, 1, nradial);
SphereRoots = inline('sin(x)-Bi*sin(x)-x.*cos(x)', 'x', 'Bi');
zet = FindZeros(SphereRoots, Nroot, linspace(0.1, 70, 120), Bi); % See Exercise 12.6
Cn = 4.*(sin(zet)-zet.*cos(zet))./(2*zet-sin(2*zet));
[dum, Cnn] = meshgrid(xi, Cn);
theta = exp(-zet.^2*tau)'*(Cnn.*sin(zet*xi)./(zet*xi));
mesh(xi, tau, theta)
colormap([0 0 0])
xlabel('\zeta')
ylabel('\tau')
zlabel('\theta')
view(49.5,-34)
Answer:
1.1
1
0.9
0.8
0.7
0.6
0.5
1
0.4
0
0.8
0.1
0.6
0.2
0.4
0.3
0.2
0.4
0.5
12.8
function Exercise12_8
CylinderRoots = inline('x.*besselj(1, x)-Bi*besselj(0, x)', 'x', 'Bi');
Bi = .5; Nroots = 15; tau = [0, 0.001, 0.005];
xi = linspace(0, 1, 100);
r = FindZeros(CylinderRoots, Nroots, linspace(0.1, 60, 100), Bi);
Cnn = Cn(r); co = char('k-', 'k--', 'k:.');
T = zeros(length(xi),1);
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.
for k = 1:length(tau)
for n = 1:length(xi)
T(n) = sum(Cnn.*besselj(0, r*xi(n)).*exp(-tau(k)*r.^2));
end
plot(xi, T, co(k,:))
hold on
end
legend(['\tau = ' num2str(tau(1))], ['\tau = ' num2str(tau(2))], ['\tau = ' num2str(tau(3))], 'Location','SouthWest')
ylim([0.98, 1.005])
function res = Cn(r)
res = 2*besselj(1, r)./(r.*(besselj(0, r).^2+besselj(1, r).^2));
Answer:
1.005
0.995
),
(
0.99
0.985
=0
= 0.001
= 0.005
0.98
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
12.9
function Exercise12_9
CylinderRoots = inline('x.*besselj(1, x)-Bi*besselj(0, x)', 'x', 'Bi');
Bi = .5; Nroots = 15;
r = FindZeros(CylinderRoots, Nroots, linspace(0.1, 60, 100), Bi);
tau = fzero(@Flux, 1, [], r)
function res = Flux(t, r)
res = 1/exp(1)-sum(2*besselj(1, r)./(r.*(besselj(0, r).^2+besselj(1, r).^2)).*exp(-t*r.^2));
Answer: tau = 1.2521
12.10
function Exercise12_10
L = 0.1; flux = 12.5; TL = 300;
k0 = 0.048; ks = 0.00032;
solinit = bvpinit(linspace(0, L, 10), [100]);
sol = bvp4c(@heatVark, @heatbc, solinit, [], flux, k0, ks, TL);
x = linspace(0, L, 10);
T = deval(sol, x);
AnalSol = inline('k0*(T-TL)-ks/2*(T.^2-TL^2)-q*(x-L)', 'T', 'k0', 'ks', 'TL', 'x', 'q', 'L');
T0anal = fzero(AnalSol, [250 350], [], k0, ks, TL, 0, flux, L);
k0 = -k0+ks*mean(T(1,:)); ks = 0.0;
solavg = bvp4c(@heatVark, @heatbc, solinit, [], flux, k0, ks, TL);
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.
12.11
Tb = 80; Tinf = 100; h = 25; d = 0.005; P = pi*d;
Ac = pi*d^2/4; Np = 20;
k = [20, 100, 200, 300, 400];
L = linspace(0.005, 0.1, Np);
col = char('k-', 'b-', 'r-', 'g-', 'c-');
for i = 1:length(k)
y = (Tb-Tinf)./cosh(sqrt(h*P/(k(i)*Ac))*L);
plot(L, y, col(i,:))
hold on
end
% plot(L, y(1,:), L, y(2,:), L, y(3,:), L, y(4,:), L, y(5,:))
legend('k = 20 W/m-K', num2str(k(2)), num2str(k(3)), num2str(k(4)), num2str(k(5)), 'Location', 'NorthWest')
xlabel('L (m)')
ylabel('Temperature Error (K)')
Answer:
0
)
K
(
r
o
r
r
E
e
r
u
t
a
r
e
p
m
e
T
-2
k = 20 W/m-K
100
200
300
-4
400
-6
-8
-10
-12
-14
-16
-18
-20
0
0.01
0.02
0.03
0.04
0.05
L (m)
0.06
0.07
0.08
0.09
0.1
12.12
function Exercise12_12
Tw = 40; qw = 10; Re = 40; Pr = 5;
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.
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.
2.5
12
2
10
1.5
u
N
1
7
0.5
5
0
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
40
35
30
25
20
1
0.8
0.8
0.6
0.6
0.4
0.4
0.2
0.2
Axial distance
Radial Distance
12.13
function Exercise12_13
Pr = [0.07, 0.7, 7.0]; etaMax = [15, 8, 8]; xm = [15, 5, 5];
disp(['
Pr
d_u
d_T
d_u/d_T Pr^(1/3)'])
for k = 1:3
figure(k)
solinit = bvpinit(linspace(0, etaMax(k), 8), @BlasiusTguess);
sol = bvp4c(@BlasiusT, @BlasiusTbc, solinit, [], Pr(k));
eta = linspace(0, etaMax(k), 1000);
y = deval(sol, eta);
subplot(2, 1, 1)
plot(eta, y(1,:), '-.k', eta, y(2,:), '-k', eta,y(3,:), '--k')
xlabel('\eta')
ylabel('y_i (i = 1, 2, 3)')
legend('Stream function', 'Velocity', 'Shear', 'Location', 'NorthWest')
title(['Pr = ' num2str(Pr(k))])
axis([0, xm(k), 0, 2])
subplot(2, 1, 2)
plot(eta, y(4,:), '-k', eta, y(5,:), '--k')
axis([0, xm(k), 0, 2])
legend('Temperature', 'Heat flux', 'Location', 'NorthWest')
xlabel('\eta')
ylabel('y_i (i = 4, 5')
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.
eta_ubl = eta(find(y(2,:)>0.99,1,'first'));
% Velocity boundary layer thickness
eta_Tbl = eta(find(y(4,:)>0.99, 1, 'first')); % Temperature boundary layer thick
disp([Pr(k), eta_ubl, eta_Tbl, eta_ubl/eta_Tbl, Pr(k)^(1/3)])
end
function F = BlasiusT(eta, y, Pr)
F=[y(2); y(3); -0.5*y(1)*y(3); y(5); -Pr*0.5*y(1)*y(5)];
function res=BlasiusTbc(ya, yb, Pr)
res = [ya(1); ya(2); ya(4); yb(2)-1; yb(4)-1];
function y = BlasiusTguess(eta)
y = [eta, eta^0.5, 5-eta, eta/10, 0.5*(1-eta/10)];
Answers:
)
3
Pr
d_u
d_T
d_u/d_T Pr^(1/3)
0.0700 4.9249 13.6637 0.3604 0.4121
0.7000 4.9169 5.6296 0.8734 0.8879
7.0000 4.9169 2.4505 2.0065 1.9129
Pr = 0.07
)
3
,
2
Stream function
Velocity
Shear
1.5
,
1
=
Velocity
1.5
1
i
Stream function
,
1
i
(
y
Pr = 0.7
2
,
2
Shear
i
(
0.5
10
0.5
15
0.5
1.5
3.5
4.5
3.5
4.5
Temperature
,
4
Heat flux
1.5
Temperature
,
4
Heat flux
1.5
i
(
y
2.5
i
(
0.5
0
0
10
15
0.5
)
3
0.5
1.5
2.5
Pr = 7
2
,
2
Stream function
Velocity
Shear
1.5
,
1
=
i
(
y
0.5
0.5
1.5
2.5
3.5
4.5
3.5
4.5
2
5
Temperature
,
4
Heat flux
1.5
=
1
i
(
y
0.5
0
0
0.5
1.5
2.5
12.14
function Exercise12_14
Pr = 0.7; etaMax = 8; xm = 5;
solinit = bvpinit(linspace(0, etaMax, 8), @BlasiusTguess);
sol = bvp4c(@BlasiusT, @BlasiusTbc, solinit, [], Pr);
eta = linspace(0, etaMax);
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.
y = deval(sol, eta);
uinf = 1; nu = 1.5e-5; Rec = 5e5;
xc = Rec*nu/uinf;
yy = 10*xc/sqrt(Rec);
x = linspace(.001, xc, 50);
yx = linspace(0.001, yy, 30);
[X, Y] = meshgrid(x, yx);
et = Y.*(uinf./sqrt(nu*X));
T = interp1(eta, y(4,:), et);
[c, h] =contour(X, Y, T);
clabel(c,h)
xlabel('x (m)')
ylabel('y (m)')
title('Isotherms')
ylim([0 .07])
function F = BlasiusT(eta, y, Pr)
F=[y(2); y(3); -0.5*y(1)*y(3); y(5); -Pr*0.5*y(1)*y(5)];
function res=BlasiusTbc(ya, yb, Pr)
res = [ya(1); ya(2); ya(4); yb(2)-1; yb(4)-1];
function y = BlasiusTguess(eta)
y = [eta, eta^0.5, 5-eta, eta/10, 0.5*(1-eta/10)];
Answer:
Isotherms
0.05
0.045
0.04
0.9
0.035
)
m
(
0.03
0.9
0.025
0.8
0.8
0.7
y
0.02
0.015
0.01
0.7
0. 8
0.6
0.5
0.7
0.5
0.4
0.6
0.4
0.3
0.5
0.4
0.3
0.2
0.1
0.005
0.6
0. 9
0.3
0.2
0.2
0.1
0.1
0
1
x (m)
12.15
function Exercise12.15
Pr = 0.7; etaMax = 8; xm = 5;
solinit = bvpinit(linspace(0,etaMax,8), @BlasiusTguess);
sol = bvp4c(@BlasiusT, @BlasiusTbc, solinit, [], Pr);
eta = linspace(0, etaMax);
y = deval(sol, eta);
uinf = 1; nu = 1.5e-5; Rec = 5e5;
xc = Rec*nu/uinf;
yy = 10*xc/sqrt(Rec);
x = linspace(.001, xc, 50);
yx = linspace(0.001, yy, 30);
[X, Y] = meshgrid(x, yx);
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.
et = Y.*sqrt(uinf./(nu*X));
SF = interp1(eta, y(1,:), et).*uinf.*sqrt(nu*X/uinf);
[c, h] =contour(X, Y, SF, 10);
clabel(c, h)
xlabel('x (m)')
ylabel('y (m)')
title('Isotherms')
ylim([0.01, 0.09])
function F = BlasiusT(eta, y, Pr)
F=[y(2); y(3); -0.5*y(1)*y(3); y(5); -Pr*0.5*y(1)*y(5)];
function res=BlasiusTbc(ya, yb, Pr)
res = [ya(1); ya(2); ya(4); yb(2)-1; yb(4)-1];
function y = BlasiusTguess(eta)
y = [eta, eta^0.5, 5-eta, eta/10, 0.5*(1-eta/10)];
Answer:
Isotherms
0.09
0.08
0.054066
0.07
0.048061
0.06
)
m
(
0.042055
0.042055
0.03605
0.05
0.03605
0.030044
y
0.030044
0.024039
0.04
0.024039
0.018033
0.024039
0.018033
0.03
0.012028
0.018033
0.012028
0.012028
0.02
0.0060227
0.0060227
0.0060227
0.01
1
x (m)
12.16
function Exercise12_16
Pr = [0.07, 0.7, 7]; etaMax = [11, 8, 8]; xm = [10, 5, 5]; ym = [2, 0.8, 0.5];
for k = 1:3
figure(k)
solinit = bvpinit(linspace(0, etaMax(k), 5), @NaturalConvGuess);
sol = bvp4c(@NaturalConv, @NaturalConvbc, solinit, [], Pr(k));
eta = linspace(0, etaMax(k), 300);
y = deval(sol, eta);
subplot(2, 1, 1)
plot(eta, y(1,:), '-.k', eta,y(2,:), '-k', eta, y(3,:), '--k')
legend('Stream function', 'Velocity', 'Shear')
axis([0, xm(k), -0.2, ym(k)])
xlabel('\eta')
ylabel('y_i (i = 1, 2, 3)')
title(['Pr = ' num2str(Pr(k))])
subplot(2, 1, 2)
plot(eta, y(4,:), '-k', eta, y(5,:), '--k')
legend('Temperature', 'Heat flux')
axis([0 xm(k) -1.2 1])
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.
xlabel('\eta')
ylabel('y_i (i = 4, 5)')
[etaMaxv, Vmax] = fminbnd(@Vel, 0,5, [], eta, y(2,:));
disp(['Pr = ' num2str(Pr(k)) ' etaMax = ' num2str(etaMaxv) ' Vmax =' num2str(-Vmax)])
end
function ff = NaturalConv(eta,y,Pr)
ff = [y(2); y(3); -3*y(1)*y(3)+2*y(2)^2-y(4); y(5); -3*Pr*y(1)*y(5)];
function res = NaturalConvbc(ya,yb,Pr)
res=[ya(1); ya(2); ya(4)-1; yb(2); yb(4)];
function y = NaturalConvGuess(eta)
y = [eta, eta-eta^2/10, 1-eta, 1-eta/10, -.5*(1-eta/10)];
function V = Vel(x, eta, y2)
V=-spline(eta, y2, x);
Answers: Pr = 0.07 etaMax = 1.2307 Vmax =0.4551
Pr = 0.7 etaMax = 0.96452 Vmax =0.27838
Pr = 7 etaMax = 0.72832 Vmax =0.13138
)
3
)
3
Pr = 0.07
2
,
2
Stream function
Velocity
0.6
,
1
Shear
0.4
i
(
y
Velocity
Shear
1.5
,
1
Pr = 0.7
0.8
,
2
Stream function
i
(
0.5
0.2
i
0
0
0
-0.2
10
0.5
1.5
Heat flux
0.5
4.5
Temperature
,
4
Heat flux
0.5
i
(
y
3.5
)
5
Temperature
,
4
)
5
2.5
i
(
i
-0.5
-1
-0.5
-1
0
10
0.5
1.5
)
3
0.5
,
2
0.4
,
1
0.3
3.5
4.5
Pr = 7
Stream function
Velocity
Shear
0.2
0.1
i
(
y
2.5
0
-0.1
-0.2
0.5
1.5
2.5
3.5
4.5
)
5
Temperature
,
4
Heat flux
0.5
i
(
y
-0.5
-1
0
0.5
1.5
2.5
3.5
4.5
12.17
function Exercise12_17
Pr = [0.07, 0.7, 7]; etaMax = [11, 8, 8]; xm = [10, 5, 5]; ym = [2, 0.8, 0.5];
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.
for k = 1:3
solinit = bvpinit(linspace(0, etaMax(k), 5), @NaturalConvGuess);
sol = bvp4c(@NaturalConv,@NaturalConvbc, solinit, [], Pr(k));
eta = linspace(0, etaMax(k), 300);
y = deval(sol, eta);
[etaMaxv Vmax] = fminbnd(@Vel, 0, 5, [], eta, y(2,:));
Vmax = -Vmax;
delV = spline(y(2, 2:end)/Vmax, eta(2:end), 0.01);
delT = spline(y(4, 2:end), eta(2:end), 0.01);
disp(['Pr = ' num2str(Pr(k)) ' deltaT = ' num2str(delT) ' deltaV = ' num2str(delV)])
end
function ff = NaturalConv(eta, y, Pr)
ff = [y(2); y(3); -3*y(1)*y(3)+2*y(2)^2-y(4); y(5); -3*Pr*y(1)*y(5)];
function res = NaturalConvbc(ya, yb, Pr)
res=[ya(1); ya(2); ya(4)-1; yb(2); yb(4)];
function y = NaturalConvGuess(eta)
y = [eta, eta-eta^2/10, 1-eta, 1-eta/10, -.5*(1-eta/10)];
function V = Vel(x, eta, y2)
V=-spline(eta, y2, x);
Answer: Pr = 0.07 deltaT = 10.2661 deltaV = 9.4841
Pr = 0.7 deltaT = 4.4729 deltaV = 5.6483
Pr = 7 deltaT = 1.7772 deltaV = 6.4123
12.18
function Exercise12_18
Pr = 0.7; etaMax = 8; xm = 5 ;ym = 0.8;
g = 9.98; Tinf = 300; Ts = 400; nu = 1.6e-5;
beta = 1/Tinf; x = 0.1:0.1:0.5;
solinit = bvpinit(linspace(0,etaMax,5), @NaturalConvGuess);
sol = bvp4c(@NaturalConv, @NaturalConvbc, solinit, [], Pr);
eta = linspace(0, etaMax, 100);
y = deval(sol, eta);
y1 = linspace(1e-5, 0.01, 100);
co = g*beta*(Ts-Tinf)/nu^2;
u1 = zeros(length(x), length(y1)); v1 = u1;
for i = 1:length(x)
Gr = co*x(i)^3;
eta1 = y1/x(i)*(Gr/4)^0.25;
u1(i,:) = spline(eta, y(2,:), eta1)*sqrt(Gr)*2*nu/x(i);
fp = spline(eta, y(2,:), eta1);
f = spline(eta, y(1,:), eta1);
v1(i,:) = nu./x(i).*(Gr/4)^0.25.*(eta1.*fp-3*f);
end
subplot(2, 1, 1)
plot(y1, u1(1,:), y1,u1(2,:), y1, u1(3,:), y1, u1(4,:), y1, u1(5,:))
xlabel('y (m)')
ylabel('u (m/s)')
subplot(2, 1, 2)
plot(y1, v1(1,:), y1, v1(2,:), y1, v1(3,:), y1, v1(4,:), y1, v1(5,:))
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 a13
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.
xlabel('y (m)')
ylabel('v (m/s)')
legend('x = 0.1 m', 'x = 0.2', 'x = 0.3', 'x = 0.4.', 'x = 0.5', 'Location', 'SouthWest')
function ff = NaturalConv(eta, y, Pr)
ff = [y(2); y(3); -3*y(1)*y(3)+2*y(2)^2-y(4); y(5); -3*Pr*y(1)*y(5)];
function res = NaturalConvbc(ya, yb, Pr)
res=[ya(1); ya(2); ya(4)-1; yb(2); yb(4)];
function y = NaturalConvGuess(eta)
y = [eta, eta-eta^2/10, 1-eta, 1-eta/10, -.5*(1-eta/10)];
function V = Vel(x, eta, y2)
V=-spline(eta, y2, x);
Answer:
0.8
)
s
/
m
(
0.6
0.4
u
0.2
0.001
0.002
0.003
0.004
0.005
0.006
0.007
0.008
0.009
0.01
0.006
0.007
0.008
0.009
0.01
y (m)
0
-0.002
)
s
/
m
(
v
-0.004
-0.006
x = 0.1 m
x = 0.2
-0.008
x = 0.3
-0.01
x = 0.4.
x = 0.5
-0.012
0
0.001
0.002
0.003
0.004
0.005
y (m)
12.19
function Exercise12_19
Pr = 0.7; etaMax = 8; xm = 5 ;ym = 0.8;
solinit = bvpinit(linspace(0,etaMax,5), @NaturalConvGuess);
sol = bvp4c(@NaturalConv, @NaturalConvbc, solinit, [], Pr);
eta = linspace(0, etaMax, 300);
y = deval(sol, eta);
g = 9.98; Tinf = 300; Ts = 400; nu = 1.6e-5;
beta = 1/Tinf; co =g*beta*(Ts-Tinf)/nu^2;
y1 = linspace(.001, 0.035, 30);
x1 = linspace(.001, 1, 50);
[X Y] = meshgrid(x1, y1);
Gr = co*X.^3;
eta1 = Y./X.*(Gr/4).^0.25;
f = spline(eta, y(1,:), eta1);
SF = 4*nu*f.*(Gr/4).^0.25;
[c, h] = contour(X, Y, SF);
clabel(c, h)
xlabel('x (m)')
ylabel('y (m)')
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 a14
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.03
0
.
0
0
1
0
.
0
0
2
0
.
0
0
3
0
.
0
0
4
0
.
0
0
5
0
.
0
0
6
0
.
0
0
1
0
.
0
0
2
0
.
0
0
3
0
.
0
0
4
0
.
0
0
5
0
.
0
0
6
7
0
0
.
0
8
0
0
.
0
0
.
0
0
9
0.025
0.02
)
m
(
y
0
.
0
0
7
0
.
0
0
0
.
0
0
8
0.015
0.01
0.005
0
.0
0
1
0. 0
02
0. 0
04
0. 0
03
0.004
0.2
0.005
0.003
0.002
0.002
0.001
0.1
0. 0
07
0. 0
06
0. 0
05
0.3
0.4
0.001
0.5
x (m)
0.6
0.7
0.8
0.9
12.20
function Exercise12_20
F12 = dblquad(@kernel2, -1, 0, -1, 0, [], [], 5)/pi
function f = kernel2(x, y, dist)
L = length(x);
S = [x; repmat(y, 1, L); dist*ones(1, L)];
nd = repmat([0 1 0]', 1, L);
nf = repmat([0 0 -1]', 1, L);
f = dot(nd, S).*dot(nf, S)./dot(S, S).^2;
Answer: F12 = 0.0012
12.21
function Exercise12_21
sigma = 5.667e-8; T1 = 100+273.15; T2 = 20+273.15;
q1 = sigma*(T1^4-T2^4)
Tm1 = ((T1^4+T2^4)/2)^0.25
% Algebraic solution to one shield problem
qm1 = sigma*(T1^4-Tm1^4) % Flux for one shield from algebraic solution
opt = optimset('display', 'off');
x1 = fsolve(@OneShield, [q1 (T1+T2)/2], opt, T1, T2, sigma)
x2 = fsolve(@TwoShield, [q1, (T1+T2)/2, (T1+T2)/2-10], opt, T1, T2, sigma)
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 a15
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.
12.22
function Exercise12_22
sigma = 5.667e-8; llow = 0.5; lhigh = 300;
T = [300, 400, 500];
C1 = 3.742e8; C2 = 1.439e4;
format short e
disp(['
Temp
E(int)
E(exact)'])
for i = 1:3
Etot = quadl(@intg, llow, lhigh, [], [], T(i), C1, C2);
Etotchk = sigma*T(i)^4;
disp([T(i), Etot, Etotchk])
end
format short
function E = intg(lambda, T, C1, C2)
E = C1./(lambda.^5.*(exp(C2./(lambda.*T))-1));
Answers:
Temp
E(int)
E(exact)
3.0000e+002 4.5895e+002 4.5903e+002
4.0000e+002 1.4507e+003 1.4508e+003
5.0000e+002 3.5418e+003 3.5419e+003
12.23
sigma = 5.6693e-8; N = 5;
A = [3, 5, 3, 2.5, 2.5]; epsilon = [0.7, 0.3, 0.85, 0.45, 0.45];
T = [550 700 650 600 600];
F = -[0, 0.3615, 0.277, 0.0957, 0.2658;...
0.2169, 0, 0.2169, 0.2831, 0.2831;...
0.277, 0.3615, 0, 0.2658, 0.0957;...
0.1148, 0.5662, 0.3190, 0, 0;...
0.3190, 0.5662, 0.1148, 0, 0];
Q = [0, 0, 0, 0, 0];
c = [0, 0, 0, 0, 0];
b = sigma*epsilon./(1-epsilon).*(1-c).*T.^4+c.*Q./A;
d = (1-c).*1./(1-epsilon)+c;
F = F+diag(d);
q0 = F\b';
Q = A.*epsilon./(1-epsilon).*(1-c).*(sigma*T.^4-q0');
q = Q./A;
disp('Enclosure Results')
disp('Heat(W), Temp(K), Heat Flux(W/m^2)')
format short g
disp([Q' T' (Q./A)'])
format short
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 a16
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.
Heat Flux(W/m^2)
-2853.2
1612.7
1483.6
-949.39
-632.59
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 a17
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.
Solution to Exercises
Chapter 13
13.1
function Exercise13_1
L1 = 0.5; L2 = 0.3; P1 = 3; P2 = 1; P = 3;
x1 = 0.0:0.1:pi/2;
x2 = 0.0:0.1:pi/2;
[x1, x2] = meshgrid(x1,x2);
PE= -P1*L1*sin(x1)-P2*L2*sin(x2)+2*P*(L1*(1-cos(x1))+L2*(1-cos(x2)));
subplot(1,2,1)
c = contour(x1, x2, PE, [-.4:.1:-.1 .5:1:20], 'k');
clabel(c)
axis([0, 1.5, 0, 1.5]);
xlabel('\alpha')
ylabel('\beta')
subplot(1,2,2)
meshc(x1, x2, PE)
axis([0, 1.5, 0, 1.5, -0.5, 2.5]);
colormap([0 0 0])
xlabel('\alpha')
ylabel('\beta')
zlabel('PE');
view (150,10);
options = optimset('LargeScale', 'off');
[xopt, fopt] = fminunc(@func13_1, [1,1], options, L1, L2, P1, P2, P);
disp(['alpha = ' num2str(xopt(1)) ' beta = ' num2str(xopt(2)) ' PE = ' num2str(fopt) ])
function PE = func13_1(x, L1, L2, P1, P2, P)
PE=-P1*L1*sin(x(1))-P2*L2*sin(x(2))+2*P*(L1*(1-cos(x(1)))+L2*(1-cos(x(2))));
Answers: alpha = 0.46365 beta = 0.16515 PE = -0.37893
1.5
2.
1.5
2.5
2
0.5
1.5
1
E
P
0.5
0.5
0
-0.1
-0.2
-0.5
0
-0.3
0.5
1
0
0
0.5
0.5
1.5
1.5
1.5
13.2
function Exercise13_2
A = 9.3; n = 15;
theta = linspace(0.5, 2, n);
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.
d = linspace(1.5, 4, n);
[dd pphi] = meshgrid(d, theta);
f = 1./(A./dd-dd.*cot(pphi)+2*dd./sin(pphi));
subplot(1,2,1)
h = contour(dd, pphi*180/pi, f, (0.09:0.005:0.125), 'k');
clabel(h)
xlabel('h')
ylabel('\theta (\circ)')
subplot(1,2,2);
mesh(dd, pphi*180/pi, f);
colormap([0 0 0])
xlabel('h')
ylabel('\theta (\circ)')
zlabel('1/p')
options = optimset('LargeScale', 'off');
[xopt, fopt] = fminsearch(@flowrate, [1 1], options, A);
disp(['h = ' num2str(xopt(1)) ' theta = ' num2str(xopt(2)*180/pi) ' deg'])
function f = flowrate(x, A)
f = -1/(A/x(1)-x(1)*cot(x(2))+2*x(1)/sin(x(2)));
Answers: h = 2.3172 theta = 60 deg
0.1
110
0.09
0.1
0.095
0.105
100
0.13
0.12
90
0.11
80
)(
p
/
1
70
0.1
0.09
60
0.115 0.11
50
0.12
150
4
100
40
0.105
0.1
30 0.105
1.5
0.08
3.5
3
0.095
50
2.5
0.09
2
2.5
3.5
()
2
0
1.5
13.3
function Exercise13_3
k1 = 8; k2 = 8; L1 = 10; L2 = 10; F = 5;
[x1, x2] = meshgrid(linspace(-5, 15, 15), linspace(-5, 15, 15));
subplot(1,2,1);
h = contour(x1, x2, spring([x1, x2], k1, k2, L1, L2, F), [-25:10:25 100:50:500],'k');
xlabel('x_1')
ylabel('x_2')
axis([-5 15 -5 10])
clabel(h)
subplot(1,2,2)
mesh(x1, x2, spring([x1, x2], k1, k2, L1, L2, F))
colormap([0 0 0])
axis([-5, 15, -5, 10, -100, 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 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.
view(50,15)
xlabel('x_1')
ylabel('x_2')
zlabel('PE')
[x, fx] = fminsearch(@spring, [1,1], [], k1, k2, L1, L2, F);
disp(['x1 = ' num2str(x(1)) ' x2 = ' num2str(x(2)) ' PE = ' num2str(fx)])
function PE = spring(x, k1, k2, L1, L2, F)
[r, c]= size(x);
x1 = x(1:r,1:c/2);
x2 = x(1:r,(c/2+1):c);
PE1=1/2*k1*(sqrt(x1.^2+(L1-x2).^2)-L1).^2;
PE2=1/2*k2*(sqrt(x1.^2+(L2+x2).^2)-L2).^2;
PE=(PE1+PE2-F*x1);
Answers: x1 = 4.1289 x2 = 3.1281e-005
PE = -15.2802
10
500
450
1000
900
350
800
250
700
600
100
500
E
P
25
5
300
200
-5
100
15
30040
4
-100
-5
200
150
10
150
-5
-5
400
5
200
0
10
5
x1
10
15
15
x1
-5
13.4
function Exercise13_4
n = 0.17; a = 0.77; b = 0.37; Kt = 200; fmax = 2;
tc = 7; taux = 3; L = 500; D=100; d = 0.3;
[v, f] = meshgrid(linspace(20, 150, 10), linspace(0.5, 10, 10));
F1 = MachineObj([v, f], d, a, b, n, Kt, tc, taux, L, D);
subplot(1,2,1);
g = contour(v, f, F1, [0:0.1:3.94, 4:0.5:5, 10:15:50]);
clabel(g)
hold on;
plot([20, 200], [fmax, fmax], 'r')
xlabel('V')
ylabel('f');
subplot(1,2,2);
mesh(v, f, F1);
colormap([0 0 0])
xlabel('V')
ylabel('f')
zlabel('T');
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.
T = 3.942
10
9
350
8
3.7
40
300
250
25
10
200
6
T
f
3.8
5
4.5
150
100
50
3.9
0
3
3.9
4
10
4.5
150
4
10
100
1
20
50
40
60
80
V
100
120
140
13.5
function Exercise13_5
k = [5, 10, 8]; p = 100;
[x1, x2] = meshgrid(linspace(0, 10, 20), linspace(5, 15, 20));
subplot(1,2,1)
con = contour(x1, x2, PE5([x1, x2], k, p), [-550:22:-400]);
clabel(con)
xlabel('x_1')
ylabel('x_2')
subplot(1,2,2)
meshc(x1, x2, PE5([x1, x2], k, p))
colormap([0 0 0])
xlabel('x_1')
ylabel('x_2')
zlabel('PE')
view(50,15)
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.
PE=inline('0.5*k(2)*x(1)^2+0.5*k(3)*(x(2)-x(1))^2+0.5*k(1)*x(2)^2-p*x(2)','x',...
'k','p');
options = optimset('LargeScale', 'off');
[x, f] = fminunc(@PE5, [5,5], options, k, p);
disp(['x1 = ' num2str(x(1)) ' x2 = ' num2str(x(2)) ' PE = ' num2str(f)])
function PE = PE5(x, k, p)
[r, c]= size(x);
x1 = x(1:r,1:c/2);
x2 = x(1:r,(c/2+1):c);
PE = 0.5*k(2)*x1.^2+0.5*k(3)*(x2-x1).^2+0.5*k(1)*x2.^2-p*x2;
Answers: x1 = 4.7059 x2 = 10.5882
PE = -529.4118
15
14
200
13
100
12
-462 -506
-418
-100
-528
11
-200
x
10
E
P
-300
9
-400
8
-484
-500
7
-440
-600
0
15
5
10
5
0
10
x1
10
x2
x1
13.6
function Exercise13_6
k1 = 4500; k2 = 1650; k3 = 1100;
k4 = 2250; k5 = 550; k6 = 9300;
K = [k1+k3+k4 -k3 -k4;...
-k3 k2+k3+k5 -k5;...
-k4 -k5 k4+k5+k6];
P = [1100, 1800, 3300]';
options = optimset('LargeScale', 'off');
[x, f]=fminunc(@Func6, [0, 0, 0]', options, K, P)
disp(['x1 = ' num2str(x(1)) ' x2 = ' num2str(x(2)) '
x3 = ' num2str(x(3))])
function PE = Func6(x, K, P)
PE = 0.5*x'*K*x-x'*P;
Answers: x1 = 0.34755 x2 = 0.72301
x3 = 0.37022
13.7
function Exercise13_7
I = 6; J = 5; Li = 7.5;
W = 60*(1:J);
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.
k = 450+225*(J/3-(1:I)).^2;
Lspr(1:J) = Li;
xo = [cumsum(Lspr) zeros(1,J)];
options = optimset('LargeScale', 'off');
[x, f] = fminunc(@Prob7, xo, options, Li, k, W);
n = (2:6)'; X = x(1:5)'; Y = x(6:10)';
disp([repmat('X(', 5,1) num2str(n) repmat(') = ', 5,1) num2str(X) ...
repmat(' Y(', 5,1) num2str(n) repmat(') = ', 5,1) num2str(Y)])
function PE = Prob7(x, Li, k, w)
X = [0, x(1:5), 6*Li];
Y = [0, x(6:10), 0];
dL = sqrt(diff(X).^2+diff(Y).^2)-Li;
PE = 0.5*sum(k.*dL.^2)+sum(w.*x(6:10));
Answers: X(2) = 7.91676
X(3) = 16.2538
X(4) = 24.3557
X(5) = 32.2231
X(6) = 39.3033
Y(2) = -3.8577
Y(3) = -7.1459
Y(4) = -8.8364
Y(5) = -8.2859
Y(6) = -5.1603
13.8
function Exercise13_8
E = 1724; L = 127; t = 25.4;
R = [27.9, 43.2, 53.3, 73.7, 99.1];
F = [385, 536, 2317, 7820, 18230];
x = lsqcurvefit(@func8, [1 1], R, F, [], [], [], E, L, t);
disp(['a = ' num2str(x(1)) ' b = ' num2str(x(2))])
plot(R, F*1e-3, 'ko');
hold on;
R = linspace(25, 100, 50);
plot(R, func8(x, R, E, L, t)*1e-3, 'k');
xlabel('R (mm)')
ylabel('F (MN)')
legend('Experimental values', 'Fitted curve', 'Location', 'NorthWest');
function F = func8(x, R, E, L, t)
F = pi^x(1)*E*R.^x(2)*t^(4-x(2))/(4*L^2);
Answers: a = -3.3182 b = 3.1588
20
18
Experimental values
Fitted curve
16
14
12
)
N
M
(
10
F
8
0
20
30
40
50
60
R (mm)
70
80
90
100
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.
13.9
function Exercise13_9
t = 7:2:41;
ingred = [0.488, 0.473, 0.448, 0.435, 0.431, 0.453, 0.421,...
0.405, 0.405, 0.405, 0.403, 0.391, 0.403, 0.398, 0.393,...
0.398, 0.388, 0.388];
x = lsqcurvefit(@fit8, [1,1], t, ingred);
disp(['a = ' num2str(x(1)) ' b = ' num2str(x(2))])
function ingred = fit8(x, t, ingred)
ingred = x(1)+(0.51-x(1))*exp(-x(2)*(t-8));
Answers: a = 0.39177 b = 0.13944
13.10
function Exercise13_10
x0 = [0, 0];
pos = [0, 2.74, 6.1, 18.3, 27.4, 36.6];
t = [0, 2.05, 3.1, 4.8, 5.6, 6.8];
x = lsqnonlin(@func10,[0, 0], [], [], [], pos, t);
disp(['v(t) = ' num2str(x(1)*4) 't^3 + ' num2str(x(2)*3) 't^2 + 1.22t'])
function velfunc = func10(x, pos, t)
velfunc = pos - (x(1).*t.^4 + x(2).*t.^3 + 0.61*t.^2);
Answers: v(t) = -0.032693t^3 + 0.2515t^2 + 1.22t
13.11
function Exercise13_11
N = 40; xc = 1.25; yc = 1.5;
th = linspace(0, 2*pi*(1-1/N), N);
r = 0.75+0.02*randn(N,1);
x = xc+r'.*cos(th);
y = yc+r'.*sin(th);
plot(x, y, 'k*')
hold on
plot([0, 0, 2.5, 2.5, 0], [0, 2.5, 2.5, 0, 0], 'k-')
axis equal off
opt = optimset('display', 'off');
x = lsqnonlin(@circl, [1, 2, 1], [], [], opt, x, y);
th = linspace(0, 2*pi, 100);
plot(x(1)+x(3)*cos(th), x(2)+x(3)*sin(th),'k-')
plot(x(1), x(2), '+k')
text(0.1, 0.7, ['r = ' num2str(x(3),5)])
text(0.1, 0.55, ['x_c = ' num2str(x(1),5)])
text(0.1, 0.40, ['y_c = ' num2str(x(2),5)])
function f = circl(x, xd, yd)
f = x(3)-sqrt((x(1)-xd).^2+(x(2)-yd).^2);
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.
Answer:
r = 0.75083
x c = 1.2491
y
= 1.5011
13.12
function Exercise13_12
p = [1, 1, 1; -1, 2, 4; 2, 3, 4; -3, -4, 1];
SphereDiamObj = @(x, p) (2*x(4));
options = optimset('Algorithm', 'active-set');
x = fmincon(SphereDiamObj, [4, 4, 4, 4], [], [], [], [], ...
[-inf, -inf, -inf, 0], [], @SphereConstraints, options, p);
disp(['xc = ' num2str(x(1)) ' yc = ' num2str(x(2)) ' zc = ' num2str(x(3)) ' R = ' num2str(x(4))])
function [C,Ceq] = SphereConstraints(x, p)
r = size(p);
for k = 1:r
C(k) = (x(1)-p(k,1))^2+(x(2)-p(k,2))^2+(x(3)-p(k,3))^2-x(4)^2;
end
Ceq = [];
Answers: xc = -0.5 yc = -0.5 zc = 2.5 R = 4.5552
13.13
function Exercise13_13
x0 = [0, 0]; p = 1; e = 2; h = 2;
vlb = [0.1, 0.1]; vub = [inf, inf];
options = optimset('Algorithm', 'active-set');
[x, f] = fmincon(@TrussObj,x0,[],[],[],[],vlb,vub,...
@TrussCon, options, p, h, e);
disp(['x1 = ' num2str(x(1)) ' x2 = ' num2str(x(2)) ' f = ' num2str(f)])
function f = TrussObj(x, p, h, e)
f = (p*h/e)*(1/(x(1)+sqrt(2)*x(2)));
function [C, Ceq] = TrussCon(x, p, h, e)
s1x = p*(x(2)+sqrt(2)*x(1))/(sqrt(2)*x(1)^2+2*x(1)*x(2));
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.
13.14
function Exercise13_14
x0(1:5) =1; lb(1:5) = 0;
Imin(1:5) =1; Imax(1:5) = 2;
v = [3, 2, 1, 2, 1];
options = optimset('Algorithm', 'active-set');
[x, P] = fmincon(@CircuitObj, x0, [], [], [], [], lb, [],...
@CircuitCon, options, v, Imin, Imax);
X = x'; n = (1:5)';
disp([repmat('R(', 5,1) num2str(n) repmat(') = ', 5,1) num2str(X)])
disp(['Power = ' num2str(P) ' W'])
function f = CircuitObj(x, v, Imin, Imax)
f = sum(v.^2./x);
function [C, Ceq] = CircuitCon(x, v, Imin, Imax)
C = zeros(10,1);
for n = 1:5
C(n) = -v(n)/x(n)+Imin(n);
C(n+5) = v(n)/x(n)-Imax(n);
end
Ceq(1) = v(1)/x(1)+v(3)/x(3)-v(5)/x(5);
Ceq(2) = v(2)/x(2)-v(3)/x(3)-v(4)/x(4);
Answers: R(1) = 3
R(2) = 1
R(3) = 1
R(4) = 2
R(5) = 0.5
Power = 12 W
13.15
function Exercise13_15
d = -[7, 12, 13, 7, 4, 17, 4, 9, 12, 9, 10, 9,...
6, 14, 8, 16, 21, 8, 8, 7, 4, 8, 13, 4];
c = [300, 740, 300, 430, 210, 360,...
270, 600, 490, 250, 830, 290,...
460, 540, 380, 390, 470, 400,...
800, 380, 760, 600, 680, 310];
H = 2*diag(d);
A = zeros(10,24);
k = 0;
for i = 1:4
for j = 1:6
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.
A(i,j+k*6)=-1;
end
k = k+1;
end
k = 0;
for i = 1:6
A(i+4,1+k) = 1;
A(i+4,7+k) = 1;
A(i+4,13+k) = 1;
A(i+4,19+k) = 1;
k = k+1;
end
a = [8, 24, 20, 24, 16, 12];
b = -[29, 41, 13, 21];
lb = zeros(24,1);
options = optimset('LargeScale','off');
x0 = [5, 5, 10, 5, 5, 5, 5, 5, 0, 20, 0, 5, 0, 0, 0, 0, 15, 0, 0, 10, 0, 0, 0, 0];
xopt = quadprog(H, c, A, [b, a]', [], [], lb, [], x0, options);
x = zeros(6,4);
for k = 1:4
rs =6*(k-1)+1;
x(1:6,k) = xopt(rs:rs+5);
end
disp(int2str(x))
Answers: -0 8 -0 0
0 3 0 21
20 0 -0 0
0 24 -0 0
3 -0 13 0
6 6 -0 0
13.16
function Exercise13_16
x0 = [0.1, 0.1];
LBnd = [0.15, 0.15]; UBnd = [3.0, 3.5];
[x, fopt] = fseminf(@TwobarsObj, x0, 1, @TwobarsCon, [], [], [], [], LBnd, UBnd);
disp(['x(1) = ' num2str(x(1)) ' x(2) = ' num2str(x(2)) ' w = ' num2str(fopt)])
subplot(1,2,1)
ylabel('stress \sigma_1 (GPa)')
xlabel('\theta (degrees)')
axis([-90, 90, -1.5, 1.5])
hold off
subplot(1,2,2)
ylabel('stress \sigma_2 (GPa)')
xlabel('\theta (degrees)')
axis([-90, 90, -1.5, 1.5])
function f = TwobarsObj(x)
ro = 7833.4117; h = 2.159; Aref = 6.4516e-04;
f = 2*ro*h*x(2)*sqrt(1+x(1)^2)*Aref;
function [C, Ceq, K1, s] =TwobarsCon(x, s)
P = 35585.776; sgm0 = 127.553e06; Aref = 6.4516e-04;
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.
if isnan(s(1,1))
s = [5, 0];
end
theta = -90:s(1,1):90;
b1 = x(1)*cos(theta/180*pi);
b2 = P*sqrt(1+x(1)^2)/(2*x(1)*x(2)*Aref);
sgm1 = (b1+sin(theta/180*pi))*b2;
sgm2 = (b1-sin(theta/180*pi))*b2;
K1(1,:) = sgm1-sgm0;
K1(2,:) = sgm2-sgm0;
K1(3,:) = -sgm1-sgm0;
K1(4,:) = -sgm2-sgm0;
C = [];
Ceq = [];
subplot(1,2,1)
plot(theta, (K1(1,:)+sgm0)*1e-9, 'k')
hold on
subplot(1,2,2)
plot(theta, (K1(2,:)+sgm0)*1e-9, 'k')
hold on
Answers: x(1) = 0.80883 x(2) = 0.45046 w = 12.6431
1.5
1.5
0.5
)
a
P
G
(
s1
s
e
r
t
s
0.5
)
a
P
G
(
s2
s
e
r
t
s
-0.5
-0.5
-1
-1
-1.5
-1.5
-50
(degrees)
50
-50
50
(degrees)
13.17
function Exercise13_17
global K P
k1 = 4500; k2 = 1650; k3 = 1100;
k4 = 2250; k5 = 550; k6 = 9300;
K = [k1+k3+k4, -k3, -k4;...
-k3, k2+k3+k5, -k5;...
-k4, -k5, k4+k5+k6];
P = [1100, 1800, 3300]';
nvars = 3; lb = [0 0 0]; ub = [1 1 1];
options = gaoptimset;
options = gaoptimset(options, 'HybridFcn', {@fmincon []});
options = gaoptimset(options, 'Display', 'off');
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.
l
a
u
d
i
v
i
d
n
i
0.7
0.6
t
s
e
b
0.5
t
n
e
r
r
u
C
0.4
0.3
0.2
0.1
0
1
2
Number of variables (3)
13.18
function Exercise13_18
global p e h
p = 1; e = 2; h = 2;
nvars = 2; lb = [0.1, 0.1]; ub = [inf, inf];
options = gaoptimset;
options = gaoptimset(options, 'Display', 'off');
options = gaoptimset(options, 'PlotFcns', {@gaplotbestindiv});
x = ga(@obj_truss_Ex13_18, nvars, [], [], [], [], lb, ub, @con_truss_Ex13_18, options);
disp(['x1 = ' num2str(x(1)) ' x2 = ' num2str(x(2))]);
function f = obj_truss_Ex13_18(x)
global p e h
f = (p*h/e)*(1/(x(1)+sqrt(2)*x(2)));
function [C, Ceq] = con_truss_Ex13_18(x)
global p
s1x = p*(x(2)+sqrt(2)*x(1))/(sqrt(2)*x(1)^2+2*x(1)*x(2));
s2x = p*(1/(x(1)+ sqrt(2)*x(2)));
s3x = -p*(x(2)/(sqrt(2)*x(1)^2+2*x(1)*x(2)));
C(1) = s1x-17.5;
C(2) = s2x-17.5;
C(3) = s3x-12;
Ceq = [];
Answers: x1 = 67.8144 x2 = 79.4752
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.
l
a
u
d
i
v
i
d
n
i
70
60
t
s
e
b
50
t
n
e
r
r
u
C
40
30
20
10
0
1
2
Number of variables (2)
13.19
function Exercise13_19
global E Rho c P
nvars = 5; P = 100;
lb = [0.05, 0.2, 0.2, 0.35, 3];
ub = [0.5, 0.5, 0.6, 0.5, 6];
E = [1.6, 70, 200]*10^9;
Rho = [100, 2770, 7780];
c = [500, 1500, 800];
A = [1, -1, 0, 0, 0; -1, 1, 0, 0, 0; 0, 1, -1, 0, 0 ; 0, -1, 1, 0, 0];
b = [0, 0.15, 0, 0.01]';
options = gaoptimset;
options = gaoptimset(options,'PlotFcns', { @gaplotpareto });
gamultiobj(@obj_Ex13_19,nvars,A,b,[],[],lb,ub,options);
function f = obj_Ex13_19(x)
global E Rho c P
EI = (2*x(4)/3)*(E(1)*x(1)^3+E(2)*(x(2)^3-x(1)^3)+E(3)*(x(3)^3-x(2)^3));
mu = 2*x(4)*(Rho(1)*x(1)+Rho(2)*(x(2)-x(1))+Rho(3)*(x(3)-x(2)));
c1 = mu*x(5)-2800;
f(1) = (-pi/(2*x(5)^2)*sqrt(EI/mu))+P*max(0,c1);
f(2) = 2*x(4)*(c(1)*x(1)+c(2)*(x(2)-x(1))+c(3)*(x(3)-x(2)))+P*max(0,c1);
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 a13
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.
Pareto front
300
250
2
e
v
i
t
c
e
j
b
O
200
150
100
50
-400
-350
-300
-250
-200
Objective 1
-150
-100
-50
13.20
function Exercise13_20
% Part (a)
global P
nvars = 7; P = 100;
lb = [2.6, 0.7, 17, 7.3, 7.3, 2.9, 5];
ub = [3.6, 0.8, 28, 8.3, 8.3, 3.9, 5.5];
A = zeros(4, 7);
A(1,1) = -1; A(1,2 )= 5;
A(2,1) = 1; A(2,2) = -12;
A(3,4) = -1; A(3,6) = 1.5;
A(4,5) = -1; A(4,7) = 1.1;
b = [0, 0, -1.9, -1.9];
options = gaoptimset;
[x, V] = ga(@obj_Ex13_20a, nvars, A, b, [], [], lb, ub, @con_Ex13_20a, options);
for n = 1:length(x)
if n == 2 || n == 3
a = [];
else
a = ' cm';
end
disp(['x(' int2str(n) ') = ' num2str(x(n)) a])
end
disp(['Volume = ' num2str(V) ' cm^3'])
% Part (b)
options = gaoptimset;
options = gaoptimset(options,'PlotFcns', { @gaplotpareto });
gamultiobj(@obj_Ex13_20b,nvars,A,b,[],[],lb,ub,options);
function f = obj_Ex13_20a(x)
f = 0.7854*x(1)*x(2)^2*(3.3333*x(3)^2+14.9334*x(3)-43.0934) ...
-1.508*x(1)*(x(6)^2+x(7)^2)+7.477*(x(6)^3+x(7)^3) ...
+0.7854*(x(4)*x(6)^2+x(5)*x(7)^2);
function [C, Ceq] = con_Ex13_20a(x)
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 a14
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.
C(1) = 1/(x(1)*x(2)^2*x(3))-1/27;
C(2) = 1/(x(1)*x(2)^2*x(3)^2)-1/397.5;
C(3) = x(4)^3/(x(2)*x(3)*x(6)^4)-1/1.93;
C(4) = x(5)^3/(x(2)*x(3)*x(7)^4)-1/1.93;
C(5) = sqrt((745*x(4)/(x(2)*x(3)))^2+16.9*10^6)/(0.1*x(6)^3)-1100;
C(6) = sqrt((745*x(5)/(x(2)*x(3)))^2+157.5*10^6)/(0.1*x(7)^3)-850;
C(7) = x(2)*x(3)-40;
Ceq = [];
function f = obj_Ex13_20b(x)
global P
[C, Ceq] = con_Ex13_20a(x);
penalty = P*(max(0,C(1))+max(0,C(2))+max(0,C(3))+max(0,C(4))+max(0,C(5))+max(0,C(6))+max(0,C(7)));
f(1) = obj_Ex13_20a(x)+penalty;
f(2) = sqrt((745*x(4)/(x(2)*x(3)))^2+16.9*10^6)/(0.1*x(6)^3)+penalty;
Answers:
Part (a)
x(1) = 3.4991 cm
x(2) = 0.7
x(3) = 17.0002
x(4) = 7.3015 cm
x(5) = 7.7146 cm
x(6) = 3.3503 cm
x(7) = 5.2867 cm
Volume = 2994.0775 cm^3
Part (b)
Pareto front
1100
1050
1000
2
e
v
i
t
c
e
j
b
O
950
900
850
800
750
700
650
3000
3050
3100
3150
3200
3250
Objective 1
3300
3350
3400
3450
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 a15
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.
Solution to Exercises
Chapter 14
14.1
function Exercise14_1
rho = 850; cp = 3800; Sm = 145; mb = 0.18;
cpb = 3300; Tb = 37; alpha = 1e-7; S = 8e5; R = 0.05;
r = linspace(0, R, 51);
t = linspace(0, 3000, 1001);
sol = pdepe(2, @tumorPDE, @tumorIC, @tumorBC, r, t, [], alpha, S, rho, cp, mb, cpb, Tb, Sm);
T = sol(:, :);
r = r*100;
plot(r, T(61,:), 'k-.', r, T(134,:), 'k-', r, T(201,:), 'k--', r, T(501,:), 'k:', [1, 1], [30, 70], 'k--')
xlabel('r (cm)')
ylabel('Temperature (\circC)')
legend('t = 300 s', 't = 400 s', 't = 600 s', 't = 1500 s')
ylim([30 70])
function [c, f, s] = tumorPDE(r, t, T, DTDr, alpha, S, rho, cp, mb, cpb, Tb, Sm)
c = 1;
f = DTDr*alpha;
s = (S*(r<0.008)*(t<200)+Sm+mb*cpb*(Tb-T))/(rho*cp);
function T0 = tumorIC(r, alpha, S, rho, cp, mb, cpb, Tb, Sm)
T0 = 37;
function [pl, ql, pr, qr] = tumorBC(rl, Tl, rr, Tr, t, alpha, S, rho, cp, mb, cpb, Tb, Sm)
pl = 0; ql = 1;
pr = 0; qr = 1;
Answer:
70
t = 300 s
t = 400 s
t = 600 s
t = 1500 s
65
60
(
e
r
)u
55
t
C
a
r
e
p
m
e
T
50
45
40
35
30
0
0.5
1.5
2.5
r (cm)
3.5
4.5
14.2
function Exercise14_2
rho = 850; cp = 3800; Sm = 145; mb = 0.18;
cpb = 3300; Tb = 37; alpha = 1e-7; S = 8e4; R = 0.05;
r = linspace(0, R, 501);
t = linspace(0, 80000, 1001);
sol = pdepe(2, @tumorPDE2, @tumorIC, @tumorBC, r, t, [], alpha, S, rho, cp, mb, cpb, Tb, Sm);
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.
T = sol(:, :);
r1 = r(1:101);
Q1= 4*pi*S/3*r1(end)^3;
Q2 = trapz(r1,4*pi*r1.^2.*(mb*cpb*(Tb-T(end,1:101))));
Q4 = 4*pi*Sm/3*r1(end)^3;
[uout, duoutdx] = pdeval(2, r, T(end,:), r1(end));
Q3 = 4*pi*r1(end)^2*alpha*rho*cp*duoutdx;
Q = Q1+Q2+Q3+Q4;
disp(['Q1 = ' num2str(Q1) 'Q2 = ' num2str(Q2) ' Q3 = ' num2str(Q3) ' Q4 = ' num2str(Q4)])
disp(['Sum Qj = ' num2str(Q)])
function [c, f, s] = tumorPDE2(r, t, T, DTDr, alpha, S, rho, cp, mb, cpb, Tb, Sm)
c = 1;
f = DTDr*alpha;
s = (S*(r<0.01)*(t<80000)+Sm+mb*cpb*(Tb-T))/(rho*cp);
function T0 = tumorIC(r, alpha, S, rho, cp, mb, cpb, Tb, Sm)
T0 = 37;
function [pl, ql, pr, qr] = tumorBC(rl, Tl, rr, Tr, t, alpha, S, rho, cp, mb, cpb, Tb, Sm)
pl = 0; ql = 1;
pr = 0; qr = 1;
Answers: Q1 = 0.3351Q2 = -0.018606 Q3 = -0.2919 Q4 = 0.00060737
Sum Qj = 0.025208
14.3
T0 = 20; alpha = 1.5e-7; k=0.6;
euler = 0.577216; Q=1;
t = linspace(0, 10, 100);
r = 0.001/2;
z = r^2./(4*alpha*t);
Texact = T0+Q/(4*pi*k)*expint(z);
Tapprox = T0+Q/(4*pi*k)*(-euler-log(r^2./(4*alpha*t)));
plot(t, Texact, 'k-', t, Tapprox, 'k--')
xlabel('Time (s)')
ylabel('Temperature (\circC)')
legend('Exact', 'Approximate', 'Location', 'SouthEast')
Answer:
20.4
20.3
20.2
(
e
r
)u
t
C
a
r
e
p
m
e
T
20.1
20
19.9
19.8
Exact
Approximate
0
5
Time (s)
10
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.
14.4
function Exercise14_4
Q = 1; T0 = 20; R = 0.0005;
Rs = R/10; k = 0.6; alpha = 1.5e-7;
t = linspace(0, 10, 500);
r = logspace(0, 3, 100)*Rs; % r variable for pdepe, Note: r1(34) = R
sol = pdepe(1, @LinePDE, @LineIC, @LineBC, r, t, [], Rs, k, alpha, T0, Q);
T = sol(:,:);
z = R^2./(4*alpha*t);
Texact = T0+Q/(4*pi*k)*expint(z);
plot(t, T(:,34), 'k-', t, Texact, 'k--')
legend('T_{pdepe}', 'T_{exact}', 'Location', 'SouthEast')
xlabel('Time (sec)')
ylabel('Temperature (\circC)')
function [c, f, s] = LinePDE(r, t, T ,DTDr, R, k, alpha, T0, Q)
c = 1/alpha; f = DTDr; s = 0;
function T0 = LineIC(r, R, k, alpha, T0, Q)
T0 = 20;
function [pl,ql,pr,qr] = LineBC(rl, Tl, rr, Tr, t, R, k, alpha, T0, Q)
pl = Q/(2*R*pi); ql = k;
pr = Tr-T0; qr = 0;
Answer:
20.4
20.35
20.3
(
e
r
)u
20.25
t
C
a
r
e
p
m
e
T
20.2
20.15
20.1
20.05
T pdepe
T ex ac t
20
0
5
Time (sec)
10
14.5
syms K1 K2 Kc H x1 x2 x3 y D
X = solve('Kc=(x2-x1)/x1',...
'K1 =H*(x2-x3)/(x1-x2)',...
'K2=(1+x3)*H/(x2-x3)', 'x1', 'x2', 'x3');
x1 = X.x1
x2 = X.x2
x3 = X.x3
Answers: x1 = -H^2/(H^2*Kc + H^2 + H*K1*Kc + K1*K2*Kc)
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.
14.6
Kc1 = 4.25e-7; PCO2 = 45; HCO2 = 22618;
CO2 = PCO2/HCO2; Kw =1e-14;
Hi = 10^(-7.4); OHi = 1e-14/Hi;
ybase = linspace(0, 1e-6, 25);
HCO3base = Kc1*CO2/Kw*(OHi+ybase);
Hbase = Kw./(OHi+ybase);
yacid = linspace(0, 1e-7, 10);
HCO3acid = Kc1*CO2./(Hi+yacid);
Hacid = Hi+yacid;
plot( HCO3acid, -log10(Hacid), 'k-')
hold on
plot( HCO3base, -log10(Hbase), 'k-')
xlabel('Bicarbonate concentration (M)')
ylabel('pH')
Answer:
8.4
8.2
7.8
H
p
7.6
7.4
7.2
6.8
0
0.02
0.04
0.06
Bicarbonate concentration (M)
0.08
0.1
0.12
14.7
function Exercise14_7
C = linspace(0,150e-6,100); CHb = 0.0022;
[Y, dDtdC] = OxyHemo(C, CHb);
figure(1)
plot(C*1e6, Y, 'k-')
xlabel('[C_{O2}]_d (\muM)')
ylabel('Fractional Hb Saturation (Y)')
figure(2)
plot(C*1e6, dDtdC, 'k-')
xlabel('[C_{O2}]_d (\muM)')
ylabel('\partialC_{T,O2}/\partialC_{O2}')
function [Y, dCtdC] = OxyHemo(C, CHb)
n = 2.34; C50 = 35.14e-6;
Y = C.^n./(C50.^n+C.^n);
dCtdC = 1+4*n*CHb.*Y.^2.*C50.^n./C.^(n+1);
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.
Answers:
)
Y
(
n
o
i
t
a
r
u
t
a
S
0.9
b
H
0.6
l
a
n
o
i
t
c
a
r
F
180
160
0.8
140
0.7
120
2
O
100
0.5
/ 2O
,
T
80
C
0.4
60
0.3
40
0.2
20
0.1
0
0
50
100
150
[C O2 ] d (M)
0
0
50
100
150
[C O2 ] d (M)
14.8
pCO2 = 45; pH = 7.4;
Hco2 = 22618; Kc1 = 4.25e-7;
H = 10^(-pH);
CO2 = pCO2/Hco2;
HCO3 = Kc1*CO2/H;
disp(['Bicarbonate concentration = ' num2str(HCO3) ' M'])
Answer: Bicarbonate concentration = 0.02124 M
14.9
function Exercise14_9
L = 5.5; h = 0.01; Vavg = 0.3; D = 2e-5;
Da = 0.45; Cin = 150e-6; Cmm = 10e-6;
Lh = L/h; hD = h/D;
y = linspace(0, 1, 101);
x = linspace(0, 1, 101);
sol = pdepe(0, @pdepbx, @pbICx, @pbBCx, y, x, [], Lh, hD, Vavg, Da, Cin, Cmm);
C = sol(:,:)*1e6;
Pe = Vavg*hD;
Cf = zeros(101,2);
for j = [1,101]
for i = 1:101
Cf(i,j) = Cin*(1+Da*((1-3*(h-y(j))^2)/6-Lh/Pe*x(i)))*1E6;
end
end
plot(x, C(:,1), 'k-', x, Cf(:,1), 'k--')
hold on
plot(x, C(:,end), 'k-', x, Cf(:,end), 'k--')
xlabel('Distance along reactor (x/L)')
ylabel('Concentration (\muM)')
text(0.14, 60, 'y/h = 0')
text(0.39, 84, 'y/h = 1')
axis([0 1 0 160])
legend('pdepe solution', 'Approximate solution', 'Location', 'NorthEast')
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.
function [c, f, s] = pdepbx(y, x, C, DCDy, Lh, hD, Vavg, Da, Cin, Cmm)
c = Vavg*hD;
f = DCDy*Lh;
s = 0;
function Czero = pbICx(y, Lh, hD, Vavg, Da, Cin, Cmm)
Czero = Cin;
function [pa, qa, pb, qb] = pbBCx(yl, Cl, yr, Cr, x, Lh, hD, Vavg, Da, Cin, Cmm)
pb = 0; qb = 1;
pa = -Da*Cin*Cl/(Cl+Cmm);
qa = 1/(Lh);
Answer:
160
pdepe solution
Approximate solution
140
120
(
n
o
i
t)
a
M
r
t
n
e
c
n
o
C
100
y/h = 1
80
60
y/h = 0
40
20
0
0
0.1
0.2
0.3
0.4
0.5
0.6
Distance along reactor (x/L)
0.7
0.8
0.9
14.10
function Exercise14_10
L = 5.5; h = 0.01; Vavg = 0.3; D = 2e-5;
Da = 0.45; Cin = 150e-6; Cmm = 10e-6;
Lh = L/h; hD = h/D;
y = linspace(0, 1, 101);
x = linspace(0, 1, 101);
sol = pdepe(0, @pdepbyy, @pbICyy, @pbBCyy, y, x, [], Lh, hD, Vavg, Da, Cin, Cmm, 1);
C = sol(:,:)*1e6;
plot(x, C(:,1), 'k-')
hold on
plot(x, C(:,end), 'k-')
xlabel('Distance along reactor (x/L)')
ylabel('Concentration (\muM)')
text(0.16, 120, 'y/h = 0')
text(0.39, 145, 'y/h = 1')
ylim([90 160])
function [c, f, s] = pdepbyy(y, x, C, DCDy, Lh, hD, Vavg, Da, Cin, Cmm, plug)
C50 = 35e-6; n = 2.54; CHb = 2.2e-3;
Y = C^n/(C^n+C50^n);
dCdC = 1+4*n*CHb*Y^2*C50^n/C^(n+1);
c = Vavg*hD*dCdC;
f = DCDy*Lh;
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.
s = 0;
function Czero = pbICyy(y, Lh, hD, Vavg, Da, Cin, Cmm, plug)
Czero = Cin;
function [pa, qa, pb, qb] = pbBCyy(yl, Cl, yr, Cr, x, Lh, hD, Vavg, Da, Cin, Cmm, plug)
pb = 0; qb = 1;
pa = -Da*Cin*Cl/(Cl+Cmm);
qa = 1/(Lh);
Answer:
160
150
y/h = 1
(
n
o
i
t)
M
a
r
t
n
e
c
n
o
C
140
130
120
y/h = 0
110
100
90
0
0.1
0.2
0.3
0.4
0.5
0.6
Distance along reactor (x/L)
0.7
0.8
0.9
14.11
function Exercise14_11
R = 0.02; Xb = 5.234e-8; Smax = 15e-9;
D = 2e-5; rho = 1; K = 25e-10;
S = Smax*R^2/(D*Xb*rho);
KKb = K/Xb; c = char('k--', 'k-');
chiR = 1.0; chi0 = 0.0005;
solinit = bvpinit(linspace(chi0, chiR, 5), [0 0]);
chi = linspace(chi0, chiR, 50);
for MM = 0:1
sol = bvp4c(@TumorODE, @TumorBC, solinit, [], S, KKb, MM);
y = deval(sol, chi);
subplot(2,1,1)
plot(chi, y(1,:), c(MM+1,:))
hold on
ylabel('\psi')
xlabel('\chi')
if MM == 1
plot(chi, 1+S/6*(chi.^2-1), 'ko')
legend('K = 0', ['K = ' num2str(K)], 'Exact solution (K = 0)', 'Location', 'NorthWest')
end
subplot(2,1,2)
plot(chi, y(2,:), c(MM+1,:))
hold on
ylabel('d\psi/d\chi')
xlabel('\chi')
if MM == 1
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.
0.8
0.6
0.4
0.2
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
0.6
0.7
0.8
0.9
2
K= 0
K = 2.5e-009
1.5
d
/
Exact solution (K = 0)
d
0.5
0
0
0.1
0.2
0.3
0.4
0.5
14.12
function Exercise14_12
Rc = 10e-6; Rt=100e-6;
Vmax = 0.0005; CHb = 0.0022; Cin = 120e-6;
Smax = 20e-6; Cmm = 10e-6;
z = linspace(0, 0.001, 101);
r = linspace(0, 10e-6, 101);
options = odeset('RelTol', 1e-6, 'AbsTol', 1e-9);
Dc = [2e-9, 2.2e-9, 1.8e-9, 2e-9, 2e-9];
Dt = [1e-9, 1e-9, 1e-9, 1.1e-9, 0.9e-9,];
for n = 1:length(Dc)
sol1 = pdepe(1, @CapillPDE, @CapillIC, @CapillBC, r, z, options, ...
Rc, Rt, Dc(n), Dt(n), Vmax, CHb, Cin, Smax, Cmm);
C = sol1(:,:);
Cm = 4/Rc^2*trapz(r, (1-(r/Rc).^2).*C(end,:).*r)*1e6;
disp(['Dc = ' num2str(Dc(n)) ' m^2/s Dt = ' num2str(Dt(n)) ' m^2/s Cm = ' num2str(Cm) ' uM'])
end
function [c, f, s] = CapillPDE(r, z, C, DCDr, Rc, Rt, Dc, Dt, Vmax, CHb, Cin, Smax, Cmm)
n = 2.34; C50 = 35.14e-6;
Y = C^n/(C50^n+C^n);
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.
dCtdC = 1+4*n*CHb*Y^2*C50^n/C^(n+1);
c = dCtdC*Vmax*(1-(r/Rc)^2);
f = Dc*DCDr;
s = 0;
function C0 = CapillIC(r, Rc, Rt, Db, Dt, Vmax, CHb, Cin, Smax, Cmm)
C0 = Cin;
function [pa, qa, pb, qb] = CapillBC(rl, Cl, rr, Cr, z, Rc, Rt, Dc, Dt, Vmax, CHb, Cin, Smax, Cmm)
solinit = bvpinit(linspace(Rc, Rt, 10), [0 0]);
sol = bvp4c(@TissueODE, @TissueBC, solinit, [], Cr, Dt, Smax, Cmm);
pb = -Dt*sol.y(2,1); qb = 1;
pa = 0; qa = 1;
function res = TissueBC(ya, yb, Cr, Dt, Smax, Cmm)
res = [ya(1)-Cr; yb(2)];
function dydx = TissueODE(r, y, Cr, Dt, Smax, Cmm)
dydx = [y(2); Smax/Dt*y(1)/(y(1)+Cmm)-y(2)/r];
Answers: Dc = 2e-009 m^2/s Dt = 1e-009 m^2/s Cm = 45.2942 uM
Dc = 2.2e-009 m^2/s Dt = 1e-009 m^2/s Cm = 45.1111 uM
Dc = 1.8e-009 m^2/s Dt = 1e-009 m^2/s Cm = 45.517 uM
Dc = 2e-009 m^2/s Dt = 1.1e-009 m^2/s Cm = 44.0989 uM
Dc = 2e-009 m^2/s Dt = 9e-010 m^2/s Cm = 46.645 uM
14.13
function Exercise14_13
gate = char('n', 'm', 'h');
tspan = linspace(0, 100, 300);
for k = 1:3
[t, y] = ode45(@HH, tspan, [0], [], gate(k));
disp([gate(k) '(100) = ' num2str(y(end))])
end
function dy = HH(t, y, g)
V = -65+65*((t>2)&(t<5));
dy = alph(V+65, g)-(alph(V+65, g)+bet(V+65, g))*y(1);
Answers: n(100) = 0.31768
m(100) = 0.05294
h(100) = 0.59611
14.14
function Exercise14_14
gKbar = 0.036; gNabar = 0.120;
gL = 0.0003; EL = -49; EK = -77;
gate = char('n', 'm', 'h');
tspan = linspace(0, 20, 500);
IC = [0.3177, 0.0529, 0.5961];
Vs = [-50, -25, 0, 25]+65;
for nn = 1:4
subplot(4,1,nn)
ENa = 50;
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.
for k = 1:3
[t, y] = ode45(@HH2, tspan, [IC(k)], [], gate(k), Vs(nn));
switch gate(k)
case 'n'
n = y(:,1);
case 'm'
m = y(:,1);
case 'h'
h = y(:,1);
end
end
V = -65+Vs(nn)*((t>2) & (t<18));
Iion = gKbar.*n.^4.*(V-EK)+gNabar.*m.^3.*h.*(V-ENa)+gL.*(V-EL);
plot(t, Iion, 'k-')
ylabel('I_{ion} (mA/cm^2)')
text(9, min(Iion), ['V_{pot} = ' num2str(Vs(nn)-65) ' mV'])
if nn == 4
xlabel('t (ms)')
end
end
function dy = HH2(t, y, g, Vs)
V = -65+Vs*((t>2)&(t<18));
dy = alph(V+65, g)-(alph(V+65, g)+bet(V+65, g))*y(1);
Answers:
0.1
m
c
2)/
A
m
(n
I
o
i
-0.1
m
c
2)/
A
m
(n
I
o
i
m
c
2)/
A
m
(n
I
o
i
m
c
2)/
A
m
(n
V pot = -50 mV
0
12
14
16
18
20
12
14
16
18
20
12
14
16
18
20
12
14
16
18
20
0
V
-1
-2
pot
= -25 mV
10
0
V
-2
pot
= 0 mV
10
4
2
0
V pot = 25 mV
Ii
10
-2
10
t (ms)
14.15
function Exercise14_15
Vr = -62.607; gKbar = 0.036; gNabar = 0.120;
gL = 0.0003; EL = -49; EK = -77; ENa = 50; Cm = 0.001;
IC = [0.3177, 0.0529, 0.5961, -62.607];
Vs = [100, 150, 200, 250];
c = char('k-', 'k--', 'k:', 'k-.');
options = odeset('MaxStep', 0.1);
for nn=1:4
[t, y] = ode45(@HodHux2, [0, 10], IC, options, gKbar, gNabar, gL, EL, EK, ENa, Cm, Vr, Vs(nn));
plot(t, y(:,4), c(nn,:))
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.
hold on
end
ylabel('Membrane Potential (mV)')
xlabel('Time (ms)')
A = 'V_s = '; B = ' mV';
legend([A int2str(Vs(1)) B], [A int2str(Vs(2)) B], [A int2str(Vs(3)) B], [A int2str(Vs(4)) B])
function hh = HodHux2(t, y, gKbar, gNabar, gL, EL, EK, ENa, Cm, Vr, Vs)
% y(1) = n, y(2) = m, y(3) = h, y(4) = V
Vd = y(4)-Vr;
dn = alph(Vd, 'n')-(alph(Vd, 'n')+bet(Vd, 'n'))*y(1);
dm = alph(Vd, 'm')-(alph(Vd, 'm')+bet(Vd, 'm'))*y(2);
dh = alph(Vd, 'h')-(alph(Vd, 'h')+bet(Vd, 'h'))*y(3);
dV = -(gKbar*y(1)^4*(y(4)-EK)+gNabar*y(2)^3*y(3)*(y(4)-ENa)+gL*(y(4)-EL))/Cm;
dV = dV+Vs*((t>2) & (t<2.1));
hh = [dn; dm; dh; dV];
Answers:
60
)
V
m
(
V s = 100 mV
V s = 150 mV
V
40
V
,
l
a
i
t
n
e
t
o
P
e
n
a
r
b
m
e
M
= 200 mV
V s = 250 mV
20
-20
-40
-60
-80
0
5
Time (ms)
10
14.16
function Exercise14_16
Vr = -62.607; gKbar = 0.036; gNabar = 0.120;
gL = 0.0003; EL = -49; EK = -77; ENa = 50; Cm = 0.001;
IC = [0.3177, 0.0529, 0.5961, -62.607];
td = [11, 12];
options = odeset('MaxStep', 0.1);
for nn=1:2
subplot(2,1,nn)
[t, y] = ode45(@HodHux3, [0, 20], IC, options, gKbar, gNabar, gL, EL, EK, ENa, Cm, Vr, td(nn));
plot(t, y(:,4), 'k-')
ylabel('Membrane Potential (mV)')
xlabel('Time (ms)')
end
function hh = HodHux3(t, y, gKbar, gNabar, gL, EL, EK, ENa, Cm, Vr, td)
% y(1) = n, y(2) = m, y(3) = h, y(4) = V
Vd = y(4)-Vr;
dn = alph(Vd, 'n')-(alph(Vd, 'n')+bet(Vd, 'n'))*y(1);
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.
l
a
i
t
n
e
t
o
P
e
n
a
r
b
m
e
M
)
V
m
(
l
a
i
t
n
e
t
o
P
60
40
20
0
-20
-40
-60
-80
10
12
14
16
18
20
12
14
16
18
20
Time (ms)
60
40
20
0
e
n
a
r
b
m
e
M
-20
-40
-60
-80
0
10
Time (ms)
14.17
function Exercise14_17
Vr = -62.607; gKbar = 0.018; gNabar = 0.120;
gL = 0.0003; EL = -49; EK = -77; ENa = 50; Cm = 0.001;
IC = [0.3177, 0.0529, 0.5961, -62.607];
options = odeset('MaxStep', 0.1);
[t, y] = ode45(@HodHux, [0, 100], IC, options, gKbar, gNabar, gL, EL, EK, ENa, Cm, Vr);
plot(t, y(:,4), 'k-')
ylabel('Membrane Potential (mV)')
xlabel('Time (ms)')
function hh = HodHux(t, y, gKbar, gNabar, gL, EL, EK, ENa, Cm, Vr)
% y(1) = n, y(2) = m, y(3) = h, y(4) = V
Vd = y(4)-Vr;
dn = alph(Vd, 'n')-(alph(Vd, 'n')+bet(Vd, 'n'))*y(1);
dm = alph(Vd, 'm')-(alph(Vd, 'm')+bet(Vd, 'm'))*y(2);
dh = alph(Vd, 'h')-(alph(Vd, 'h')+bet(Vd, 'h'))*y(3);
dV = -(gKbar*y(1)^4*(y(4)-EK)+gNabar*y(2)^3*y(3)*(y(4)-ENa)+gL*(y(4)-EL))/Cm;
dV = dV+200*((t>2) & (t<2.1));
hh = [dn; dm; dh; dV];
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 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.
60
)
V
m
(
l
a
i
t
n
e
t
o
P
e
n
a
r
b
m
e
M
40
20
-20
-40
-60
-80
0
10
20
30
40
50
Time (ms)
60
70
80
90
100
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 a13
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.