An Engineers Guide to Matlab Solutions

181
Solution to Exercises 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

description

Matlab

Transcript of An Engineers Guide to Matlab Solutions

  • 1Solution to Exercises

    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 a 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.

  • 2Answer: 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 a 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.

  • 31.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 a 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.

  • 4e = 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 a 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.

  • 5format 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 a 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.

  • 6Answer: 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 ' 232 2 4

    3 3 / 22 2

    3 62 2

    3 3 / 2 3 / 22 2 2

    32 2

    cos cos 2 9cos( ) 6 4(cos( ) 2)

    sin 3 cos(2 ) 1 9cos(2 ) 80cos( ) 73

    24 cos cos 2 3cos( ) 2 cos( ) 2

    4 cos 2 cos 9cos(2 ) 80cos( ) 73

    24 cos cos 2 cos( ) 2 3cos( ) 2

    a t t t t

    t a t t t

    a t t t t

    t a t t t

    a t t t t

    ! +

    =+ + +

    + =

    +

    # + % &=( )

    ( ) ( )

    ( ) ( )( )

    ( ) ( )

    ( )( )

    ( )

    3

    3 3 / 23 / 2 3 3 2

    3 3

    3 3 / 22

    3

    3 / 2

    cos( ) 2

    2 cos 4 cos 9cos(2 ) 80cos( ) 73

    4 cos( ) 3cos( ) 2 cos( ) 26 2

    cos 4 cos 9cos(2 ) 80cos( ) 73

    sec 3cos( ) 2 cos( ) 26 2

    9cos(2 ) 80cos( ) 73

    t

    a t t t t

    t t t

    a t t t t

    t t t

    a t t

    +

    =

    +

    =

    +

    (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 a 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.

  • 7(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 a 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.

  • 81.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 a 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.

  • 1Solution 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))]

    Answer: w = -3 -7 -37 -47 51 29 19 17 5

    2.3 y = [0, -0.2, 0.4, -0.6, 0.8, -1.0, -1.2, -1.4, 1.6];

    sy = sin(y);

    % (a)

    mx = max(sy(find(sy

  • 22.5 z = magic(5)

    z(:,2) = z(:,2)/sqrt(3);

    z(5,:) = z(5,:)+z(3,:);

    z(:,1) = z(:,1).*z(:,4);

    q = z-diag(diag(z))+diag([2 2 2 2 2]);

    format long g

    dq = diag(q*q')

    format short

    qmax = max(max(q))

    qmin = min(min(q))

    Answers: z =

    17 24 1 8 15

    23 5 7 14 16

    4 6 13 20 22

    10 12 19 21 3

    11 18 25 2 9

    dq = [486 104189 7300 44522 111024] qmax = 330 qmin = 1

    2.6 w = magic(2);

    wa = repmat(w, 2, 2)

    wb = repmat(w, 3, 1)

    wc = [repmat(w, 3, 1), repmat(w', 3, 1)]

    wad = [w, w; w, w]

    wbd = [w; w; w]

    wcd = [w, w'; w, w'; w, w']

    Answers: wa = % or wad

    1 3 1 3

    4 2 4 2

    1 3 1 3

    4 2 4 2

    wb = % or wbd

    1 3

    4 2

    1 3

    4 2

    1 3

    4 2

    wc = % or wcd

    1 3 1 4

    4 2 3 2

    1 3 1 4

    4 2 3 2

    1 3 1 4

    4 2 3 2

    2.7

    2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This publication is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a 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.

  • 3(a)

    x = magic(3); t = x(1,:); x(1:2,:) = x(2:3,:); x(3,:) = t; x

    Answers: x =

    3 5 7

    4 9 2

    8 1 6

    (b)

    x = magic(3) t = x(:,3); x(:,2:3) = x(:,1:2); x(:,1) = t; x

    Answers: x =

    6 8 1

    7 3 5

    2 4 9

    2.8 x = magic(5);

    xf = fliplr(x);

    xf = fliplr(xf-diag(diag(xf)))

    Answer: xf =

    17 24 1 8 0

    23 5 7 0 16

    4 6 0 20 22

    10 0 19 21 3

    0 18 25 2 9

    2.9 a = 1; b = 1.5; e = 0.3;

    phi = linspace(0, 2*pi);

    s = a*cos(phi)+sqrt(b^2-(a*sin(phi)-e).^2);

    plot(phi*180/pi, s)

    Answer:

    2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This publication is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a 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.

  • 40 50 100 150 200 250 300 350 4000

    0.5

    1

    1.5

    2

    2.5

    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:

    0 5 10 15 20 2582

    84

    86

    88

    90

    92

    94

    96

    98

    100

    2.11 a = sqrt(2.8);

    n = 1:100; % (1x100)

    x = 1:0.5:5; % (1x9)

    exact = a./sqrt(a^2+x.^2).*sin(pi*sqrt(a^2+x.^2))/sin(pi*a);

    e = 100*(prod(1-(1./(n.^2-a^2))'*x.^2)-exact)./exact % prod works on columns

    Answer: e = 1.0001 2.2643 4.0610 6.4176 9.3707 12.9670 17.2642 22.3330 28.2588

    2.12 x = [72, 82, 97, 103, 113, 117, 126, 127, 127, 139, 154, 159, 199, 207];

    beta = 3.644;

    delta = (sum(x.^beta)/length(x))^(1/beta)

    Answer: delta = 144.2741

    2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This publication is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a 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.

  • 52.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:

    -2-1.5

    -1-0.5

    00.5

    11.5

    2

    -2

    -1

    0

    1

    20

    0.5

    1

    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 10002.1644456719

    91.7751642291914 91.7752044040698

    12.9244097924593 12.9244499673344

    4.40350416999114 4.40354434485533

    2.15691498449604 2.15695515933427

    2.15 k = 0:25; n = 2;

    x = linspace(1, 6, 6);

    [xx, kk] = meshgrid(x, k);

    Jn = sum((-1).^kk.*(xx/2).^(2*kk+n)./factorial(kk)./gamma(kk+1+n));

    format long g

    Comp = [Jn' besselj(n, x)']

    format short

    Answer: Comp =

    0.1149034849319 0.114903484931901

    0.352834028615638 0.352834028615638

    2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This publication is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a 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 0.486091260585891 0.486091260585891

    0.364128145852073 0.364128145852073

    0.0465651162777518 0.0465651162777523

    -0.242873209960186 -0.242873209960185

    2.16 n = 7; k = 1:(2*n-1);

    ser = sum(cos(k*pi/n))

    Answer: ser = -1.0000

    2.17 n = 6; k = 1:n;

    N1 = n*(2*n^2+3*n+1)/6

    S1 = sum(k.^2)

    N2 = n*(6*n^4+15*n^3+10*n^2-1)/30

    S2 = sum(k.^4)

    N3 = n^2*(2*n^4+6*n^3+5*n^2-1)/12

    S3 = sum(k.^5)

    Answers: N1 = 91 S1 = 91 N2 = 2275 S2 = 2275 N3 = 12201 S3 = 12201

    2.18 N = 10; n = 0:N;

    PieDiff = sum((4./(8*n+1)-2./(8*n+4)-1./(8*n+5)-1./(8*n+6)).*(1/16).^n) -pi

    Answer: PieDiff = 0

    2.19 k=1:300;

    dn=0.5*cumsum(1./k);

    On = find(dn>1);

    d1 = On(1)

    tw = find(dn>2);

    d2 = tw(1)

    th = find(dn>3);

    d3 = th(1)

    Answer: d1 = 4 d2 = 31 d3 = 227

    2.20 N = 10; k = 0:N;

    e = sum(1./factorial(k))-exp(1)

    Jo = sum((-1).^k./factorial(k).^2)-besselj(0,2)

    co = sum((-1).^k./factorial(2*k))-cos(1)

    Answers: e = -2.7313e-008 Jo = 6.3838e-016 co = -1.1102e-016

    2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This publication is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a 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.

  • 72.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)

  • 8A = [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 a 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.

  • 9th4 = 0; th5 = 215*c; th6 = 55*c;

    a2 = 0.431; a3 = 0.019; r4 = a2; r3 = 0.125;

    T12 = [cos(th1) 0 sin(th1) 0 ; sin(th1) 0 -cos(th1) 0 ; 0 1 0 0; 0 0 0 1];

    T23 = [cos(th2) -sin(th2) 0 a2*cos(th2); sin(th2) cos(th2) 0 a2*sin(th2); 0 0 1 0; 0 0 0 1];

    T34 = [cos(th3) 0 sin(th3) a3*cos(th3); sin(th3) 0 -cos(th3) a3*sin(th3); 0 1 0 r3; 0 0 0 1];

    T45 = [cos(th4) 0 sin(th4) 0; sin(th4) 0 -cos(th4) 0; 0 1 0 r4; 0 0 0 1];

    T56 = [cos(th5) 0 sin(th5) 0; sin(th5) 0 -cos(th5) 0; 0 1 0 0; 0 0 0 1];

    T67 = [cos(th6) 0 sin(th6) 0; sin(th6) 0 -cos(th6) 0; 0 1 0 0; 0 0 0 1];

    T17 =T12*T23*T34*T45*T56*T67

    Answer: T17 =

    0.2418 -0.5540 0.7966 -0.4729

    0.9128 -0.1485 -0.3804 -0.2561

    0.3290 0.8192 0.4698 0.5459

    0 0 0 1.0000

    2.31 x = [17 31 5;6 5 4;19 28 9;12 11 10];

    H = diag(x*inv(x'*x)*x')'

    Answer: H = 0.7294 0.9041 0.4477 0.9188

    2.32 % square

    n = 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 a 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

    tau = linspace(-2, 2, 200);

    plot(tau, 64*((sin(n*pi/4)./(pi*n).^2)*sin(pi*n'*tau)))

    2.33 a = sqrt(3); n = 1:25;

    t = (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:

    0

    0.2

    0.4

    0.6

    0.8

    1

    0

    0.2

    0.4

    0.6

    0.8

    10

    0.2

    0.4

    0.6

    0.8

    1

    1.2

    1.4

    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 a 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

    0

    0.5

    1

    1.5

    2

    0

    0.1

    0.2

    0.3

    0.4

    0.5

    0.6

    0.7

    0.8

    0.9

    1

    -4

    -2

    0

    2

    4

    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 a 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

    0.3500 -1.1375 0.3875 -0.1000

    0.0333 -0.1500 0.1500 -0.0333

    2.40 a = 0.005; b = 0.0064; c = 0.008;

    E1 = 2.1e9; E2 = 0.21e9;

    nu1 = 0.4; nu2 = 0.4; Uo = 0.00025;

    Matrix = [1, a^2, 0, 0; 1, b^2, -1, -b^2; ...

    -(1+nu1), (1-nu1)*b^2, (1+nu2)*E1/E2, -(1-nu2)*b^2*E1/E2;...

    0, 0, -(1+nu2), (1-nu2)*c^2];

    y = [0, 0, 0, -Uo*E2*c]';

    AB = Matrix\y;

    hoop1 = -AB(1)/b^2+AB(2)

    hoop2 = -AB(3)/b^2+AB(4)

    % check

    urc = -(1+nu2)*AB(3)/E2/c+(1-nu2)*c*AB(4)/E2

    Answers: hoop1 = -6.3013e+007 hoop2 = -1.1790e+007 urc = -2.5000e-004

    2.41 syms i1 i2 i3 R V1 V2 V3

    Q1 = 'V1-6*R*i1+4*R*(i2-i1)=0,';

    Q2 = 'V2+2*R*(i3-i2)-3*R*i2-4*R*(i2-i1)=0,';

    Q3 = '-V3-R*i3-2*R*(i3-i2y)=0';

    [i1 i2 i3] = solve([Q1 Q2 Q3])

    Answer: i1 = 1/182/R*(23*V1 + 12*V2 - 8*V3)

    i2 = 1/91/R*(6*V1 + 15*V2 - 10*V3)

    i3 = 1/91/R*(4*V1 + 10*V2 - 37*V3)

    2.42 Either

    syms s t V1 V2 V3 U real

    A = [2*s+t -s 0; -s 2*s+t -s; 0 -s s+t];

    B = [s*U 0 0]';

    V=inv(A)*B

    or

    syms s t V1 V2 V3 U real

    [V1 V2 V3] = solve((2*s+t)*V1-s*V2-s*U, -s*V1+(2*s+t)*V2-s*V3, -s*V2+(s+t)*V3, V1, V2, V3);

    V1 = factor(V1)

    V2 = factor(V2)

    V3 = factor(V3)

    gives

    Answer: V1 = (U*s*(s^2 + 3*s*t + t^2))/(s^3 + 6*s^2*t + 5*s*t^2 + t^3)

    V2 = (U*s^2*(s + t))/(s^3 + 6*s^2*t + 5*s*t^2 + t^3)

    V3 = (U*s^3)/(s^3 + 6*s^2*t + 5*s*t^2 + t^3)

    2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This publication is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a 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.

  • 1Solution 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

    F 1 = 1

    F 2 = 1

    F 3 = 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 a 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.

  • 23.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 pi/9 = 20.0 degrees

    cos(pi/8) = 0.92388 pi/8 = 22.5 degrees

    cos(pi/7) = 0.90097 pi/7 = 25.7 degrees

    cos(pi/6) = 0.86603 pi/6 = 30.0 degrees

    cos(pi/5) = 0.80902 pi/5 = 36.0 degrees

    cos(pi/4) = 0.70711 pi/4 = 45.0 degrees

    cos(pi/3) = 0.50000 pi/3 = 60.0 degrees

    cos(pi/2) = 0.00000 pi/2 = 90.0 degrees

    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, 1! = 1

    For n = 2, 2! = 2

    For n = 3, 3! = 6

    For n = 4, 4! = 24

    The sum of these 4 factorials = 33

    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 a 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.

  • 1Solution 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 a 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.

  • 24.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:

    0 10 20 30 40 50 60 70 80 90 1006

    6.5

    7

    7.5

    8

    8.5

    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 a 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.

  • 3 ($) ($/yr) (%) years ($)

    250000 25000 4.5 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)=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)

  • 44.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

  • 50 20 40 60 80 100 120 140 160 180 2000

    0.05

    0.1

    0.15

    0.2

    0.25

    0.3

    0.35

    0.4

    0.45

    0.5

    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

  • 6 h = 11 12 114 116

    h = 77 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

  • 7for 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

  • 1Solution 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 Kpoly

    0.6504 0.6504 0.6504

    0.8900 0.8900 0.8900

    1.1126 1.1126 1.1135

    1.3479 1.3479 1.3369

    1.6098 1.6098 1.6970

    1.9497 1.9497 1.8546

    1.9814 1.9814 1.9221

    2.0495 2.0495 1.9886

    2.0870 2.0870 2.1037

    2.2645 2.2645 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)

  • 2freqpeak = 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 20.0781 Hz

    Average power = 0.0013038

    Peaks occur at 4.92188 9.0625 9.45313 20.0781 Hz

    0 5 10 15 20 25 30 35 400

    0.01

    0.02

    0.03

    0.04

    0.05

    0.06

    0.07

    0 5 10 15 20 25 30 35 400

    0.002

    0.004

    0.006

    0.008

    0.01

    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

    In Exercises 5.4 to 5.12 we have used the following function:

    function Rt = FindZeros(FunName, Nroot, x, w)

    f = feval(FunName, x, w);

    indx = find(f(1:end-1).*f(2:end)

  • 3Rt = 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 7.7253 10.9041 14.0662 17.2208

    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 = 0.4435 3.2040 6.3149 9.4460 12.5823

    Rt = 1.3065 3.6732 6.5846 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 9.4182 12.5614 15.7040

    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 a 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.

  • 4for 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 6.3064 9.4395

    m = 1: 4.6109 7.79927 10.9581

    m = 2: 5.90568 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)

  • 5x = [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 a 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 -9.068133269285e-9 1.6182240726495e-9 -3.320447939146e-10];

    g = 0.0588; k = 1:12; r = rr.^k; t = tt.^k(1:6);

    z1 = r(1)*sum(a(1:6).*t(1:6)/t(1))+r(2)*sum(a(7:10).*t(1:4)/t(1))+r(3)*sum(a(11:13).*t(1:3)/t(1));

    z2 = r(4)*a(14)*t(1)+r(5)*(a(15)*t(2)+a(16)*t(3))+r(6)*a(17)*t(2)+r(7)*(a(18)*t(1)+a(19)*t(3)) ...

    +r(8)*a(20)*t(3);

    z31 = r(2)*(a(21)*t(3)+a(22)*t(4))+r(4)*(a(23)*t(3)+a(24)*t(5))+r(6)*(a(25)*t(3)+a(26)*t(4));

    z32 = r(8)*(a(27)*t(3)+a(28)*t(5))+r(10)*(a(29)*t(3)+a(30)*t(4));

    z33 = r(12)*(a(31)*t(3)+a(32)*t(4)+a(33)*t(5));

    z = 1+z1+z2+(z31+z32+z33)*exp(-g*r(2));

    function s = pvrtr(r, p, t)

    s = zstanford(r,t)-p*t/r;

    function s = pvrtt(t, p, r)

    s = zstanford(r,t)-p*t/r;

    Answers: Zi = 7.024239692767296e-001

    Zii = 2.999999998525347e-001

    Ziii = 9.922185392802401e-001

    p = 0.6 1/tau = 1.05 r = 0.71309 Z = 0.80134

    p = 2.18 1/tau = 1.2 r = 3.3567 Z = 0.54121

    p = 0.6 1/r = 1.4 t = 0.95319 Z = 0.80068

    p = 2.18 1/r = 0.6 t = 0.65049 Z = 0.85084

    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 a 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.

  • 7ro = roots([3*pi*sqrt(5) -60 0 0 0 0 0 0 0 20]);

    posroot = ro(find(real(ro)>1))

    Answer: posroot = 2.8468

    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 a 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.

  • 8 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 a 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.

  • 9[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

  • 10

    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:

    0 5 10 15 20 25 30 35 40 45 50-1

    -0.5

    0

    0.5

    1

    -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8-1

    -0.5

    0

    0.5

    1

    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)

  • 11

    Answer: Minimum xi = 0.71873

    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 -0.5 0 0.5 1 1.5-1

    -0.5

    0

    0.5

    1

    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 a 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

    -1.5 -1 -0.5 0 0.5 1 1.5-1.5

    -1

    -0.5

    0

    0.5

    1

    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 100 200 300 400 500 600 700 800-0.4

    -0.3

    -0.2

    -0.1

    0

    0.1

    0.2

    0.3

    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 a 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.

  • 13

    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:

    0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

    0.8

    1

    1.2

    1.4

    1.6

    1.8

    2

    2.2

    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 a 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.

  • 14

    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 0.2 0.4 0.6 0.8 10

    0.02

    0.04

    0.06

    0.08

    0.1

    0.12

    0 0.2 0.4 0.6 0.8 10

    0.05

    0.1

    0.15

    0.2

    0 0.2 0.4 0.6 0.8 10

    0.1

    0.2

    0.3

    0.4

    0 0.2 0.4 0.6 0.8 1-0.5

    -0.4

    -0.3

    -0.2

    -0.1

    0

    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 a 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.

  • 15

    function z = Shoot(q, Pbar, alph, sw, tol)

    z = q-NLBeam(q, Pbar, alph, sw, tol);

    function [res, dis]= NLBeam(y0, Pbar, alph, sw, tol)

    solinit = bvpinit(linspace(0,1,5), [2 1]);

    opt = bvpset('RelTol', tol);

    solu = bvp4c(@Odes, @BC, solinit, opt, Pbar, alph, y0);

    r = deval(solu(1,end), 1);

    res = r(1);

    dis = [999, 999];

    if sw==1

    xx = linspace(0,1,50);

    s = deval(solu,xx);

    dis = [trapz(xx, cos(s(1,:))), trapz(xx, sin(s(1,:)))] ;

    end

    function der = Odes(x, y, Pbar, alph, y0)

    der = [y(2); -Pbar*sin(y(1)+alph-y0)];

    function der = BC(ya, yb, Pbar ,alph, y0)

    der = [ya(1); yb(2)];

    Answer: Pbar = 8 phi(0) = 157.938 (deg) x(0) = -0.073844 y(0) = 0.63353

    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 a 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.

  • 16

    solinit = bvpinit(linspace(0.2,1,5), [0.1, 0.1, 0.1, 0.1]);

    plat = bvp4c(@Plate, @bcPlate, solinit, [], v);

    rr = linspace(0.2, 1, 50);

    w = deval(plat, rr);

    subplot(2,2,1)

    plot(rr, w(1,:), 'k')

    subplot(2,2,2)

    plot(rr, w(2,:), 'k')

    subplot(2,2,3)

    plot(rr, w(3,:)+v*w(2,:)./rr, 'k')

    subplot(2,2,4)

    plot(rr, w(4,:)+w(3,:)./rr-w(2,:)./rr.^2, 'k')

    function s = Plate(r, y, v)

    s = [y(2); y(3); y(4); -2/r*y(4)+y(3)/r^2-y(2)/r^3+1];

    function d = bcPlate(yi, yo, v)

    d = [yi(1); yi(2); yo(3)+v*yo(2); yo(4)+yo(3)-yo(2)];

    Answer:

    0.2 0.4 0.6 0.8 10

    0.01

    0.02

    0.03

    0.04

    0.05

    0.06

    0.2 0.4 0.6 0.8 10

    0.02

    0.04

    0.06

    0.08

    0.2 0.4 0.6 0.8 1-0.2

    0

    0.2

    0.4

    0.6

    0.8

    0.2 0.4 0.6 0.8 1-2.5

    -2

    -1.5

    -1

    -0.5

    0

    0.5

    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 a 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.

  • 17

    function bc = CantileverBC(y0, y1, S)

    bc = [y0(1); y0(2); y1(3); y1(4)+S*y1(2)];

    Answer:

    0 0.2 0.4 0.6 0.8 10

    0.05

    0.1

    0.15

    0.2

    0 0.2 0.4 0.6 0.8 10

    0.05

    0.1

    0.15

    0.2

    0.25

    0 0.2 0.4 0.6 0.8 10

    0.1

    0.2

    0.3

    0.4

    0.5

    0.6

    0.7

    0 0.2 0.4 0.6 0.8 1-1

    -0.8

    -0.6

    -0.4

    -0.2

    0

    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 a 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.

  • 18

    lambda2 = fzero(wormlead, [25 40]*pi/180, opt, 0.16, 1.5)*180/pi

    Answers: 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 a 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.

  • 19

    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

    From matrix inversion:

    TA = 352.052 TB = 326.5116 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 a 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.

  • 20

    disp(['alphaMax = ' num2str(AlphMax) ' and f(alphaMax) = ' num2str(-fAlphaMax)])

    [AlphMin fAlphaMin] = fminbnd(@Integ, 0.5, 5);

    disp(['alphaMin = ' num2str(AlphMin) ' and f(alphaMin) = ' num2str(fAlphaMin)])

    function In = Integ(alph)

    In = (2+sin(10*alph)).*quadl(@Arg, 0, 1.8, [], [], alph);

    function A = Arg(x, alph)

    A = x.^alph.*sin(alph./(2-x));

    Answers: alphaMax = 0.78153 and f(alphaMax) = 3.2284

    alphaMin = 3.8882 and f(alphaMin) = -0.99339

    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 a 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.

  • 21

    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, a22, a23, a33]);

    C2 = matlabFunction(C(2), 'vars', [a11, a12, a13, a22, a23, a33]);

    C3 = matlabFunction(C(3), 'vars', [a11, a12, a13, a22, a23, a33]);

    C4 = matlabFunction(C(4), 'vars', [a11, a12, a13, a22, a23, a33]);

    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 L(1,n) L(2,n) L(3,n)

    0 1.0546 0.7105 0.4646

    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 a 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.

  • 22

    1.0000 1.5258 0.8883 0.2574

    2.0000 2.3405 1.3203 0.1271

    3.0000 3.2468 1.8546 0.1433

    4.0000 4.1920 2.4212 0.2348

    5.0000 5.1566 2.9996 0.3630

    6.0000 6.1320 3.5831 0.5213

    7.0000 7.1141 4.1693 0.7088

    8.0000 8.1004 4.7570 0.9253

    9.0000 9.0897 5.3457 1.1706

    10.0000 10.0811 5.9351 1.4449

    0 1 2 3 4 5 6 7 8 9 10

    100

    101

    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 a 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.

  • 1Solution 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 a 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

    %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 a 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.

  • 3

    % 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 a 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.

  • 4Answer:

    % 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)