Solutions Manual

to accompany

Applied Numerical Methods
With MATLAB for Engineers and Scientists

Steven C. Chapra
Tufts University

CHAPTER 1
1.1 You are given the following differential equation with the initial condition, v(t = 0) = 0,

c
dv
= g − d v2
dt
m
Multiply both sides by m/cd

m dv m
=
g − v2
c d dt c d
Define a = mg / c d

m dv
= a2 − v2
c d dt
Integrate by separation of variables,

dv

cd

∫ a 2 − v 2 = ∫ m dt
A table of integrals can be consulted to find that

∫a

2

dx
x
1
= tanh −1
2
a
a
−x

Therefore, the integration yields
1
v c
tanh −1 = d t + C
a
a m

If v = 0 at t = 0, then because tanh–1(0) = 0, the constant of integration C = 0 and the solution
is
1
v c
tanh −1 = d t
a
a m
This result can then be rearranged to yield

v=

⎛ gc d ⎞
gm
tanh ⎜
t⎟
⎜ m ⎟
cd

1.2 This is a transient computation. For the period from ending June 1:

1

Balance = Previous Balance + Deposits – Withdrawals
Balance = 1512.33 + 220.13 – 327.26 = 1405.20
The balances for the remainder of the periods can be computed in a similar fashion as
tabulated below:
Date

Deposit

Withdrawal

1-May

Balance
$ 1512.33

$ 220.13

$ 327.26

1-Jun

$ 1405.20
$ 216.80

$ 378.61

1-Jul

$ 1243.39
$ 350.25

$ 106.80

1-Aug

$ 1586.84
$ 127.31

$ 450.61

1-Sep

$ 1363.54

1.3 At t = 12 s, the analytical solution is 50.6175 (Example 1.1). The numerical results are:
step
2
1
0.5

v(12)
51.6008
51.2008
50.9259

absolute
relative error
1.94%
1.15%
0.61%

where the relative error is calculated with

absolute relative error =

analytical − numerical
× 100%
analytical

The error versus step size can be plotted as
2.0%

1.0%
relative error
0.0%
0

0.5

1

1.5

2

Thus, halving the step size approximately halves the error.
1.4 (a) The force balance is

2

2.5

dv
c'
=g− v
dt
m
Applying Laplace transforms,
sV − v(0) =

g c'
− V
s m

Solve for
V=

g
v ( 0)
+
s ( s + c ' / m) s + c ' / m

(1)

The first term to the right of the equal sign can be evaluated by a partial fraction expansion,

g
A
B
= +
s ( s + c ' / m) s s + c ' / m

(2)

g
A( s + c' / m) + Bs
=
s ( s + c ' / m)
s ( s + c ' / m)

Equating like terms in the numerators yields
A+ B=0
g=

c'
A
m

Therefore,
A=

mg
c'

B=−

mg
c'

These results can be substituted into Eq. (2), and the result can be substituted back into Eq.
(1) to give
V=

mg / c'
mg / c'
v ( 0)

+
s
s + c' / m s + c' / m

Applying inverse Laplace transforms yields
v=

mg mg −( c '/ m )t

e
+ v ( 0) e − ( c ' / m ) t
c'
c'

or

3

9294 2.81 − (19. 1 ⎣ ⎦ The computation can be continued and the results summarized and plotted as: t 0 2 4 6 8 10 12 v 0 19.v = v(0)e −( c '/ m )t + ( mg 1 − e −( c '/ m )t c' ) where the first term to the right of the equal sign is the general solution and the second is the particular solution.5739 0.81 − (0) 2 = 19. so the final solution is v= ( mg 1 − e −( c '/ m )t c' ) (b) The numerical solution can be implemented as 12.0102 dv/dt 9.8700 48.1 ⎥⎦ ⎣ 12.81 6.8962 44.6200 32.5 ⎤ ⎡ v(2) = 0 + ⎢9. For our case.62 + ⎢9.5 ⎡ ⎤ v(4) = 19. v(0) = 0.2087 68 .4869 1.6304 60 40 20 0 0 4 8 12 Note that the analytical solution is included on the plot for comparison.0374 39.0179 50.62 68.62)⎥ 2 = 6.9961 0.2087 3. 4 .

1 = 9.7015 -1.8447 -1.8584 8.5 = 0 + [0 − 0.4 2.333333 0.6 0.7717 -1.7 0.7363 -1.2 0.8078 -1.0000 -1.8 − 0.6813 8.1 = 9.6341 (b) The results when plotted on a semi-log plot yields a straight line 2.2237 9.8000 9.2(10)0.0392 8.9 1 c 10.1.5) = 0 + ⎢3 sin 2 (0) − 0.1707 dc/dt -2.6 The first two steps yield 400 ⎤ ⎡ 400 y (0.5 = −0.16667 1200 ⎥⎦ ⎣ 1200 [ ] y (1) = −0.8 Bq/L c(0.8 0.4119 9.9600 -1.8)0.3 2.6040 9.8 1 The slope of this line can be estimated as ln(8.4 0.1 2 0 0.0000 9.5 (a) The first two steps are c(0.8824 -1.1 0.2 0.6675 -1.21841 5 .5 0.2 2.3375 8.2) = 9.5076 8.2(9.6 0.5) − 0.604 Bq/L The process can be continued to yield t 0 0.5 = −0.9208 -1.3 0.4 0.1) = 10 − 0. the slope is approximately equal to the negative of the decay rate.33333] 0.1707) − ln(10) = −0.16667 + sin 2 (0. 1.20203 1 Thus.

5 − 52.18666 t 0.7 v(t ) = (1 − e ⎝ m ⎠ ) c ⎛ 12.8 y 0.5 ⎛ 14 ⎞ −⎜ ⎟ t 9.18666 t ln 0.8 Qin = Qout Q1 = Q2 + Q3 6 5 .03104 0.33 sec 1.87 m / s jumper #1: v(t ) = 12.The process can be continued to give t 0 0.5 4 4.5 5 y 0 -0.546537 0.5 2 2.1 ⎠ ) = 44.402245 0.5 1 1.299793 0.14533 = ln e −0.8(68.16667 -0.297103 0.18666 t t = 10.4 0 0 1 2 3 4 -0.5 ⎞ −⎜ ⎟ 10 9.558955 0.87 = 52.14533 = e −0.5e −0.87 = (1 − e ⎝ 75 ⎠ ) 14 44.8(75) jumper #2: 44.5 3 3.21841 -0.4 ⎛c⎞ −⎜ ⎟ t gm 1.727927 0.1) (1 − e ⎝ 68.416811 0.

5 + 12 + 4.30 = 20 + vA3 10 = 5 A3 A3 = 2 m2 1.5 % 7 .10 ∑ % body weight = 60 4.5 + 4.5 + 12 + 4.5 + IW = 60 % Intracellular water body weight = 33 % 4.5 + 1.5 + 4.5 + 55 + TW = 100 % Transcellular water of body water = 2.5 + 1.5 + 7.5 + 20 + 7.9 ∑ M in − ∑ M out = 0 [1000 + 1200 + MP + 50] − [400 + 200 + 1400 + 200 + 350] = 0 Metabolic production = 300 grams 1.5 + IW = 60 ∑ % body water = 100 7.

t = linspace(0.L = 5.q) >> >> >> >> >> z = linspace(-3.1 >> >> >> >> q0 = 10.R = 50.CHAPTER 2 2.2 2.^2/2).3 (a) >> t = linspace(5.*cos(sqrt(1/(L*C)-(R/(2*L))^2)*t).f) xlabel('z') ylabel('frequency') 2.C = 1e-4. plot(z.. f = 1/sqrt(2*pi)*exp(-z.5).6) 8 . plot(t. q = q0*exp(-R*t/(2*L)).30.3).

>> x = [0.6:93.5622e-5*TC+0.0800 >> U = .0000 1.0000 (b) >> r = 6:-1:0 r = 6 5 4 3 2 1 0 2.010 0.0675 0.6667 0.013 0.6 >> >> >> >> TF = 32:3.009 0.7692 0.^3-8.1200 >> max(U) ans = 0.5016e-6*TC.5000 0.0450 0.5289e-8*TC.7) x = -3 -2 -1 0 3 2. rho = 5.010].0720 0.0000 -1. plot(TC.9000 1.75:1 v = -2.0e+003 * 0.020 0.5*k.4 (a) >> v = -2:.^2+6.2. TC = 5/9*(TF-32).99987.5 >> F = [10 12 15 9 12 16].rho) 9 .6000 0./x k = 1.t = 5 10 15 20 25 30 1 2 (b) >> x = linspace(-3.012 0.2500 -0.6000 1.2500 1.*x.1200 2.3.^2 U = 0. >> k = F.0650 0.

0002 0.4))).2. cf = 4. tf = 0:70. .'s'.5] A = 0.6 1.0000 2.0000 8.3624 0.^(2/3) U = 0.0007 0.034*tf).0220 0. . c = [3.0001 10 2.*A(:.0007 24 3.7 >> A = [.c.0000 2.0200 0.0000 1.5809 1.0000 20.0003 10.02 .022 .6 1.03 . plot(t.8 >> >> >> >> >> t = 10:10:60.015 .0002 8 1.3).5./A(:.1).0001 0.0300 0.1971 2.0350 0.5000 3.5].5167 1.0 0.cf.0000 1.0000 15.4 2.'--') 10 .4).*(A(:.0000 24.tf.6094 2.3 1.001 20 1. .3)+2*A(:.0003 15 2.5000 >> U = sqrt(A(:.84*exp(-0./(A(:.0010 0. .035 .2)).0150 0.

9 >> >> >> >> >> t = 10:10:60. F = [25 70 380 550 610 1220 830 1450].tf.3 1. cf = 4.6 1.0 0. Ff = 0.^1.':') 2.5].Ff.vf.c.034*tf).84*exp(-0. c = [3. semilogy(t.'--') >> >> >> >> >> v = 10:10:80.4 2.10 11 .'d'. plot(v.cf.2.9842.'s'.6 1. tf = 0:70.F.2741*vf. vf = 0:100.

Ff = 0.'d'. plot(x.vf. c = cos(x).^6/factorial(6).F.^1.2741*vf. F = [25 70 380 550 610 1220 830 1450].11 >> >> >> >> >> v = 10:10:80.Ff.12 12 .x. cf = 1-x. loglog(v. vf = 0:100.'--') 2.c.^2/2+x.9842.^4/factorial(4)-x.2.':') >> >> >> >> x = linspace(0.3*pi/2).cf.

13 .

37669564 6. end This function can be used to evaluate the test case.43 171382. >> futureworth(100000.00000310 -0.9974949866 error -50. i.1) * x^(2*i-1) / factorial(2*i-1).81 158687.9974949866 0.9974949866 0.8) year 0 1 2 3 4 5 6 7 8 future worth 100000. fprintf('\n').90 146932.0. This function can be used to evaluate the test case.00 125971. y = [nn.00000003 0.32945162 0.00 116640. >> sincomp(1.10f %12.CHAPTER 3 3.tru.2 The M-file can be written as function futureworth(P.F].9974971226 0. F = P*(1+i).2f\n'. while (1) if i > n.9974949557 0.00000000 3.9974949869 0.ser) / tru * 100.8f\n'.9974949866 0.^nn.43 185093.9974949866 approximation 1.n) i = 1. i = i + 1.5.8) order 1 2 3 4 5 6 7 8 true value 0.1 The M-file can be written as function sincomp(x. fprintf('%5d %14. n) nn = 0:n.ser.00 108000.01456523 -0.08.9974949866 0. fprintf('\n year future worth\n'). tru = sin(x).0007812500 0.9974949866 0. ser = 0. fprintf('%3d %14.02 14 .5000000000 0.er).00021414 0.20 136048.i.9375000000 1.y). fprintf('order true value approximation error\n'). er = (tru . end ser = ser + (-1)^(i .10f %14.01040643 -0.9974949866 0.9973911830 0.9974949866 0. break.

2.5) year 1 2 3 4 5 annualpayment 37660. n) nn = 1:n.59) ans = -10. tend) omega = 2*pi/365. t = tstart:tend. i. >> avgtemp(5.180. This function can be used to evaluate the test case.0.y).1.4 The M-file can be written as function Tavg = avgtemp(Tmean./((1+i).0398 3. d) if d < R vol = pi * d ^ 3 / 3. Tavg = mean(Te). v2 = pi * R ^ 2 * (d . tstart.00 19519.. else error('overtop') end This function can be used to evaluate the test cases.^nn. >> annualpayment(35000. This function can be used to evaluate the test cases. y = [nn.A].076.34 13483. 15 .R).30 8673. elseif d <= 3 * R v1 = pi * R ^ 3 / 3.33. vol = v1 + v2.1.5 The M-file can be written as function vol = tankvol(R.8418 >> avgtemp(23.3 The M-file can be written as function annualpayment(P. fprintf('%5d %14.2f\n'. Tpeak.242) ans = 33.6.26 10473. A = P*i*(1+i).3.22.^nn-1).76 3. Te = Tmean + (Tpeak-Tmean)*cos(omega*(t-205)). fprintf('\n year annualpayment\n').

1. y) r = sqrt(x . elseif y < 0 th = atan(y / x) .2) ans = 1.th]=polar(1. if x < 0 if y > 0 th = atan(y / x) + pi. end else if y > 0 th = pi / 2.3. >> [r. end end th = th * 180 / pi. th] = polar(x.3. This function can be used to evaluate the test cases. elseif y < 0 th = -pi / 2.>> tankvol(1.^ 2 + y .6 The M-file can be written as function [r.3304 >> tankvol(1. else th = 0. For example. for the first case.pi.0. else th = pi.^ 2).0) ans = 7.1) ??? Error using ==> tankvol overtop 3.4142 th = 90 The remaining cases are 16 .5) ans = 0.6755 >> tankvol(1.1309 >> tankvol(1.1) r = 1.

0000 0.ou).4142 1.00 0. elseif y(i) < 0 th(i) = atan(y(i) / x(i)) .0000 1. >> polar2(x.4142 1.4142 1.0000 1. n = length(x). end ou = [x.00 -1.th]. angle\n').00 1.0000 1.^ 2).0000 0. end else if y(i) > 0 th(i) = pi / 2.0000 135.00 1.0000 1.^ 2 + y . y) r = sqrt(x .00 1. fprintf('\n x y radius fprintf('%8.0000 1.y) x 1. end end th(i) = th(i) * 180 / pi. else th(i) = pi.00 0.0000 angle 90.7 The M-file can be written as function polar2(x.0000 1.0000 -90.pi.0000 90 −90 0 135 −135 180 90 −90 0 3.0000 -135.2f %8.4142 1.00 0.x 1 1 1 −1 −1 −1 0 0 0 y 1 −1 0 1 −1 0 1 −1 0 θ r 1.0000 17 .00 y 1.4f\n'.r. for i = 1:n if x(i) < 0 if y(i) > 0 th(i) = atan(y(i) / x(i)) + pi.4142 1.00 -1.0000 0. elseif y(i) < 0 th(i) = -pi / 2.00 -1.y.0000 180.00 -1.2f %10.00 1.0000 90.00 -1.00 0.00 0.00 0. This function can be used to evaluate the test cases and display the results in tabular form.0000 0.00 -1. else th(i) = 0.00 radius 1.4f %10.4142 1.4142 1.0000 -90.4142 1.

8 The M-file can be written as function grade = lettergrade(score) if score >= 90 grade = 'A'. >> lettergrade(95) ans = A >> lettergrade(45) ans = F >> lettergrade(80) ans = B 3./A(:. This function can be run to create the table.50 3.022 S 0.2f %10.3. else grade = 'F'.0002 0.0010 0.00 24.A'). elseif score >= 70 grade = 'C'.4f %10.5809 1.5167 1.00 2. fprintf('\n n S B H U\n').9 The M-file can be written as function Manning(A) A(:.035 0.00 8.00 1.020 0.^(2/3).015 0.00 1.4))).*A(:.2f %10.00 H 2.0007 0. >> Manning(A) n 0.030 0.*(A(:.3624 0.4).2)).4f\n'. end This function can be tested with a few cases. elseif score >= 60 grade = 'D'.1971 .50 18 U 0.0001 0.0003 B 10.6094 2.3f %8.3).00 20. fprintf('%8.1).00 15.5) = sqrt(A(:.3)+2*A(:./(A(:. elseif score >= 80 grade = 'B'.

*xx(i)^3 . >> beam(10) 3.10 The M-file can be written as function beam(x) xx = linspace(0.4)-sing(xx(i).*sing(xx(i).*xx(i).3.2). >> cylinder(2. for i=1:n uy(i) = -5/6.11 The M-file can be written as function cylinder(r.5) 19 .*sqrt(2*r*h-h.a./r)-(r-h).n) if xxx > a s = (xxx .3) + 75*sing(xx(i). n=length(xx). plot(h.x).^n.a). end plot(xx.2*r). else s=0.*(sing(xx(i). uy(i) = uy(i) + 15/6. V = (r^2*acos((r-h).25. uy(i) = uy(i) + 57/6.7. V) This function can be run to the plot.4)). end This function can be run to create the plot.5. L) h = linspace(0.^2))*L.238.uy) function s = sing(xxx.0.8.

20 .

9% 2.996 1 − 3x 2 = 0.462 = = 2.577 2 ) 2 Using 3-digits with chopping chopping 6 x = 6(0.577) = 3.0013 f ' (0.462 ⎯⎯ ⎯⎯→ 3.CHAPTER 4 4.46 = = 216. the error is still considerable.352.521 2 (1 − 0.37 3 − 7(1.352.37) 2 + 8(1.1 The true value can be computed as f ' (1.577) = 2.577 chopping x 2 = 0.352.46 3.332 3x 2 = 0.004 f ' (0. the correct result can be calculated as y = 1.3329 2 3x = 0.462 6 x = 6(0.46 x = 0.0013 2 This represents a percent relative error of εt = 2.8% 2. 4.577) = 3.332929 ⎯⎯ ⎯⎯→ 0.048.911 Although using more significant digits improves the estimate.462 ⎯⎯ x = 0.911 − 216.352.462 3.048.911 Using 4-digits with chopping chopping ⎯⎯→ 3.996) 0.9987) 0.22) = 6(0.577) = 3. Such subtractive cancellation is worsened by the fact that the denominator is squared.35 = 0.577) = 3.911 − 2.332929 ⎯⎯ ⎯⎯→ 0.9987 1 − 3x 2 = 0.37) − 0. The problem stems primarily from the fact that we are subtracting two nearly equal numbers in the denominator.250 2 (1 − 0.2 First.911 (1 − 3 × 0.250 = 90.004 2 This represents a percent relative error of εt = 2.521 = 12.577 chopping x 2 = 0.352.043053 21 .

35 y = 0.29 × 1.3 (a) For this case.571353 –7(1.37 − 0.35 y = (−5.71 + 8)1.043053 − 0. Thus.7% 0.(a) Using 3-digits with chopping 1.37 + 8)1.35 y = 0. f (0) = f ' (0) = f " (0) = f ( 3) (0) = 1 Substituting these values yields.57 –13.35 –0.35 y = (−7.35 y = 0.043053 − 0.37 + 8)1.043053 Hence.043053 (b) Using 3-digits with chopping y = ((1.37 − 0. 22 . 4.47 = 9.37 − 0.373 –7(1.9 – 0.37)2 8(1.047 This represents an error of εt = 0. xi = 0 and h = x.0 10.63 × 1.87) 10. the second form is superior because it tends to minimize round-off error. the Taylor series is f ( x) = f (0) + f ' (0) x + f " ( 0) 2 f ( 3 ) ( 0) 3 x + x + ⋅⋅⋅ 2! 3! For the exponential function.397 − 0.96 → → → 2.37) → → → 2.37 − 7)1.2% 0.12 = 178.12 This represents an error of εt = 0.37 − 0.

367879 Second-order approximation: f (1) = 0.367879 − 0.367879 First-order approximation: f (1) = 0.75 2 = 0.778801 = 0.7% 0.778801 100% = 111.1% 0.367879 Third-order approximation: f (1) = 0.f ( x) = 1 + x + 1 2 1 3 x + x + ⋅⋅⋅ 2! 3! which is the Maclaurin series expansion. The complete Taylor series to the third-order term is f ( xi +1 ) = e − xi − e − xi h + e − xi h2 h3 − e − xi 2 3! Zero-order approximation: f (1) = e −0.5% 0.707107… zero-order: 23 .413738 2 0.1947 εt = 0.778801(0.75) = 0.367879 − 0.413738 100% = 12.778801 εt = 0.42% 0.358978 2 6 0.75.778801 − 0.778801(0.367879 − 0.367879 and the step size is h = xi+1 – xi = 1 – 0.778801 εt = 0.778801 − 0.5×102–2 = 0.367879 − 0.25 = 0. The true value = cos(π/4) = 0.75) + 0.75 2 0.367879 4.778801 − 0.4 Use εs = 0.778801 εt = 0.778801(0.75 3 − 0.1947 100% = 47.25 = 0.358978 100% = 2.75) + 0. (b) The true value is e–1 = 0.5%.

691575 second-order: (π / 4) 4 ⎛π ⎞ cos⎜ ⎟ ≅ 0.5%.707429 − 720 ⎝4⎠ εt = 0. The true value = sin(π/4) = 0.5%.691575 100% = 2.707103 100% = 0.707107 first-order: (π / 4) 2 ⎛π ⎞ cos⎜ ⎟ ≅ 1 − = 0.707429 100% = 0.5 Use εs = 0.707107 εa = 0.691575 100% = 2.707429 − 0.707107… zero-order: 24 .42% 0.0005% 0.24% 0.707107 εa = 0.456% 0.6% 0.691575 − 1 100% = 44. we can terminate the computation.707107 − 0.707429 24 ⎝4⎠ εt = 0.707103 Because εa < 0.707429 100% = 0.707103 − 0.707107 − 0.5×102–2 = 0.19% 0.691575 + = 0.046% 0.691575 2 ⎝4⎠ εt = 0.⎛π ⎞ cos⎜ ⎟ ≅ 1 ⎝4⎠ εt = 0.707429 third-order: (π / 4) 6 ⎛π ⎞ = 0.707107 εa = 0.707107 − 0.707107 − 1 100% = 41.707103 cos⎜ ⎟ ≅ 0. 4.

704653 100% = 0. we can terminate the computation.704653 − 0.707107 εa = 0.704653 sin ⎜ ⎟ ≅ 0.707143 sin ⎜ ⎟ ≅ 0.704653 + 120 ⎝4⎠ εt = 0. 4.1% 0.347% 0.5%.707107 − 0.785398 − 6 ⎝4⎠ εt = 0.707143 Because εa < 0.707143 100% = 0.707107 first-order: (π / 4) 3 ⎛π ⎞ = 0.⎛π ⎞ sin ⎜ ⎟ ≅ 0.46% 0. zero order: f ( 2) = f (1) = −62 εt = 102 − (−62) 100% = 160.704653 second-order: (π / 4) 5 ⎛π ⎞ = 0.707143 − 0.704653 100% = 0.785398 100% = 11.6 The true value is f(2) = 102.707107 εa = 0.352% 0.8% 102 first order: f ' (1) = 75(1) 2 − 12(1) + 7 = 70 f ( 2) = −62 + 70(1) = 8 εt = 102 − 8 100% = 92.785398 ⎝4⎠ εt = 0.1% 102 second order: 25 .707107 − 0.785398 100% = 11.707107 − 0.0051% 0.

4.7% 1.66667 100% = 142.098612 − 2.66667 6 εt = 1. This is due to the fact that cubics have zero fourth and higher derivatives.098612 first order: f ' ( x) = 1 x f ' (1) = 1 f (3) = 0 + 1(2) = 2 εt = 1.5% 102 εt = third order: f ( 3) (1) = 150 f ( 2) = 77 + 150 3 (1) = 102 6 εt = 102 − 102 100% = 0.05% 1. the error is zero.098612 fourth order: 26 .098612 − 0 100% = 100% 1.098612 zero order: εt = f (3) = f (1) = 0 1.098612 − 0 100% = 100% 1.098612 εt = 1.f " (1) = 150(1) − 12 = 138 138 2 (1) = 77 2 f ( 2) = 8 + 102 − 77 100% = 24.7 The true value is ln(3) = 1.098612 second order: f " ( x) = − 1 x2 f (3) = 2 − 1 f " (1) = −1 22 =0 2 third order: f ( 3) ( x) = 2 x3 f (3) = 0 + 2 f " (1) = 2 23 = 2.098612 − 2 100% = 82.0% 102 Because we are working with a third-order polynomial.

85938 f(xi) = 102 f(xi+1) = 182. 27 .85938 = 284.1406 − 39.5625 backward: f ' ( 2) = 102 − 39.1406 forward: f ' ( 2) = 182.5625 0 . Et ≈ 288 0.4375 centered: f ' ( 2) = 182.f ( 4) ( x) = − 6 x4 f (3) = 2.25 = 36 2 which is similar in magnitude to the computed errors.8 The first derivative of the function at x = 2 can be evaluated as f ' (2) = 75(2) 2 − 12(2) + 7 = 283 The points needed to form the finite divided differences can be computed as xi–1 = 1.33333 24 εt = 1.1406 − 102 = 320.75 xi = 2.5625 E t = 283 − 284.5625 0.5625 = 37.85938 = 248.25 f(xi–1) = 39.5625 0.33333) 100% = 221. 4.5625 = −1. A smaller step size is required to obtain convergence.5 Both the forward and backward differences should have errors approximately equal to Et ≈ f " ( xi ) h 2 The second derivative can be evaluated as f " (2) = 150(2) − 12 = 288 Therefore.4% 1.098612 The series is diverging.5625 = 34.0 xi+1 = 2.098612 − (−1.25 E t = 283 − 248.66666 − 6 f ( 4) (1) = −6 24 = −1.25 E t = 283 − 320.

765 − 2(102) + 75.11111… zero-order: 1 ≅1 1 − 0. Et ≈ − f ( 3) ( xi ) 2 h 6 The third derivative of the function is 150 and Et ≈ − 150 (0. This occurs because the underlying function is a cubic equation that has zero fourth and higher derivatives.1 εt = 1. The true value = 1/(1 – 0.10 Use εs = 0.5%. f " ( 2) = 164.1 = 1 . 4.56 − 2(102) + 50.5×102–2 = 0. f " ( 2) = 131.1 1 − 0.11111 − 1 100% = 10% 1.1.For the central difference.1) = 1.115 = 288 (0.9 The second derivative of the function at x = 2 can be evaluated as f ' (2) = 150( 2) − 12 = 288 For h = 0.1) 2 Both are exact because the errors are a function of fourth and higher derivatives which are zero for a 3rd-order polynomial.25) 2 = −1. 4.2) 2 For h = 0.5625 6 which is exact.2.1 28 .11111 first-order: 1 ≅ 1 + 0 .96 = 288 (0.

11 100% = 0.11111 εa = 1.0909% 1 .1 second-order: 1 ≅ 1 + 0.090009% 1.111 − 1.1 + 0.1 100% = 1% 1.εt = 1.11111 − 1.111 1 − 0.11111 − 1. 4.11 − 1.1 − 1 100% = 9.11111 εa = 1.1 εt = 1.111 The approximate error has fallen below 0.11111 εa = 1 .11 third-order: 1 ≅ 1 + 0.01 = 1.001 = 1.1% 1.01 + 0.1 100% = 0.111 100% = 0.11 Here are the function and its derivatives f ( x) = x − 1 − f ' ( x) = 1 − f " ( x) = f ( 3) f ( 4) 1 sin x 2 1 cos x 2 1 sin x 2 ( x) = 1 cos x 2 1 ( x) = − sin x 2 29 .1 εt = 1.1 + 0.9009% 1.11 100% = 0.11111 − 1.01% 1.5% so the computation can be terminated.11 1 − 0.

2).2 -1 0 0 1 2 3 4 2nd/3rd Order Taylor Series Error 0.5. f2. 3rd.^2). f4=x-1.Using the Taylor Series expansion.2. we obtain the following 1st.5*pi). and 4th order Taylor Series functions shown below in the MATLAB program−f1. plot(x.title('1st Order Taylor Series Error').25.grid.e1).25.title('f(x)=x-1-0.5+0.4). e2=abs(f-f2).2.4 0 0.01 0.e4).1 0.2.f). and f4. subplot(2.*((x-0.005 0. 2nd.grid. Note the 2nd and 3rd order Taylor Series functions are the same. From the plots below.2.2 0 1 2 3 4 4th Order Taylor Series Error 0.015 0.5*pi).3).15 0. e4=abs(f4-f).^4).grid.5*sin(x) 1st Order Taylor Series Error 3 0.05 0 0 0 1 2 3 4 30 0 1 2 3 4 .e2). subplot(2.8 2 0. we see that the answer is the 4th Order Taylor Series expansion.5+0. plot(x. e1=abs(f-f1).1).001:3.title('2nd/3rd Order Taylor Series Error').5*sin(x). plot(x. subplot(2. %Calculates the absolute value of the difference/error subplot(2.*((x-0.6 1 0. x=0:0.5*sin(x)').2. plot(x. f2=x-1.hold on f1=x-1.hold off f(x)=x-1-0.^2)-(1/48)*((x-0.title('4th Order Taylor Series Error').grid. f=x-1-0.5*pi).

078 4.563 2.500 1.500 -9.500 0.313 1.625 4.688 5.500 -6.859 4.000 8.813 3.250 0.5 -2.250 8.000 -4.000 2.5 2.063 8.547 5.250 0.563 4.484 -1.000 3.000 3.813 3.750 -0.813 -1.078 4.0 0.000 1.000 -7.813 4.313 -0.000 0.563 10.0 Theoretical Backward Centered Forward f'(x) 6.875 4.000 -0.500 f''(x).891 0.141 3.000 -10.453 4.484 4.500 -3.547 5.000 -1.125 2.141 3.922 f''(x)Theory -12.750 1.922 3.938 -1.000 3.063 11.000 5.000 1.750 1.000 5.500 3.625 7.000 2.875 4.000 f(x) 0.500 0.000 f(x+1) 2.750 -1.813 -1.625 4.922 3.875 4.250 0.0 2.0 2.547 5.000 5.563 10.813 -1.0 10.547 5.875 4.188 -0.000 .000 -4.313 0.938 8.500 -6.5 1.813 1.12 x -2.000 0.563 3.000 2.563 10.000 7.500 -9.250 5.500 -4.813 5.000 2.859 8.5 -1.188 8.484 4.078 4.750 -0.250 0.141 10.0 -1.750 -1.859 f(x+1) f'(x)-Theory f'(x)-Back f'(x)-Cent f'(x)-Forw 2.000 -4.484 4.078 4.938 3.516 3.250 1.078 4.922 -1.891 10.5 0.938 7.500 -3.875 4.484 4.547 5.375 5.000 f(x-1) -2.813 5.625 -2.500 -9.500 0.375 5.000 11.000 0.750 2.000 -3.563 -1.813 2.563 7.000 -1.891 0.500 -10.891 0.875 4.000 5.484 31 3.484 4.000 5.000 2.0 -4.563 First Derivative Approximations Compared to Theoretical 14.000 -1.250 -1.125 2.500 f''(x)Forw -10.063 1.188 -1.000 -12.500 -1.547 4.453 1.000 -7.688 5.500 -3.0 1.0 -2.500 0.141 3.625 4.000 5.000 -7.500 -12.000 -1.516 3.000 2.000 -0.500 -6.000 1.5 -2.000 3.000 -1.516 -2.063 0.250 -1.875 4.000 3.000 1.250 f(x) 0.000 -1.141 3.000 -1.500 -1.516 3.250 -1.000 3.000 1.125 f(x-2) f(x+2) 3.078 4.938 4.547 5.250 -0.938 3.547 5.750 -1.0 0.875 -0.4.625 4.313 3.0 12.625 4.750 3.0 8.750 5.563 -1.813 4.000 -6.938 -1.078 1.750 -1.938 4.125 2.313 -0.375 2.141 3.000 0.500 -0.500 -1.0 -0.813 -0.000 -10.188 5.625 4.f''(x)-Cent Back 150.000 5.0 x-values x -2.500 -7.125 -1.0 4.078 4.141 3.516 3.625 4.250 -0.750 3.000 3.484 4.938 -1.500 -0.313 4.688 4.516 f(x-1) -2.453 4.000 -9.688 3.688 2.000 -0.688 1.

453 4.500 1.750 1.2204e-016 32 0.2204e-016 >> eps ans = 2.250 1.000 3.000 3.500 9.000 13.859 8.625 3. end eps = 2*e.375 5.000 3.000 3.0 0.500 3.5 -1.859 8.375 5.000 10.5 f''(x)-Theory f''(x)-Backward f''(x)-Centered f''(x)-Forward 4.000 7.500 9.922 3.750 2.500 6.0 -1.0 10.000 3.125 2.453 4.922 3.000 1.516 3.453 4.375 3.000 3. while e+1>1 e = e/2.500 12.125 2.13 function eps = macheps % determines the machine epsilon e = 1.000 4.500 9.000 4.5 0.500 6.000 7.516 3.0 1.0 -10.0 -5.500 6.500 .000 10.0.859 2.000 4.000 10.375 5.5 -2.453 4.5 1.500 12.500 0.0 -0.500 3.922 3.000 Approximations of the 2nd Derivative 15.0 x-values 4.500 12.000 3.891 4.000 7.922 3.500 6. >> macheps ans = 2.500 9.125 2.0 -2.000 7.0 2.000 3.5 2.0 f''(x) 5.0 -15.891 14.000 1.000 10.375 5.453 4.000 10.000 10.859 8.

01058 xr 0.860291(0.02199 |εa| 20.1 + 0.05464 0.140625 0.81c d 9.125 f (0.86029 0.2 0.20452 −0.1390625 with an approximate error of 1.15 0. 5. after six iterations.12% Thus. the root is in the first interval and the upper guess is redefined as xu = 0.20452 −0.xl.140625 f(xu) −1.15 2 f (0.125 0.20452 −0.1375 f(xl) 0.273923 Therefore.1375 0.204516) = −0.01058 0.07551 −0.05464 xu 0.xu.1 The function to evaluate is f (c d ) = ⎛ gc d ⎞ gm tanh⎜ t ⎟ − v(t ) ⎜ m ⎟ cd ⎝ ⎠ or substituting the given values f (c d ) = ⎛ 9.15.15 0.12%.81(80) tanh⎜ ⎜ 80 cd ⎝ ⎞ 4 ⎟ − 36 ⎟ ⎠ The first iteration is xr = 0 .15 100% = 20% 0. The remainder of the iterations are displayed in the following table: i 1 2 3 4 5 6 xl 0.15 0.15) = 0. the root is in the second interval and the lower guess is redefined as xu = 0.1) f (0.14375 0.860291(−0.15 = 0.22% 1.1 0.35% 2.125 0.31841 0.xu.175944 Therefore.maxit): 33 .15 0.86029 0.1375 0.20452 0.07551 −0.05464 −0.1 + 0 .Ead) % bisectnew(xl.00% 9.2 = 0.19738 −0.31841 0.09% 4.125 − 0.14375 0.125) = 0.05464 0.2 function root = bisectnew(func.318407) = 0.CHAPTER 5 5. we obtain a root estimate of 0.1) f (0.125 2 εa = 0. The second iteration is xr = 0.1390625 f(xr) −0.1 0.es.125.1375 0.

if xr ~= 0.81*80/cd)*tanh(sqrt(9. elseif test > 0 xl = xr. Ead = 0.1 with Ea. end %if Ead blank set to 0.'cd') fcd = Inline function: fcd(cd) = sqrt(9. assign default values if nargin<4.81*80/cd)*tanh(sqrt(9.3 The function to evaluate is f (c d ) = ⎛ 9. 5.81c d 9.5).0.81*cd/80)*4)-36'.d = 0. end test = func(xl)*func(xr).14008789062500 5. xr = (xl + xu)/2.0001. xu = lower and upper guesses % Ead = (optional) desired tolerance (default = 0.0. end end root = xr.xl)/Ead) + 0.81*cd/80)*4)-36 >> format long >> bisectnew(fcd. else ea = 0. >> fcd = inline('sqrt(9.2.xrold)/xr) * 100.000001) % output: % root = real root if func(xl)*func(xu)>0 %if guesses do not bracket a sign change error('no bracket') %display an error message and terminate end % if necessary.% uses bisection method to find the root of a function % with a fixed number of iterations to attain % a prespecified tolerance % input: % func = name of function % xl. for i = 1:n xrold = xr.1.81(80) tanh ⎜ ⎜ 80 cd ⎝ ⎞ 4 ⎟ − 36 ⎟ ⎠ 34 . if test < 0 xu = xr.0.000001 % bisection xr = xl. ea = abs((xr .000001. % compute n and round up to next highest integer n = round(1 + log2((xu .0001) ans = 0. The following is a MATLAB session that uses the function to solve Prob.

19738(0. ea = abs((xr . after only two iterations we obtain a root estimate of 0. xr = xu .030292 Therefore. maxit=50.maxit): % uses the false position method to find the root % of the function func % input: % func = name of function % xl.es.func(xu)).4 function root = falsepos(func.141809) = 0. end test = func(xl)*func(xr). the root is in the first interval and the upper guess is redefined as xu = 0. xu = lower and upper guesses % es = (optional) stopping criterion (%) (default = 0.17% 0.17% which is below the stopping criterion of 2%.2) = 0.1 − 0.140165 − 0. The second iteration is x r = 0.es. 5.xl.xu)/(func(xl) .140165 0. elseif test > 0 xl = xr.141809.140165 with an approximate error of 1.1) f (0.xrold)/xr) * 100.func(xu)*(xl . else ea = 0.2 − − 1.xu.141809 100% = 1.The first iteration is x r = 0.001) % maxit = (optional) maximum allowable iterations (default = 50) % output: % root = real root if func(xl)*func(xu)>0 %if guesses do not bracket a sign change error('no bracket') %display an error message and terminate end % default values if nargin<5.141809) = 0.19738) f (0.141809 − εa = − 0.860291( −0.03521) = −0.141809 0.03521(0. end % false position iter = 0.maxit) % falsepos(xl.03521) 0.140165 Therefore. 35 . while (1) xrold = xr. iter = iter + 1. end if nargin<4. xr = xl.xu.1 − 0.001.86029 − (−0.86029 − (−1. if xr ~= 0. es=0. if test < 0 xu = xr.

14016503741282 5. Write beam equations: 0<x<3 x − 265 x = 0 3 M = 265 − 5.0.end if ea <= es | iter >= maxit.81*cd/80)*4)-36'. xU = 10 36 . end end root = xr. The following is a MATLAB session that uses the function to solve Prob.55 x 3 M + (16.2) ans = 0.1. 5. break.81*80/cd)*tanh(sqrt(9.5 Solve for the reactions: R1 = 265 lbs.667 x 2 ) (1) 3<x<6 2 x−3 ) + 150( x − (3)) − 265 x = 0 2 3 2 (2) M = −50 x + 415 x − 150 6<x<10 2 M = 150( x − (3)) + 300( x − 4. (3) M = −185 x + 1650 Set x L = 6.81*80/cd)*tanh(sqrt(9.81*cd/80)*4)-36 >> format long >> falsepos(fcd.'cd') fcd = Inline function: fcd(cd) = sqrt(9. use (3). R2 = 285 lbs.2.1: >> fcd = inline('sqrt(9.5) − 265 x 3 (3) M = −185 x + 1650 10<x<12 M + 100( x − 3)( M + 100(12 − x) = 0 (4) M = 100 x − 1200 Combining Equations: Because the curve crosses the axis between 6 and 10.0.

6 (a) The graph can be generated with MATLAB >> x=[-1:0. 37 . x = 8.5 → replaces x L M ( x L ) = 77.75 M ( xU ) = −15 2 M ( x R ) = 31.5 2 M ( xU ) = −200 M ( x R ) = 170 → replaces x L M ( x L ) = 170 M ( xU ) = −200 M ( x R ) = −15 → replaces xU M ( x L ) = 170 M ( xU ) = −15 M ( x R ) = 77.875 + 8.91 feet 5.546875 xr = xr = 8.875 M ( xU ) = −15 2 M ( x R ) = 8.9375 = 8.921875 = 8.4375 2 M ( x R ) = −0.8984 Therefore.90625 + 8.125 xr = 8.75 + 9 = 8.M ( x L ) = 540 xr = x L + xU =8 2 xr = 8 + 10 =9 2 xr = 8+9 = 8.125 → replaces x L M ( x L ) = 8.5 8.9375 M ( xU ) = −15 2 M ( x R ) = −3.5 + 9 = 8.4375 2 M ( x R ) = 2.25 → replaces x L M ( x L ) = 31.125 xr = 8.9140625 2 M ( x R ) = 0.34375 M ( xU ) = −0.34375 xr = 8.25 xr = 8.90625 + 8.921875 M ( xU ) = −3.875 + 9 = 8.9375 = 8.34375 → replaces x L M ( x L ) = 2.4375 → replaces xU M ( x L ) = 8.90625 M ( xU ) = −3.546875 → replaces xU M ( x L ) = 2.1:6].

>> f=-12-21*x+18*x.^2-2.75*x.^3;
>> plot(x,f)
>> grid

This plot indicates that roots are located at about –0.4, 2.25 and 4.7.
(b) Using bisection, the first iteration is

xr =

−1+ 0
= −0.5
2

f ( −1) f (−0.5) = 29.75(3.34375) = 99.47656
Therefore, the root is in the second interval and the lower guess is redefined as xl = –0.5. The
second iteration is
xr =

− 0.5 + 0
= −0.25
2

εa =

− 0.25 − ( −0.5)
100% = 100%
− 0.25

f ( −0.5) f (−0.25) = 3.34375(−5.5820313) = −18.66492
Therefore, the root is in the first interval and the upper guess is redefined as xu = –0.25. The
remainder of the iterations are displayed in the following table:
i
1
2
3

xl
−1
−0.5
−0.5

f(xl)
29.75
3.34375
3.34375

xu
0
0
−0.25

f(xu)
−12
−12
−5.5820313

38

xr
−0.5
−0.25
−0.375

f(xr)
3.34375
−5.5820313
−1.4487305

|εa|
100.00%
33.33%

−0.5
−0.4375
−0.4375
−0.42188
−0.42188

4
5
6
7
8

3.34375
0.863098
0.863098
0.269471
0.269471

−0.375
−0.375
−0.40625
−0.40625
−0.41406

−1.4487305
−1.4487305
−0.3136673
−0.3136673
−0.0234052

−0.4375
−0.40625
−0.421875
−0.414063
−0.417969

0.8630981
−0.3136673
0.2694712
−0.0234052
0.1227057

14.29%
7.69%
3.70%
1.89%
0.93%

Thus, after eight iterations, we obtain a root estimate of −0.417969 with an approximate error
of 0.93%, which is below the stopping criterion of 1%.
(c) Using false position, the first iteration is

xr = 0 −

− 12(−1 − 0)
= −0.287425
29.75 − (−12)

f ( −1) f (−0.287425) = 29.75(−4.4117349) = −131.2491
Therefore, the root is in the first interval and the upper guess is redefined as xu = –0.287425.
The second iteration is
x r = −0.287425 −

εa =

− 4.4117349(−1 − (−0.287425))
= −0.3794489
29.75 − (−4.4117349)

− 0.3794489 − (−0.2874251)
100% = 24.25%
− 0.3794489

f ( −1) f (−0.3794489) = 29.75(−1.2896639) = −38.3675
Therefore, the root is in the first interval and the upper guess is redefined as xu = –0.379449.
The remainder of the iterations are displayed in the following table:
i
1
2
3
4
5

xl
−1
−1
−1
−1
−1

f(xl)
29.75
29.75
29.75
29.75
29.75

xu
0
−0.28743
−0.37945
−0.40523
−0.41217

f(xu)
−12
−4.4117349
−1.2896639
−0.3512929
−0.0938358

xr
−0.287425
−0.379449
−0.405232
−0.412173
−0.414022

f(xr)
−4.4117349
−1.2896639
−0.3512929
−0.0938358
−0.0249338

|εa|
24.25%
6.36%
1.68%
0.45%

Therefore, after five iterations we obtain a root estimate of –0.414022 with an approximate
error of 0.45%, which is below the stopping criterion of 1%.
5.7 A graph of the function can be generated with MATLAB
>>
>>
>>
>>

x=[-0.5:0.1:1.5];
f=sin(x)-x.^2;
plot(x,f)
grid

39

This plot indicates that a nontrivial root (i.e., nonzero) is located at about 0.85.
Using bisection, the first iteration is
xr =

0 .5 + 1
= 0.75
2

f (0.5) f (0.75) = 0.229426(0.1191388) = 0.027333
Therefore, the root is in the second interval and the lower guess is redefined as xl = 0.75. The
second iteration is
xr =

0.75 + 1
= 0.875
2

εa =

0.875 − 0.75
100% = 14.29%
0.875

f (0.75) f (0.875) = 0.119139(0.0019185) = 0.000229
Because the product is positive, the root is in the second interval and the lower guess is
redefined as xl = 0.875. The remainder of the iterations are displayed in the following table:
i
1
2
3
4
5

xl
0.5
0.75
0.875
0.875
0.875

f(xl)
0.229426
0.119139
0.001919
0.001919
0.001919

xu
1
1
1
0.9375
0.90625

f(xu)
−0.158529
−0.158529
−0.158529
−0.0728251
−0.0340924

40

xr
0.75
0.875
0.9375
0.90625
0.890625

f(xr)
0.1191388
0.0019185
−0.0728251
−0.0340924
−0.0157479

|εa|
14.29%
6.67%
3.45%
1.75%

Therefore, after five iterations we obtain a root estimate of 0.890625 with an approximate
error of 1.75%, which is below the stopping criterion of 2%.
5.8 (a) A graph of the function indicates a positive real root at approximately x = 1.4.
2
0
-3

-2

-1

0

1

2

3

-2
-4
-6
-8
-10
-12

(b) Using bisection, the first iteration is

xr =

0 .5 + 2
= 1.25
2

f (0.5) f (1.25) = −2.08629(−0.2537129) = 0.52932
Therefore, the root is in the second interval and the lower guess is redefined as xl = 1.25. The
second iteration is
xr =

1.25 + 2
= 1.625
2

εa =

1.625 − 1.25
100% = 23.08%
1.625

f (1.25) f (1.625) = −0.253713(0.2710156) = −0.06876
Therefore, the root is in the first interval and the upper guess is redefined as xu = 1.625. The
remainder of the iterations are displayed in the following table:
i
1
2
3

xl
0.5
1.25
1.25

f(xl)
−2.08629
−0.25371
−0.25371

xu
2
2
1.625

f(xu)
0.6862944
0.6862944
0.2710156

41

xr
1.25
1.625
1.4375

f(xr)
−0.2537129
0.2710156
0.025811

|εa|
23.08%
13.04%

(c) Using false position.086294(0.9 (a) Equation (5.04%.628707 1.15.086294 − 0.086294 − 0.5 f(xl) −2.15.2755734 0.6287074 1.05 ⎠ ⎠ which can be rounded up to 11 iterations.4483985 f(xr) 0.4483985 with an approximate error of 3. after three iterations we obtain a root estimate of 1.45121 ⎟ ⎝ 0.5 − 2) = 1. the root is in the first interval and the upper guess is redefined as xu = 1.628707 − 2.5 0.086294(0.223119 Therefore. the first iteration is xr = 2 − 0.80% 3.040917 |εa| 8.4970143(0.1069453) = −0.6862944(0.osf)>0 %if guesses do not bracket error('no bracket') %display an error message and terminate 42 .2755734 0.08629 −2.628707. The remainder of the iterations are displayed in the following table: i 1 2 3 xl 0.6862944 0.4970143 − 2.Thus.4970143 − 1.4375 with an approximate error of 13.628707) = −2. the root is in the first interval and the upper guess is redefined as xu = 1. xu = 35 + 273.5 − 1.6287074 100% = 8.628707) = 1.5 0.574927 Therefore. 5.497014 f(xu) 0.d ⎞ ⎟ = 1 + log 2 ⎛⎜ 35 ⎞⎟ = 10.4970143 1. after three iterations.1069453 xr 1. (b) Here is an M-file that evaluates the temperature in oC using 11 iterations of bisection based on a given value of the oxygen saturation concentration in freshwater: function TC = TempEval(osf) % function to evaluate the temperature in degrees C based % on the oxygen saturation concentration in freshwater (osf).2755734 1.8% 1.497014. xl = 0 + 273.2755734) = −0. The second iteration is x r = 0. if fTa(xl.6862944 f (0.36% Therefore.36%.6) can be used to determine the number of iterations ⎛ ∆x 0 n = 1 + log 2 ⎜ ⎜E ⎝ a.08629 xu 2 1. we obtain a root estimate of 1.4970143 f (0.osf)*fTa(xu.2755734 − εa = 1.08629 −2.4970143) = −2.5) f (1.1069453 0.5) f (1.

The function can be used to evaluate the test cases: >> TempEval(8) ans = 26. if test < 0 xu = xr.5552 5.2438e10/Ta^3 .15.osf).6. end function f = fTa(Ta. else ea = 0.81(3 y + y 2 / 2) 3 A graph of the function indicates a positive real root at approximately 1. ea = abs((xr . f = f + 1.7798 >> TempEval(10) ans = 15.5.xrold)/xr) * 100. xr = (xl + xu)/2.575701e5/Ta .3979 >> TempEval(14) ans = 1.621949e11/Ta^4.34411 + 1. for i = 1:11 xrold = xr.642308e7/Ta^2.log(osf).osf)*fTa(xr.end xr = xl. osf) f = -139. 43 . end test = fTa(xl.8. elseif test > 0 xl = xr. f = f .273. if xr ~= 0.10 (a) The function to be evaluated is f ( y) = 1 − 400 (3 + y ) 9. end end TC = xr .

03095 −0.03% 0.601809) = −0.625 1.097956 0.5078125 f(xr) −0.378909 0.03095 −0.5 2. The remainder of the iterations are displayed in the following table: i 1 2 3 4 5 6 7 8 xl 0.52% .515625 1.75 1.5) = −32.5 1.5 1.5 1.69% 4.10 0 0 0. the root is in the first interval and the upper guess is redefined as xu = 2.5) f (2) = −0.03095 −0.5 2 1.5 2 f (0.018624 Therefore.03095 −0.813032 0.097956 0.998263 Therefore.5 1.75 1.29% 7.5625 1.036261 0.625 1.5 100% = 25% 2 f (1.5) f (1.206927 0.5 + 2 .5 = 1 .030946(0.5 1.2582( −0.378909 0.5 -10 -20 -30 -40 (b) Using bisection.53125 1.2582 −0.5 2 2.5 2 1.03095 −0.5 f(xl) −32.00% 14. the first iteration is xr = 0 .5625 1.030946 0.003383 44 xr 1. The second iteration is xr = 1 . the root is in the second interval and the lower guess is redefined as xl = 1.03095 −0.013595 |εa| 25.813032 0.5 + 2 .030946) = 0.601809 0.515625 f(xu) 0.003383 −0.04% 1.5 1 1.601809 0.036261 0.00% 2.206927 0.03095 xu 2.5 =2 2 εa = 2 − 1.5.5 1.53125 1.5 1.

5078125 with an approximate error of 0.5 − 0. Discussion: This is a classic example of a case where false position performs poorly and is inferior to bisection.5 0.96% 2.23347 2.77179 0.2582 −32.12404 f(xu) 0.19534 2.2582 − 0.96% 1. the first iteration is x r = 2.5 − 2.5 0. the opposite is true.79987) = −25.31492 2.31492 2.5 0.2582 −32. the root is in the first interval and the upper guess is redefined as xu = 2. if f(xu) is much closer to zero than f(xl).27331 2.5 0.50000 2.5 that we detected graphically.2582 −32.25821(0.40363 2.92% 1.2582 −32.70900 0.78612) = −25.2582 −32.2582 −32.78612 0.81303 f (0. we obtain a root estimate of 1.45083 − 32.45083) = −32.79987 0.5 0.83% 1. The remainder of the iterations are displayed in the following table: i 1 2 3 4 5 6 7 8 9 10 xl 0.45083 100% = 1.5 f(xl) −32.15888 2.09077 with an approximate error of 1.2582 −32.52%.65693 |εa| 1.40363) = −32.After eight iterations.5) f (2. (c) Using false position.74% 1.35893 The root is in the first interval and the upper guess is redefined as xu = 2.40363 − 2.79987 0.09077 f(xr) 0.27331 2.69% 1.45083 − εa = 0.2582 −32.19534 2.5 0. This function violates the premise upon which false position was based−that is.45083) = 2.64% 1.2582 xu 2.40363 − 32.59% After ten iterations we obtain a root estimate of 2.81303(0.72547 0. the false position method is converging at a very slow pace and is still far from the root in the vicinity of 1.45083 2.74145 0.74145 0.69206 0.45083 2.25821 − 0.12404 2.5 − 2.72547 0.23347 2.80248 Therefore. Thus. Insight into these results can be gained by examining the plot that was developed in part (a).70900 0.75689 0.67469 xr 2.78612 0. then the root is closer to xu than to xl (recall Fig.2582 −32.15888 2.8). 45 .67469 0.35834 2.5 0. 5.75689 0. after ten iterations.5 0. Because of the shape of the present function. The second iteration is x r = 2.79987 2.5) = 2.40363 2.2582(0.45083.35834 2.78% 1.5 0.40363.81303 0.69206 0.5) f (2.59%.40363 f (0.77179 0.79987(0.88% 1.

649637 × 100% = 9.0097%.768532 0. the first iteration yields ( ) x1 = sin 0.649637 Second iteration: ( ) x 2 = sin 0. it can be solved for the linear x. the root is estimated to be 0.0097% Thus.721524 εa = 0.500000 0.768606 |εa| 23.96% 0. the first iteration yields 46 . after nine iterations.1 The function can be set up for fixed-point iteration by solving it for x xi +1 = sin (x) i Using an initial guess of x0 = 0.766248 0.649637 − 0.721524 The process can be continued as tabulated below: iteration 0 1 2 3 4 5 6 7 8 9 xi 0.1984% 0. 6.2 (a) The function can be set up for fixed-point iteration by solving it for x in two different ways.9123% 1.5.649637 εa = 0.5 1 .750901 0.768329 0.CHAPTER 6 6.0339% 9.7 Using an initial guess of 5.721524 0.762097 0.649637 0.649637 = 0. x i +1 = 0.5 = 0.5 × 100% = 23% 0.9 x i2 − 2.767772 0.768606 with an approximate error of 0.0265% 0. First.9632% 3.4691% 0.5418% 0.0725% 0.721524 − 0.

5% 11.x1 = 0.76) 2 − 2.76 1.496 × 100% = 14.5415% 0.0629 This version is converging.5 0.14% 3. this solution is diverging.881882 2.0% 3.5 = 3.867287 |εa| 43.5090% 47 .7(5) + 2.926306 2. x i +1 = 1.9 3.5 = 3.5 = 11.496029 3.6% 71.76 − 5 × 100% = 57.0629 0.7 εa = 11.9 3.0629 − 3.000000 3.8 − 11.6680% 1.8 Clearly.5 = 71.1410% 4. An alternative is to solve for the second-order x.7(3.496 0 .76 × 100% = 83.7 εa = 71. the first iteration yields x i +1 = εa = 1.8 1 .496 − 5 × 100% = 43. All the iterations can be tabulated as iteration 0 1 2 3 4 5 xi 5.9(5) 2 − 2.76 Second iteration: x1 = 0.062905 2.7 xi + 2.496 Second iteration: x i +1 = εa = 1.0194% 14.9 Using an initial guess of 5.496) + 2.9(11.

424658) 2 + 1.924357 − 3.56384 −3.5 − 1.3 −4.8 xi + 1.7 2.9(5) 2 + 1.7 x i + 2. f ( 2.861147 2.860190) 2 + 1.9(2.6 7 8 9 2.9(2.0061%.860363 2.862475 2.8E−07 −7.44819 −3.860104) = −0. the root estimate is 2.2 × 10 −14 48 . the first iteration yields x i +1 = 5 − εa = − 0.000294 (b) The formula for Newton-Raphson is x i +1 = xi − − 0.9 xi2 + 1.5 = 3.2E−14 f'(xi) −7.924357 − 1.7(5) + 2.7 Using an initial guess of 5.0061% Thus.7(2.424658) + 1. after 9 iterations.1681% 0.5 = −0.5 = 2.7(3.860190) + 2.8(3.424658 − εa = − 0.45006 −3.924357 2.46438 −3.9(3.860887 2.860190 0.424658 Second iteration: x i +1 = 3.860190) = −0.44819 |εa| 46.1% 2. The result can be checked by substituting it back into the original function.0000% 17.00360 −9. f ( 2.7(2.424658) + 2.860104) 2 + 1.0183% 0.424658 − 5 × 100% = 46.860104 f(xi) −11.424658 − 1.8(5) + 1.7 3.424658 × 100% = 17.0% 3.2093% 0.1081% 2.860105 2.5 −2.0364% 0. The result can be checked by substituting it back into the original function.924357 The process can be continued as tabulated below: iteration 0 1 2 3 4 5 xi 5 3.0000% After 5 iterations.5 = −7.0000%.0555% 0.424658 2.23353 −0.22527 −0. the root estimate is 2.860190 with an approximate error of 0.860104 with an approximate error of 0.860104) + 2.

191304) 2 + 11(3.05.068699 3(3.191304) − 6.1 = 3.5) 2 + 11(3.9 and 3.191304 Second iteration: x 2 = 3.1 = 3.05.191304 − εa = (3.673% 3.5 × 100% = 9.y) grid Estimates are approximately 1.191304 − 3.5) + 11 3.1 3 x i2 − 12 xi + 11 Using an initial guess of 3.5) − 6.^2+11*x-6.3 (a) >> >> >> >> x = linspace(0.^3-6*x.068699 − 3.5) 2 − 12(3.191304 × 100% = 3. plot(x.5) 3 − 6(3.5 − εa = (3. y = x. (b) The formula for Newton-Raphson is x i +1 = x i − x i3 − 6 x i2 + 11xi − 6.995% 3.191304 3(3.191304) 3 − 6(3. the first iteration yields x1 = 3.5.6.068699 49 .191304) 2 − 12(3.4).191304) + 11 3.1. 1.

711111) = 2.Third iteration: x 3 = 3.475 f(x0) = 1.068699) 2 + 11(3.711111 − εa = f(x0) = 1.068699) 2 − 12(3.068699) 3 − 6(3.1 = 3.475 − 1.889% 3.31011(2.871091 − 2.221923 (d) For the modified secant method.702% 3.775 − (−0.775 f(x1) = −0.047317 3(3.45152) 2.871091 × 100% = 10.047317 − 3.871091 1.221923 − 0.5 − 3.871091 x 3 = 2. the first iteration: x0 = 3.068699) + 11 3.57 f(x0) = 1.068699 − εa = (3.068699 × 100% = 0.871091 Third iteration: x1 = 2.221923 − 2.711111 − 2.31011) 3.5 x1 = 2.5 x0 = 3.047317 (c) For the secant method.572% 2. the first iteration: f(x−1) = −0.31011 − 0.775 x−1 = 2.199893 50 .711111 − 3.098% 2.711111 Second iteration: x0 = 3.711111 x 2 = 2.775(2.5 x0 + δx0 = 3.711111 × 100% = 5.711111 − 0.871091) = 3.775 f(x0 + δx0) = 2.068699) − 6.45152 f(x2) = −0.775 2.45152 − (−0.5 − εa = 1.5 x1 = 3.871091 − εa = f(x1) = −0.5) = 2.5 − 2.45152(3.711111 x2 = 2.45152 − 0.5 × 100% = 29.

023% 3.207573 − εa = f(x1) = 0.02(3.082034 x2 + δx2 = 3.0000 -6.084809 f(x2 + δx2) = 0.02(3.199893 − 1.4).050812 0.775 3.082034 Third iteration: x2 = 3.207573 Second iteration: x1 = 3.*exp(-x)-1.252242 0.0544 6.082034 − 3.082034 × 100% = 1.143675 x 3 = 3.02(3.050812 (e) >> a = [1 -6 11 -6.y) grid 51 .1] a = 1. plot(x.453351 3.5)1.084809 = 3.0467 1.207573)0.207573 × 100% = 4.453351 = 3.082034)0.073% 3.0000 11.685016 − 0. y = 7*sin(x).207573 2.1000 >> roots(a) ans = 3.084809 3.453351 f(x1 + δx1) = 0.050812 − 3.0000 -6.5 − εa = 0.685016 0.117% 3.4 (a) >> >> >> >> x = linspace(0.775 = 3.271725 x 2 = 3.252242 − 0.082034 0.x1 = 3.207573 x1 + δx1 = 3.207573 − 3.082034 − εa = f(x2) = 0.8990 1.5 × 100% = 9.

3 − = 0.169409 − 0.00372 = 0.5.8% 0.169409 Third iteration: x1 = 0. the first iteration yields x1 = 0.144376) − sin(0.169409)e −0.776% 0.169409 − 1 − 0.169409 − 7 sin(0.532487 = 0 .169409) − sin(0.144376 5.169409)) 52 .124168 7e (cos(0.421627 7e (cos(0.169409 4.170179 − 0.144376 − εa = 7 sin(0.169409 − 0. (b) The formula for Newton-Raphson is x i +1 = x i − 7 sin( xi )e − xi − 1 7e − xi (cos( x i ) − sin( xi )) Using an initial guess of 3.3 3.144376 − = 0.3) − sin(0.3 × 100% = 107.144376)) 0.12827 = 0.144376 − 0.3 − 1 0.3)) 0.2.144376 Second iteration: x 2 = 0.144376)e −0.144376 × 100% = 14.3)e −0.144376 − 1 − 0.The lowest positive root seems to be at approximately 0.3 − εa = 7 sin(0.169409 − = 0.828278 7e (cos(0.144376 − 0.

542708 − 0.3 − 0.532487 0.3 × 100% = 108.119347 Second iteration: x0 = 0.3 x1 = 0.119347 x2 = 0.532487 0. the first iteration: x−1 = 0.143698 0.26032(0.170683 (d) For the modified secant method.119347) = 0.532487 − (−0.3 × 100% = 151.04047 0.453% 0.303 f(x0 + δx0) = 0.532487 f(x1) = −0.119347 0.4 x0 = 0.532487 x0 = 0.04047 0.532487(0.26032 − 0.8% 0.3 − εa = f(x−1) = 0.178664 Third iteration: x1 = 0.119347 × 100% = 33.119347 − 0.3 − εa = 0.542708 x1 = 0.04047(0.178664 − 0.3)0. the first iteration: f(x0) = 0.827244 − 0.170683 − 0.119347 − εa = f(x0) = 0.178664 × 100% = 4.4 − 0.143698 53 .26032 − 0.170179 − 0.3 x0 + δx0 = 0.119347 − 0.143698 − 0.178664 x 3 = 0.178664 − εa = f(x1) = −0.2% 0.68% 0.26032) 0.εa = 0.119347 x 2 = 0.827244 f(x0) = 0.532487 = 0.170179 (c) For the secant method.178664 0.532487 0.169409 × 100% = 0.3) = 0.178664) = 0.4% 0.26032 f(x2) = 0.170683 − 0.3 x1 = 0.01(0.

Second iteration: x1 = 0.5 f(x2) = −0.5825.300098 × 100% = 97.35 xi + 31.169412 Third iteration: x2 = 0.35 Using an initial guess of 0.02(0.143698)(−0.170181 − 0.0375 x i2 + 116.5825 × 100% = 74.00371) = 0.245468 90.169412)(−0.05 xi4 + 88.13175) 0.300098 − εa = − 21.2 x i3 + 266.170181 0.546 = 90.169412 − 0.00371 f(x2 + δx2) = 0.143698 − εa = f(x1) = −0.1466 2.169412 x2 + δx2 = 0.6875 5 x i4 − 64.075 xi + 116.07506 54 .02(0.18% 0.143698 x1 + δx1 = 0.675% 2.300098 − 0.07506 0.169412 × 100% = 0.169412 − εa = 6.25 xi2 − 384.300098 − 29.169412 − 0.75 x i3 − 192.143698 × 100% = 15.452% 0.00371) 0. the first iteration yields x1 = 0.13175) = 0.300098 Second iteration x1 = 2.145135 x 2 = 0.170181 (a) The formula for Newton-Raphson is x i +1 = x i − xi5 − 16.13175 f(x1 + δx1) = −0.004456 − (−0.5825 − εa = 50.12439 0.446% 90.171106 x 3 = 0.12439 − (−0.07506 − 2.06217 = 2.004456 0.

the first iteration: x0 = 0.06217 = 2.00952 9.777% 16.6 69164.601% 23.71520 58.94E+09 1.582500 2.36 6652.056% 0.743746 6.62E+09 5.030% 17.644695 0.193735 Second iteration: x1 = 2.15724 0.94 22415.446% 23.728% 10.05(2.245468 2.1668 286.447% 2.80590 11.2 212524.193735 − f(x1) = −21.580% 2.789% 0.637% 12.303422 x 2 = 2.2913 54.193735 49.554962 6.500017 6.851 1217.8912 163.48891 − 21.396 2292.193735 x1 + δx1 = 2.300098 90.675% 97.59 38502.54 7213.094% 19.95260 15.874% 23.585% 8.06217 2.3125 (b) For the modified secant method.06896 9.1969) 55 |εa| 74.246 710.06217 f(x0 + δx0) = 49.03 2810.41 15946.84E+08 1.731% 20.9363 164.406 187.9841 209.1969 f(x1 + δx1) = −21.5448 0.75349 26.597806 0.201% 5.987% 20.193735 − 0.5825)50. the result seems to be diverging.3E+08 1.15724 − 50.603832 8.5825 x0 + δx0 = 0.880% 0.1466 0.06217 −21.08487 21.546 4.16E+08 47720880 19552115 8012160 3284098 1346654 552546.Thus.519442 7.5825 × 100% = 73. the computation eventually settles down and converges (at a very slow rate) on a root at x = 6.5 f(xi) 50.05(0.503643 6.317% 14.00285 6.703943 7.000% .675 556. However.265% 22.852% 22.55998 17.58E−08 f'(xi) −29.08238 12. The iterations can be summarized as iteration 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 xi 0.346% 21.5825 − εa = f(x0) = 50.5448 − (−21.83059 47.32 163.1969) = −4.74E+08 56852563 18616305 6093455 1993247 651370.5.611625 x1 = 0.07506 72.193735)(−21.84927 31.120057 6.3 226941 93356.72701 38.

193 for the secant method.611625 2.5942 −0.maxit): % uses secant method to find the root of a function % input: % func = name of function % xrold.5 −7201. the Newton-Raphson results in a very high value (90.xr.es.05726 −2. whereas the modified false position goes in the opposite direction to a negative value (-4.462 −67. Thereafter.27038 −0.57 −906.21 −0.2 −0.968 −75.4E−06 f(xi+ δxi) 49.4163 −15.936% 2.46994 −0.94 −2452.maxit) % secant(func.6518 −3.08575 −2.4718 −12.49).39285 −0. The guess of 0.870% 40.82163 −0.865% 56. However.1969 −20727.806% 25.2 xi+δxi 0.039% 0.5448 −24323.524% 83.6 function root = secant(func.0002 −2. At these points the function is very flat and hence.579% 73.06217 −21.48891 − 2.06839 |εa| 73. the first iteration results in a prediction of 2.2147 −0.20447 −0.075).21008 −0.15724 −21. Therefore.0686 −2.398 −250.21 f(xi) 50.447% 148.5825 2.17563 −1.000% Explanation of results: The results are explained by looking at a plot of the function.487% 46. the result seems to be diverging.εa = − 4.91903 −0.xrold.48891 −3.2.28441 −1.48891 Again.01613 −0.xrold.355 −2.3 for Newton-Raphson and 2.87% − 4. 60 40 20 -2 0 -20 -40 2 Modified secant 4 6 8 Newton Raphson -60 6.46249 −0.86271 −0.19524 −2.196% 0.72 −808.25751 −0.xr.20008 −0.957 −277.es. The iterations can be summarized as iteration 0 1 2 3 4 5 6 7 8 9 10 11 12 xi 0.44756 −0.5825 is located at a point where the function is relatively flat.4 −2793.193735 × 100% = 148. the methods slowly converge on the nearest roots.303422 −4. the computation eventually settles down and converges on a root at x = −0.193735 −4. xr = initial guesses % es = (optional) stopping criterion (%) 56 .6 −8330.71336 −3.200% 69.

maxit=50.xr)/xrn) * 100.001. end if ea <= es | iter >= maxit. 6.xr. xr = xrn. end root = xrn.2. end end root = xr. end values %if maxit blank set to 50 %if es blank set to 0.xr.es. break. assign default values if nargin<5. end if ea <= es | iter >= maxit.delta.001 % Secant method iter = 0. end %if maxit blank set to 50 if nargin<4. delta=1E-5. maxit=50. iter = iter + 1.xrold.5. xr = xr .maxit) % secant(func. es=0. while (1) xrn = xr .xr)/(func(xrold) .1').delta*xr*func(xr)/(func(xr+delta*xr)-func(xr)).es. iter = iter + 1. end %if es blank set to 0.00001 % Secant method iter = 0.5) ans = 3. Test by solving Prob. while (1) xrold = xr. ea = abs((xr .0467 6. end if nargin<3. if xr ~= 0. break. 57 . if xrn ~= 0. end if nargin<4. es=0.% maxit = (optional) maximum allowable iterations % output: % root = real root % if necessary. end xrold = xr.func(xr)*(xrold .001 %if delta blank set to 0. ea = abs((xrn .maxit): % uses the modified secant method % to find the root of a function % input: % func = name of function % xr = initial guess % delta = perturbation fraction % es = (optional) stopping criterion (%) % maxit = (optional) maximum allowable iterations % output: % root = real root % if necessary.001.7 function root = modsec(func.3.func(xr)).xrold)/xr) * 100. assign default if nargin<5.3: >> secant(inline('x^3-6*x^2+11*x-6.

4795 f'(xi) 0.08 1121.742540 f(xi) −10.3.912 326. 6.8906 58 |εa| 86.1').3: >> modsec(inline('x^3-6*x^2+11*x-6. the derivative can be evaluated as df (m) = dm ⎛ gc d ⎞ 1 ⎞ cd g ⎟t + tanh ⎜ t⎟ ⎟ m2 ⎜ m ⎟2 ⎠ ⎝ ⎠ ⎛ gc d ⎞⎛ 1 m gm sech 2 ⎜ t ⎟⎜ − ⎜ m ⎟⎜ 2 c d g cd ⎝ ⎠⎝ cd g gm c d The two terms can be reordered df (m) 1 = dm 2 ⎛ gc d ⎞ 1 cd g t⎟ − tanh⎜ ⎜ m ⎟ 2 gm c d ⎝ ⎠ ⎛ gc d ⎞ gm m c d g t sech 2 ⎜ t⎟ 2 ⎜ m ⎟ cd cd g m ⎝ ⎠ The terms premultiplying the tanh and sech can be simplified to yield the final result df (m) 1 = dm 2 6.4375 12911.5. the iterations proceed as iteration 0 1 2 3 4 xi 4.5968 118.5 xi2 Using an initial guess of 4.9 ⎛ gc d ⎞ g ⎛ gc d ⎞ g t⎟ t⎟ − t sech 2 ⎜ tanh ⎜ ⎜ ⎟ ⎜ m ⎟ mc d m m 2 ⎝ ⎠ ⎝ ⎠ (a) The formula for Newton-Raphson is x i +1 = x i − − 2 + 6 xi − 4 xi2 + 0.609% 36.0467 6.5 586.333330 22.0.8 The equation to be differentiated is f ( m) = ⎛ gc d ⎞ gm t⎟ − v tanh⎜ ⎜ m ⎟ cd ⎝ ⎠ Note that d tanh u du = sech 2 u dx dx Therefore.57 3814.02) ans = 3.375 1315.5.5 x i3 6 − 8 xi + 1.082% 43.Test by solving Prob.469 262.014910 11.586% 40.518380 16.5 32.384% .

00265 23306693 10358532 4603793 2046132 909393.541252 2.007% Thus.325261 0.25 -1165.4504 -3.13 -2625.121% 0.474 0.5 100.114% 50. after an initial jump. the iterations proceed as iteration 0 1 2 3 4 5 ⋅ ⋅ ⋅ 21 22 23 24 25 |εa| 4.522% 0.43 -3939.171% 0.112% 50.683645 2. Thereafter.524% 22.188886 6.076% 50.000% xi This time the solution jumps to an extremely large negative value The computation eventually converges at a very slow rate on a root at x = 0.5 6 7 8 9 10 8.30526 24.266% 4.996489 7.43331 27.203% 4.4E+08 f'(xi) -0.556607 2.05629 -0.39E−07 55. Because the two guesses are on opposite sides of a minimum.01802 4. 59 .474572 -0. Both guesses are in a region where the function is relatively flat.472684 6.474572 0.331330 6.474572.06199 13. the methods slowly converge on the nearest roots.2 -1749.45441 -0.549% 28.1E-06 -5.156325.43.156325 92.9E-13 3.453025 0.964 f(xi) -10.005448 8.545015 2.00146 -1.7E+09 -8E+08 -2. the computation eventually settles down and converges on a root at x = 6. both are sent to different regions that are far from the initial guesses.97196 17.051% 50.842169 0.28 -775.1E+09 -2.1E+10 -9.448386 0.94237 13.541249 105. Explanation of results: The results are explained by looking at a plot of the function.156726 6.425% 0.6041 13.586% 0.59991 30.713% 13. (b) Using an initial guess of 4.

f ( x) = x 2 − a The derivative of this function is f ' ( x) = 2 x These functions can be substituted into the Newton-Raphson equation (Eq.825311 0.11 (a) The formula for Newton-Raphson is x i +1 = x i − ( tanh x i2 − 9 2 x i sech 2 ( xi2 ) −9 ) Using an initial guess of 3. the iterations proceed as iteration 0 1 xi 3.10 The function to be evaluated is x= a This equation can be squared and expressed as a roots problem.924% .971640 60 |εa| 16.845456 −0. x i +1 = xi − x i2 − a 2 xi which can be expressed as x i +1 = xi + a / xi 2 6.2 2.736816 f(xi) 0.6).2.4 0 0 2 4 6 -4 -8 -12 6. 6.906910 f'(xi) 1.

050416 8.355 x i2 − 12. the solution is cast far from the roots in the vicinity of the original guess.15 9.25584 −9.002% As depicted below. The following graph illustrates how the divergence evolves.463023 0. the iterations involve regions of the curve that have flat slopes. 1 0.46847 0.6 2.2 3.292213 0. the next iteration will always diverge.431% 101.81E−05 2.7E−10 f'(xi) −1.887% 183.431% (b) The solution diverges from its real root of x = 3.22345 |εa| 77.6318 36.077102 −4.46848 f(xi) −9.12 The formula for Newton-Raphson is x i +1 = x i − 0.678763 128.813% 1.8 3 3.413 0.742% 139.15.71xi − 12. 61 .35368 0.67645 −0.920% 325.22351 −9.670197 −256.334244 0. Hence. the iterations proceed as iteration 0 1 2 3 4 5 6 7 8 xi 16.852% 497.2804 0.890% 27. Due to the concavity of the slope.003844 25.2 3 3.662596 −54.24995 8.0074 xi4 − 0.1832 Using an initial guess of 16.5 -1 6.4 -0.999738 0.5 0 2.686147 1.284 xi3 + 3.0296 xi3 − 0.1321 −10.0343 −9.864 −25.57445 8.163% 0.852 x i2 + 6.966 −14.183 x i + 5 0.02101 −1.

03./(1-x).13 The solution involves determining the root of f ( x) = x 1− x 6 − 0.10 5 0 -5 5 10 15 20 -5 -10 6./(1-x). >> plot(x.2).y) The fzero function can then be used to find the root 62 . >> y = f(x).*sqrt(6.05 >> x = linspace(0..*sqrt(6.05') f = Inline function: f(x) = x./(2+x))-0./(2+x))-0.05 2+ x MATLAB can be used to develop a plot that indicates that a root occurs in the vicinity of x = 0. >> f = inline('x.

15 MATLAB can be used to generate a plot of the function and to solve for the root. fv = fvol(v).R*T.0866*R*Tc/pc b = 0. It can then be used to generate a plot >> >> >> >> v = linspace(0.5/pc a = 12.p = 65000.0866*R*Tc/pc.002./(v-b)+a.>> format long >> fzero(f.518(233. a = 0. function y = fvol(v) R = 0.55778319740302 >> b = 0.*(v+b)*sqrt(T)). b = 0.00186261539130 The solution.518. One way to do this is to develop an M-file for the function./(v.000 − 0. T = 273. plot(v. >> a = 0.Tc = 191.518.0018626 v(v + 0.fv) grid 63 .pc = 4600. y = p .0018626) 233.0.pc = 4600.02824944114847 6.427*R^2*Tc^2. involves determining the root of f (v) = 65.004).427*R^2*Tc^2.15) 12.557783 + v − 0.15-40.m.03) ans = 0.5/pc.0.Tc = 191.14 The coefficient. can be evaluated as >> format long >> R = 0. therefore. This function is saved as fvol. a and b.

0028) vroot = 0.L = 5.L.r.00280840865703 The mass of methane contained in the tank can be computed as mass = 3 V = = 1068. The fzero function can be used to refine this estimate.r. a root is located at about 0.15 The function to be evaluated is ⎡ ⎛r − h⎞ 2 ⎤ f ( h) = V − ⎢r 2 cos −1 ⎜ ⎟ − (r − h) 2rh − h ⎥ L ⎝ r ⎠ ⎣ ⎦ To use MATLAB to obtain a solution.V = 8.0.0028084 6.V) h = 0.[].5. >> vroot = fzero('fvol'.317 m 3 v 0.(r^2*acos((r-h)/r)-(r-h)*sqrt(2*r*h-h^2))*L.Thus. >> h = fzero('fh'.0028.L. The fzero function can be used to determine the root as >> format long >> r = 2.0. the function can be written as an M-file function y = fh(h.74001521805594 64 .V) y = V .

266324360399887e+003 (b) A plot of the cable can be generated as >> >> >> >> x = linspace(-50. plot(x.2).3.5 A plot can be generated with MATLAB.* sin(2*pi*t) . y = TA/w*cosh(w*x/TA) + y0 .5. w = 10. >> plot(t.grid 6.1000) TA = 1.TA/w.6.16 (a) The function to be evaluated is f (T A ) = 10 − ⎛ 500 ⎞ T A TA ⎟⎟ + cosh⎜⎜ 10 ⎝ T A ⎠ 10 The solution can be obtained with the fzero function as >> format long >> TA = fzero(inline('10-x/10*cosh(500/x)+x/10').y0 = 5.17 The function to be evaluated is f (t ) = 9e −t sin(2πt ) − 3.y). >> y = 9*exp(-t) .grid 65 .y).100). >> t = linspace(0.

>> t = fzero('9*exp(-x)*sin(2*pi*x)-3.18 The function to be evaluated is f (ω ) = 1 − Z 1 ⎛ 1 ⎞ + ⎜ ωC − ⎟ 2 ωL ⎠ R ⎝ 2 Substituting the parameter values yields f (ω ) = 0.0202 6.2]) t = 0.6e-6*x-2.5'.1 and 0.[0.4.06835432096851 >> t = fzero('9*exp(-x)*sin(2*pi*x)-3.[0 0.01 − 2⎞ 1 ⎛ + ⎜ 0.8]) t = 0.40134369265980 6.^2)'.5'.[1 1000]) ans = 220.6 × 10 −6 ω − ⎟ ω⎠ 50625 ⎝ 2 The fzero function can be used to determine the root as >> fzero('0.Thus.01-sqrt(1/50625+(./x).2 0. The fzero function can be used to obtain refined estimates.19 The fzero function can be used to determine the root as 66 . there appear to be two roots at approximately 0.

21 The equation to be solved is 67 . First.8*x-95*9.0) theta = 37. the function to be evaluated is 44./cos(pi*x/180).6527 Thus.8 + 90 tan ⎜ 2 ⎝ 180 ⎠ cos (πθ 0 / 180) Note that the angle is expressed in degrees. the y at 90 m will be –0.5*40000*x^2-95*9. 6./cos(pi*x/180).1. the right fielder can throw at two different angles to attain the same result. Roots seem to occur at about 40o and 50o.8+90*tan(pi*x/180)-44.8380 >> theta = fzero('0.8+90*tan(pi*x/180)-44. >> theta = fzero('0.1.16662477900186 6.8. Therefore.8*0.20 If the height at which the throw leaves the right fielders arm is defined as y = 0.^2'. These estimates can be refined with the fzero function.1) ans = 0. MATLAB can be used to plot this function versus various angles.>> format long >> fzero('2*40*x^(5/2)/5+0.[40 60]) theta = 51.43'.^2'.1 ⎞ ⎛ π θ0 ⎟ − f (θ ) = 0.

4442 272.1) ans = 0 >> b = poly([-2 6]) b = 1 -4 -12 >> [q.516432 6. It can be formulated as ⎛π ⎞ πRxi2 − ⎜ ⎟ xi3 − V x i +1 = x i − ⎝3⎠ 2πRxi − πxi2 or substituting the parameter values. 6. >> a = poly(r) a = 1 -9 -20 204 208 -384 0 0 >> polyval(a.26917 0.r] = deconv(a.1593 276. the Newton-Raphson is the best choice to achieve results efficiently.4202 53.523% 0.017%.395 44.356057 6.26E-05 |εa| f'(xi) 314.017% Thus.355008 f(xi) 1094.⎛π ⎞ f ( h) = πRh 2 − ⎜ ⎟h 3 − V ⎝3⎠ Because this equation is easy to differentiate. the root is determined to be 6.458% 2.b) q = 1 -5 -28 32 0 0 0 0 r = 68 .0353 272. after only three iterations.2858 1. ⎛π ⎞ π (10) xi2 − ⎜ ⎟ xi3 − 1000 x i +1 = x i − ⎝3⎠ 2π (10) xi − πx i2 The iterations can be summarized as iteration 0 1 2 3 xi 10 6.355008 with an approximate relative error of 0.22 >> r = [-2 6 1 -4 8].

0000 -3.0000 .0000 204.0000 >> a = conv(q.0000 Therefore.0000 -20.>> x = roots(q) x = 8.0000 -4.0000 1. >> r = roots(a) r = -6.0000 >> a = [1 15 77 153 90].0000 6.0000 -4. >> r = roots(a) r = -4.0000 -2.0000 -5.0000 -3.b) a = 1 -9 -20 204 208 -384 >> x = roots(a) x = 8.0000 1.0000 -2. the transfer function is G (s) = ( s + 4)( s + 3)( s + 2) ( s + 6)( s + 5)( s + 3)( s + 1) 69 208.0000 >> a = poly(x) a = 1.0000 -384.23 >> a = [1 9 26 24].0000 -1.0000 -9.0000 6.

8913 0. column: {C}.2311 0. row: ⎣G⎦ (c) a12 = 5.3 2⎤ 1⎥ 7⎥ 5⎥⎦ ⎡4 3 7 ⎤ (10) I × [B ] = ⎢1 2 6⎥ ⎢⎣1 0 4⎥⎦ The terms can be collected to give 70 .0000 [D]: 2 × 4 (b) square: [B].6068 7.CHAPTER 7 7. f12 = 0. [E]. >> A = rand(3) A = 0.8214 >> Aug = [A eye(size(A))] Aug = 0.4860 0. g12 = 6 (d) MATLAB can be used to perform the operations ⎡5 8 13⎤ (1) [ E ] + [ B ] = ⎢8 3 9 ⎥ ⎣⎢5 0 9 ⎥⎦ ⎡ 3 −2 1 ⎤ (2) [ E ] − [ B] = ⎢− 6 1 3⎥ ⎣⎢ − 3 0 − 1⎦⎥ (3) [A] + [F] = undefined ⎡20 15 35⎤ (4) 5[ F ] = ⎢ 5 10 30⎥ ⎢⎣ 5 0 20⎥⎦ (5) [A] × [B] = undefined ⎡54 68⎤ (6) [ B] × [ A] = ⎢36 45⎥ ⎢⎣24 29⎥⎦ (7) [G] × [C] = 56 (8) [C ]T = ⎣2 6 1⎦ ⎡5 (9) [ D] = ⎢⎢4 3 ⎢⎣6 T 7.9501 0.0185 0.2311 0.4860 0.4565 0.4565 0. b23 = 6.0000 0 0 {C}: 3 × 1 ⎣G⎦: 1 × 3 0 1. d32 = undefined.0000 0 0 0 1.0185 0.9501 0.7621 0.7621 0.1 >> Aug = [A eye(size(A))] Here’s an example session of how it can be employed.2 (a) [A]: 3 × 2 [E]: 3 × 3 0.8913 0. e22 = 1.8214 [B]: 3 × 3 [F]: 2 × 3 1.6068 0.

⎡− 7 3 0 ⎤ ⎧⎪ x1 ⎫⎪ ⎧⎪ 10 ⎫⎪ ⎢ 0 4 7 ⎥ ⎨ x 2 ⎬ = ⎨− 30⎬ ⎣⎢− 4 3 − 7⎦⎥ ⎪⎩ x 3 ⎪⎭ ⎪⎩ 40 ⎪⎭ Here is the MATLAB session: >> A = [-7 3 0.4 ⎡ 23 − 8⎤ [ X ] × [Y ] = ⎢ 55 56 ⎥ ⎢⎣− 17 24 ⎥⎦ 8⎤ ⎡ 12 [ X ] × [ Z ] = ⎢− 30 52⎥ ⎢⎣− 23 2 ⎥⎦ 8⎤ [Y ] × [ Z ] = ⎡ 4 ⎢⎣− 47 34⎥⎦ 16 ⎤ [ Z ] × [Y ] = ⎡ 6 ⎢⎣− 20 32⎥⎦ 7.1081 0.0811 0.8108 -4.-4 3 -7].0811 0.0811 0.0347 0. >> b = [10.1892 0.0 4 7.5 Terms can be combined to yield 71 .40]. >> x = A\b x = -1.1892 -0.1892 -0.0618 0.7490 >> AT = A' AT = -7 3 0 0 4 7 -4 3 -7 >> AI = inv(A) AI = -0.-30.1081 7.

0].-10 20 -10. 72 .43 ⎬ ⎢ ⎢⎣ 0 − 10 10 ⎥⎦ ⎪⎩ x 3 ⎪⎭ ⎪⎩24. -3 3 0 0 0. -3 -1 0 0 4]. x=K\mg x = 7.2055 7.7530 15.3.0. 0 -1 -8 11 -2. m=[2.62 ⎫⎪ ⎡ 20 − 10 − 10 20 − 10⎥ ⎨ x 2 ⎬ = ⎨ 29.525⎪⎭ A MATLAB session can be used to obtain the solution for the displacements >> >> >> >> K=[20 -10 0. >> Qc = [50.2. mg=m*9.0 -10 10].6 The mass balances can be written as (Q15 + Q12 )c1 = Q01c 01 − Q31c3 − Q12 c1 + (Q23 + Q24 + Q25 )c 2 =0 − Q23 c 2 + (Q31 + Q34 )c 3 − Q24 c 2 − Q15 c1 = Q03 c 03 − Q34 c3 + Q44 c 4 − Q25 c 2 − Q54 c 5 = 0 + (Q54 + Q55 )c 5 = 0 The parameters can be substituted and the result written in matrix form as 0 − 1 0 0 ⎤ ⎧ c1 ⎫ ⎧ 50 ⎫ ⎡6 0 0 0 ⎥ ⎪⎪c 2 ⎪⎪ ⎪⎪ 0 ⎪⎪ ⎢− 3 3 ⎢ 0 − 1 9 0 0 ⎥ ⎨c3 ⎬ = ⎨160⎬ ⎢ 0 − 1 − 8 11 − 2⎥ ⎪c 4 ⎪ ⎪ 0 ⎪ ⎢⎣− 3 − 1 0 0 4 ⎥⎦ ⎪c ⎪ ⎪⎩ 0 ⎪⎭ ⎩ 5⎭ MATLAB can then be used to solve for the concentrations >> Q = [6 0 -1 0 0.160. 0 -1 9 0 0.0.3575 12.81.5].2kx1 − kx 2 = m1 g − kx1 + 2kx 2 − kx3 = m 2 g − kx 2 + kx3 = m3 g Substituting the parameter values 0 ⎤ ⎧⎪ x1 ⎫⎪ ⎧⎪ 19.

866 − 1 −1 0 0 0 ⎥ ⎪⎪ F3 ⎪⎪ = ⎪ 0 ⎪ ⎢ − 0 .866 0 0. 0 0 -0. -0.0191 -866.866 0 -0.5094 11.0110 749. F1 = –500 H2 = 0 7.>> c = Q\Qc c = 11.9983 11.5094 19.7 The problem can be written in matrix form as 0 0 0 0 ⎤ ⎧ F1 ⎫ ⎧ 0 ⎫ − 0 .866 0 0 0.5 ⎢− 0.5 0 0 0 -1 0. -0. 73 .866 0 0 -1] >> b = [0 -1000 0 0 0 0]'.0220 433.5 0 0 0 − 1 0 ⎥ ⎨H 2 ⎬ ⎨ 0 ⎬ ⎢ 0 1 0 . 0.0566 16.0381 -0. >> F = A\b F = -500.5 0 0. >> A = [0.866 0 0 0 ⎥ ⎪ F2 ⎪ ⎪− 1000⎪ ⎢ 0 .866 0 0 − 1⎥⎦ ⎪⎪ V ⎪⎪ ⎪⎩ 0 ⎪⎭ ⎩ 3⎭ MATLAB can then be used to solve for the forces and reactions.9890 Therefore.5094 7.5 ⎡ 0. 0 1 0.0000 250.5 0 0 0.8 F2 = 433 V2 = 250 F3 = –866 V3 = 750 The problem can be written in matrix form as 1 1 0 0 0 ⎤ ⎧i12 ⎫ ⎧ 0 ⎫ ⎡1 − 1 0 ⎥ ⎪i52 ⎪ ⎪ 0 ⎪ 0 1 ⎢0 − 1 ⎢0 −1 0 0 0 1 ⎥ ⎪⎪i32 ⎪⎪ = ⎪ 0 ⎪ ⎢0 − 1⎥ ⎨i65 ⎬ ⎨ 0 ⎬ 0 0 0 1 ⎢0 10 − 10 − 15 − 5⎥ ⎪i ⎪ ⎪ 0 ⎪ 0 ⎢⎣5 − 10 − 20 0 0 0 ⎥⎦ ⎪⎪i54 ⎪⎪ ⎪⎩200⎪⎭ ⎩ 43 ⎭ MATLAB can then be used to solve for the currents.5 0 0 0 ⎥ ⎪ V2 ⎪ ⎪ 0 ⎪ ⎢⎣ 0 0 − 0.5 0 0 0.866 -1 0 -1 0 0.

9. -(k3/m3). &x&1 = −0. (1/m2)*(k2+k3).1538 -1.m3 = 1.5385 -6. 74 . 0 -1 0 1 -1 0.0.5385 7. -(k3/m2).5385 -1.1 m/s2.>> A = [1 1 1 0 0 0 .9000 0.05.(1/m3)*(k3+k4)]. 0 0 -1 0 0 1.k2 = 40.0. &x&2 = 0 . 0 10 -10 0 -15 -5.0000 -0. 5 -10 0 -20 0 0].03]. >> km = [(1/m1)*(k2+k1).1000 Therefore.9 >> k1 = 10. 0.0. -(k2/m2).m2 = 1. >> b = [0 0 0 0 0 200]'. >> i = A\b i = 6. and &x&3 = 0. >> x = [0.k3 = 40. >> kmx = km*x kmx = 0. >> m1 = 1.k4 = 10. -(k2/m1). 0 0 0 0 1 -1.04.1538 -4.6154 -1.

6 can be summarized as Mult/Div 3(n – 1) 2n – 1 5n – 4 Forward elimination Back substitution Total Add/Subtr 2(n – 1) n–1 3n – 3 Total 5(n – 1) 3n – 2 8n – 7 Thus.3 (a) The equations can be expressed in a format that is compatible with graphing x2 versus x1: x 2 = 0.114943x1 + 10 75 . as n increases.11x1 + 12 x 2 = 0.CHAPTER 8 8. 8.1 The flop counts for the tridiagonal algorithm in Fig.2 The equations can be expressed in a format that is compatible with graphing x2 versus x1: x 2 = 0. x2 = 5.5 x1 + 3 x2 = − 1 34 x1 + 6 6 which can be plotted as 10 9 8 7 6 5 4 3 2 1 0 0 2 4 6 8 10 12 Thus. The solution can be checked by substituting it back into the equations to give 4( 4) − 8(5) = 16 − 40 = −24 4 + 6(5) = 4 + 30 = 34 8. the effort is much. 8. much less than for a full matrix solved with Gauss elimination which is proportional to n3. the solution is x1 = 4.

which can be plotted as 140 120 100 80 60 40 20 0 0 200 400 600 800 1000 Thus. The solution can be checked by substituting it back into the equations to give − 1.4 This result is relatively low suggesting that the solution is ill-conditioned.1(400) + 10(60) = 160 ≈ 120 − 2(400) + 17.14 + 20 = 0.2) − 10(−2) = −19.1 10 = −1. you would expect that the system would be ill-conditioned (c) The determinant can be computed as − 1. the solution is approximately x1 = 400.1(17. 8. x2 = 60.86 − 2 17.4(60) = 244 ≈ 174 Therefore.4 (a) The determinant can be evaluated as D = 0⎡ 2 − 1⎤ − (−3) ⎡1 − 1⎤ + 7 ⎡1 2 ⎤ ⎢⎣5 − 2⎥⎦ ⎢⎣− 2 0 ⎥⎦ ⎢⎣5 0 ⎥⎦ D = 0(−2) + 3(5) + 7(−12) = −69 (b) Cramer’s rule 76 . the graphical solution is not very good. (b) Because the lines have very similar slopes.

=2 5 x1 − 2 x 2 2. =2 5 x1 − 2 x 2 x1 + 2 x 2 − x3 = 3 − 3x 2 + 7 x3 = 2 Multiply pivot row 1 by 1/5 and subtract the result from the second row to eliminate the a21 term.x1 = x2 = x3 = 2 −3 7 3 2 −1 2 −2 0 − 69 0 2 7 1 3 −1 5 2 0 − 69 0 −3 2 1 2 3 5 −2 2 − 69 = − 68 = 0. =2 5 x1 − 2 x 2 − 3 x 2 + 7 x3 = 2 4.9855 − 69 = − 101 = 1.4638 − 69 = − 63 = 0.913043 4 .6 x3 = 4.4 x 2 − x 3 = 2. =2 5 x1 − 2 x 2 − 3x 2 + 7 x3 = 2 2. so switch the first and third rows.6 Multiply pivot row 2 by 2.6 x2 = 2 − 7(0.2 = 0.4 x 2 − x 3 = 2.463768 −3 77 .9130 − 69 (c) Pivoting is necessary.2 The solution can then be obtained by back substitution x3 = 4 .913043) = 1.6 − 3x 2 + 7 x3 = 2 Pivoting is necessary so switch the second and third row.4/(–3) and subtract the result from the third row to eliminate the a32 term.

-2 17.4 The resulting plot indicates that the intersection of the lines is difficult to detect: 22 20 18 16 14 12 10 5 10 15 20 Only when the plot is zoomed is it at all possible to discern that solution seems to lie at about x1 = 14.985507 + 2(1.6 (a) The equations can be expressed in a format that is compatible with graphing x2 versus x1: x 2 = 0. 78 . 8.913043) = 2 0. 8.463768) − (0.913043) = 3 5(0.4].x1 = 2 + 2(1.5 and x2 = 10. >> det(A) ans = 0.3: >> A=[-1.5 x 2 = 0.985507 5 (d) − 3(1.1 10.8600 Prob. >> det(A) ans = -69 8.985507) − 2(1.51x1 + 9.463768) = 2 8.1 2 -1.5 x1 + 9.5 -2 0].4: >> A=[0 -3 7.463768) = 0.5 Prob.463768) + 7(0.

52 x1 − x 2 = −9.45 14.02 − 2 which is close to zero.58 = 14.5 (e) Multiply the first equation by 1.75 10 10.5 0.02) = 0. (c) Because the lines have very similar slopes and the determinant is so small.65 14.4 14.5 − 0.04 This result can be substituted into the first equation which can be solved for x1 = − 9.5(−2) − (−1)(1.6 14.58 The second equation can be solved for x2 = 0.5 14.52 and subtract the result from the second equation to eliminate the x1 term from the second equation.7 14. 0.25 (b) The determinant can be computed as 0.5 − 1 = 0.55 14.02/0.5 + 14.03846 x 2 = −0. you would expect that the system would be ill-conditioned (d) Multiply the first equation by 1.14.5 and subtract the result from the second equation to eliminate the x1 term from the second equation. 0.5 x1 − x 2 = −9.04 x 2 = 0.02 1.5 0.35 14.02/0.16538 79 .3 9.5 = 10 0 .

11111 = −6 5. Then. 8.5 10 (b) Check: 80 .4 x1 = ( 27 − 6 − 2(8)) = 0.4 5.351852 x3 = −32.16538 = 4.351852 x2 = (−53.4) and subtract the result from the third equation to eliminate the x2 term from the third equation. multiply the first equation by 1/10 and subtract the result from the third equation to eliminate the x1 term from the third equation.7(−6)) =8 − 5 .4 0.4 x 2 + 1.3 = −10 0.52 x1 = Interpretation: The fact that a slight change in one of the coefficients results in a radically different solution illustrates that this system is very ill-conditioned.5 + 4.7 x3 = −53.03846 This result can be substituted into the first equation which can be solved for − 9.1x3 = −24.7 x3 = −53.7 (a) Multiply the first equation by –3/10 and subtract the result from the second equation to eliminate the x1 term from the second equation.11111 Back substitution can then be used to determine the unknowns x3 = − 32.The second equation can be solved for x2 = − 0.8 x 2 + 5.4 x 2 − x 3 = 27 + 1.3 − 0.8/(–5.2 Multiply the second equation by 0.4 − 1. 10 x1 + 2 x 2 − 5. 10 x1 + 2 x 2 − x 3 = 27 − 5.

so switch the first and third rows.75) and subtract the result from the third row to eliminate the a32 term. − 8 x1 + x 2 − 2 x3 = −20 − 3 x1 − x 2 + 7 x3 = −34 2 x1 − 6 x 2 − x3 = −38 Multiply the first equation by –3/(–8) and subtract the result from the second equation to eliminate the a21 term from the second equation.5 − 5.5 + 8 + 5(−6) = −21. − 8 x1 + x2 − 5.75 x 2 − 1.5 x3 = −43 8.8 (a) Pivoting is necessary.375 x 2 + 7.21739 The solution can then be obtained by back substitution x3 = − 16.10(0.75 x 2 − 1.5 8.5 0.5) − 6(8) + 2(−6) = −61.5 Multiply pivot row 2 by –1.5(−2) =8 − 5. − 8 x1 + x2 − 2 x3 = −20 − 5.375/(–5.75 x 2 − 2 x 3 = −20 − 1. − 8 x1 + x2 − 2 x3 = −20 − 1.375 x 2 + 7.5 x 3 = −43 − 1.5) + 2(8) − (−6) = 27 − 3(0. multiply the first equation by 2/(–8) and subtract the result from the third equation to eliminate the a31 term from the third equation.5 x 3 = −43 Pivoting is necessary so switch the second and third row.21739 = −2 8.108696 x2 = − 43 + 1.75 81 .75 x3 = −26.108696 x3 = −16. Then.75 x3 = −26.

4)245 = 173.6 x1 = 41 − (−0.4 ⎤ ⎧ x1 ⎫ ⎧ 41 ⎫ ⎪ ⎪ ⎪ ⎪ ⎢ 0.5 − ( −0.6 − 0.8 (b) Check: 0.9 Multiply the first equation by –0.75) = 105 8.75) + 0.8 and subtract the result from the second equation to eliminate the x1 term from the second equation. ⎡0.4/0.4)253.4 0.x1 = − 20 + 2(−2) − 1(8) =4 −8 (b) Check: 2(4) − 6(8) − (−2) = −38 − 3(4) − (8) + 7(−2) = −34 − 8(4) + (8) − 2(−2) = −20 8.4(173.75 0. ⎡0.8 − 0.8(253.4(253.4(245) = 41 − 0.8 − 0.75 = 245 0 .10 The mass balances can be written as 82 .5 ⎬ ⎢ 0.6 and subtract the result from the third row to eliminate the x2 term.75) − 0.533333⎥⎦ ⎪⎩ x3 ⎪⎭ ⎪⎩135.75) = 25 − 0.75 0 .4(245) + 0.3333 = 253.8(245) − 0.4 ⎥ ⎨ x 2 ⎬ = ⎨ 45.3333⎪⎭ ⎣ The solution can then be obtained by back substitution x3 = 135.8 ⎥⎦ ⎪⎩ x3 ⎪⎭ ⎪⎩ 105 ⎪⎭ ⎣ Multiply pivot row 2 by –0.4/0.5⎬ ⎢ − 0.533333 x2 = 45.8(173.6 − 0.4⎥ ⎨ x 2 ⎬ = ⎨45.4 ⎤ ⎧ x1 ⎫ ⎧ 41 ⎫ ⎪ ⎪ ⎪ ⎪ ⎢ 0.

0000 8.30 x1 + 0.11 Equations for the amount of sand.Q21c 2 + 400 = Q12 c1 + Q13 c1 Q12 c1 = Q21c 2 + Q23 c 2 Q13 c1 + Q23 c 2 = Q33 c 3 + 200 or collecting terms (Q12 + Q13 )c1 − Q21c 2 − Q12 c1 + (Q21 + Q23 )c 2 − Q13 c1 = 400 =0 − Q23 c 2 + Q33 c3 = 200 Substituting the values for the flows and expressing in matrix form ⎡ 120 − 20 0 ⎤ ⎧⎪ c1 ⎫⎪ ⎧⎪400⎫⎪ 0 ⎥ ⎨c 2 ⎬ = ⎨ 0 ⎬ ⎢ − 80 80 ⎢⎣− 40 − 60 120⎥⎦ ⎪⎩c 3 ⎪⎭ ⎪⎩200⎪⎭ A solution can be obtained with MATLAB as >> A = [120 -20 0.35 0.25 x 2 + 0.0.-80 80 0. 4400 and 7600 m3 from pits 1.35 x 3 = 6000 0.5000.-40 -60 120].4000 7.15 x3 = 5000 0.0000 4.35.4 0.38 0. >> b = [400 0 200]'. 83 .0000 4.6000 Therefore. 2 and 3 respectively.8000].15.0000 5.32 0.3 0. MATLAB can be used to solve this system of equations for >> A=[0. >> x=A\b x = 1. we take 7000.38 x1 + 0.25 0.50 x 3 = 8000 where xi = the amount of gravel taken from pit i. fine gravel and coarse gravel can be written as 0. >> b=[6000. >> c = a\b c = 4.35 x 2 + 0.5].32 x1 + 0.0e+003 * 7.0.40 x 2 + 0.

2T1 − T2 = 4 − T1 + 2.2 -1 0.0 0 -1 2.2 − 1⎥ ⎨T3 ⎬ = ⎨ 4 ⎬ ⎢⎣ 0 0 − 1 2.2 − 1 0 − 1 2 .2 -1 0 0.12 Substituting the parameter values the heat-balance equations can be written for the four nodes as − 40 + 2.0 -1 2.2 -1.8.5548 84 .7866 67.2206 135.2T2 − T3 = 4 − T2 + 2.2T3 − T4 = 4 − T3 + 2.2] >> b=[44 4 4 204]' >> T=A\b T = 50.2T4 − 200 = 4 Collecting terms and expressing in matrix form 0 ⎤ ⎧T1 ⎫ ⎧ 44 ⎫ ⎡2.2⎥⎦ ⎪T ⎪ ⎪⎩204⎪⎭ ⎩ 4⎭ The solution can be obtained with MATLAB as >> A=[2. 2 − 1 0 ⎢ ⎥ ⎪T2 ⎪ ⎪ 4 ⎪ ⎢ 0 − 1 2.7306 94.-1 2.

Thus. . the total addition/subtraction flops for elimination can be computed as n −1 ∑ (n − k )(n − k ) = k =1 ∑ [n n −1 2 − 2nk + k 2 ] k =1 Applying some of the relationships from Eq. . n 3. there are n multiplications/divisions and n – 1 addition/subtractions. n–1 Inner Loop i 2. .CHAPTER 9 9. . n . k + 1. The major difference is that the elimination is only implemented for the left-hand side coefficients. the numbers of multiplications and subtractions are the same and equal to 85 . k . n . The computations can be summarized as Outer Loop k 1 2 . . n Addition/Subtraction flops (n – 1)(n – 1) (n – 2)(n – 2) Multiplication/Division flops (n – 1)n (n – 2)(n – 1) (n – k)(n – k) (n – k)(n + 1 – k) (1)(1) (1)(2) Therefore. (8. for every iteration of the inner loop. n.14) yields ∑ [n n −1 2 ] − 2nk + k 2 = k =1 n3 n2 n − + 3 2 6 A similar analysis for the multiplication/division flops yields n −1 ∑ (n − k )(n + 1 − k ) = k =1 [n 3 ] [ n3 n − 3 3 ] 3 ⎤ n ⎡1 + O(n 2 ) + O ( n 2 ) − n 3 + O ( n) + ⎢ n 3 + O ( n 2 ) ⎥ = ⎦ 3 ⎣3 Summing these results gives 2n 3 n 2 n − − 3 2 6 For forward substitution. . . .1 The flop counts for LU decomposition can be determined in a similar fashion as was done for Gauss elimination.

6) Matrix multiplication is distributive. Then.n −1 ∑i = i =1 (n − 1) n n 2 n = − 2 2 2 Back substitution is the same as for Gauss elimination: n2/2 – n/2 subtractions and n2/2 + n/2 multiplications/divisions.8) [ L]{d } = {b} 9. so the left-hand side can be rewritten as [ L][U ]{x} − [ L]{d } = [ A]{x} − {b} Equating the terms that are multiplied by {x} yields. (9.1 and subtract the result from the third row to eliminate the a31 term. [ L][U ]{x} = [ A]{x} and.8) The matrix to be evaluated is ⎡ 10 2 − 1⎤ ⎢− 3 − 6 2 ⎥ ⎢⎣ 1 1 5 ⎥⎦ Multiply the first row by f21 = –3/10 = –0.3 (9.3 and subtract the result from the second row to eliminate the a21 term. The result is 86 . Eq. therefore. The entire number of flops can be summarized as Mult/Div Forward elimination 3 n n − 3 3 n2 n − 2 2 n2 n + 2 2 Forward substitution Back substitution Total n3 n + n2 − 3 3 Add/Subtr 3 2 n n − 3 2 2 n − 2 n2 − 2 n3 n2 + 3 2 + n 6 n 2 n 2 − Total 3 2n n2 n − − 3 2 6 n2 − n n2 5n 6 2n 3 3n 2 7 n + − 3 2 6 The total number of flops is identical to that obtained with standard Gauss elimination. (9.7) Equating the constant terms yields Eq.6) is [ L]{[U ]{x} − {d }} = [ A]{x} − {b} (9.2 Equation (9. 9. multiply the first row by f31 = 1/10 = 0.7) follows [ L][U ] = [ A] (9.

148148 1]. >> U = [10 2 -1.0 -5.148148 1⎥⎦ ⎢⎣ 0 0 5. >> L = [1 0 0.4 1.3(27) = −53.351852⎥⎦ Multiplying [L] and [U] yields the original matrix as verified by the following MATLAB session.4 1.2 − 1⎤ ⎡10 ⎢ 0 − 5.-0. 2 −1 ⎤ ⎡10 1.1 − 0.7.1 -0.4 2.148148 1⎥⎦ ⎪⎩− 21.1(27) − (−0.8/(–5.0000 2.0000 -3.0000 1.5 + 0.1 − 0.7 ⎥ ⎢ 0 − 5 .4 1.4 ⎢⎣ 0 0 5.3 1 0⎥ ⎨− 61.5⎪⎭ d1 = 27 d 2 = −61.1⎥⎦ Multiply the second row by f32 = 0.3 1 0 ⎥ ⎢ 0 − 5 .4 1. >> A = L*U A = 10.351852].3 1 0.4) = –0.7 ⎥ ⎢⎣ 0.3 1 0 ⎥ ⎢ 0 − 5 .7 ⎥ ⎢⎣ 0.8 5.11111 Back substitution: 87 .0000 9.1 − 0.4) = −32.351852⎥⎦ Forward substitution: 0 0⎤ ⎧⎪ 27 ⎫⎪ ⎡ 1 {d } = ⎢− 0.148148 and subtract the result from the third row to eliminate the a32 term.148148 1⎥⎦ ⎢⎣ 0 0 5. the LU decomposition is 0 0⎤ ⎡10 2 −1 ⎤ ⎡ 1 [ L]{U ] = ⎢− 0.351852⎥⎦ Therefore.0000 -6.4 d 3 = −21.0000 The LU decomposition can be computed as 0 0⎤ ⎡10 2 −1 ⎤ ⎡ 1 [ L]{U ] = ⎢− 0.7 ⎥ ⎢⎣ 0 0.5 − 0.0000 -1.0 0 5.0000 5.5⎬ ⎢⎣ 0.0000 1.148148)(−53.0.

7 ⎥ ⎨21.6⎬ 0 5.351852 x2 = − 53.3 1 0⎥ ⎨ 18 ⎬ ⎣⎢ 0.5 x3 = −4 = −0.747405) = −4.5 ⎬ ⎢⎣ 0 0 5.2 − 1 ⎤ ⎧⎪ x1 ⎫⎪ ⎧⎪ 27 ⎡10 ⎫⎪ {x} = ⎢ 0 − 5.7( −6) =8 − 5 .1(12) − (−0.5 10 For the alternative right-hand-side vector.235294 − 5.11111⎪⎭ x3 = − 32.4 x1 = 12 − 2( −4.6 − 1.4 1.4 x1 = 27 − 2(8) − (−1)(−6) = 0.6 d 3 = −6 − 0. forward substitution is implemented as 0 0⎤ ⎧⎪ 12 ⎫⎪ ⎡ 1 {d } = ⎢− 0.7 ⎥ ⎨ x 2 ⎬ = ⎨ − 53.351852⎥⎦ ⎪⎩ x3 ⎪⎭ ⎪⎩− 32.972318 10 The system can be written in matrix form as ⎡ 2 − 6 − 1⎤ [ A] = ⎢− 3 − 1 7 ⎥ ⎢⎣− 8 1 − 2⎥⎦ ⎧⎪ − 38⎫⎪ {b} = ⎨− 34 ⎬ ⎪⎩− 20⎪⎭ Partial pivot: 88 .351852⎦⎥ ⎪⎩ − 4 ⎪⎭ ⎣⎢ 0 9.747405 5.4 − 1.11111 = −6 5.148148 1⎥⎦ ⎪⎩− 6⎭⎪ d1 = 12 d 2 = 18 + 0.4 1.235294) − (−1)(−0.747405) = 1.1 − 0.3(12) = 21.148148)(18) = −4 Back substitution: 2 − 1 ⎤ ⎧⎪ 12 ⎫⎪ ⎡10 {x} = ⎢ 0 − 5.351852 x2 = 21.7(−0.

23913 1⎥⎦ ⎪⎩− 34 ⎪⎭ d1 = −20 d 2 = −38 − (−0.5 ⎥⎦ Pivot again ⎡− 8 1 −2 ⎤ [ A] = ⎢ 0 − 5. the LU decomposition is 0 0⎤ ⎡ − 8 1 −2 ⎤ ⎡ 1 [ L]{U ] = ⎢− 0.21739 Back substitution: 89 .375(−20) − 0.108696 ⎥⎦ Therefore.23913 1⎦⎥ ⎢⎣ 0 Forward elimination 0 0⎤ ⎧⎪− 20⎫⎪ ⎡ 1 {d } = ⎢− 0.375 7.75) = 0.25 1 0⎥ ⎢ 0 − 5.75 ⎥ ⎢⎣ 0 − 5.375/(−5.108696⎦⎥ ⎣⎢ 0.25 1 0⎥ ⎨ − 38⎬ ⎢⎣ 0.5 ⎥ 0 8.375 0.25 ⎡− 8 1 −2 ⎤ [ A] = ⎢ 0 − 1.5 ⎥ ⎢⎣ 0 0 8.375 7.75 − 1.75 − 1.375 0.75 − 1 .375 Forward eliminate f32 = −1.5 ⎥ ⎢⎣ 0 − 1.23913(−43) = −16.375 f31 = 2/(−8) = −0.25)(−20) = −43 d 3 = −34 − 0.75 − 1.75 ⎥⎦ f21 = −0.23913 ⎡− 8 1 −2 ⎤ [ A] = ⎢ 0 − 5.25 ⎧⎪− 20⎫⎪ {b} = ⎨− 38⎬ ⎪⎩− 34 ⎪⎭ f31 = 0.⎡− 8 1 − 2 ⎤ [ A] = ⎢− 3 − 1 7 ⎥ ⎢⎣ 2 − 6 − 1 ⎥⎦ ⎧⎪− 20⎫⎪ {b} = ⎨− 34 ⎬ ⎪⎩− 38⎪⎭ Forward eliminate f21 = −3/(−8) = 0.

1 − 2 ⎤ ⎧⎪ x1 ⎫⎪ ⎧⎪ − 20 ⎫⎪ ⎡− 8 − 1.1481 0 0 1.6 x3 = − 16. >> [L.108696 x2 = − 43 − (−1.k) = U(i. U(i.4000 0 -1. end L = eye(n).7000 5. end end Test with Prob. % forward elimination for k = 1:n-1 for i = k+1:n L(i.1000 0 1.5)(−2) =8 − 5.k)*U(k.21739⎪⎭ ⎣⎢ 0 9.0000 0 0 2. % input: % A = coefficient matrix % output: % L = lower triangular matrix % U = upper triangular matrix [m.5 ⎥ ⎨ x 2 ⎬ = ⎨ − 43 ⎬ ⎢ 0 − 5.3000 0.k) = 0.U] = LUnaive(A) L = 1. if m~=n.0000 U = 10.3519 90 .n] = size(A).k+1:n).k)/U(k.k+1:n) = U(i.0000 -0.75 0 8.k+1:n)-L(i.0000 -0.0000 -5.21739 = −2 8.75 x1 = − 20 − 1(8) − (−2)(−2) =4 −8 Here is an M-file to generate the LU decomposition without pivoting function [L. U] = LUNaive(A) % LUNaive(A): % LU decomposition without pivoting.3 >> A = [10 2 -1.1 1 5].-3 -6 2.0000 1.k). error('Matrix A must be square'). U(i. U = A.108696⎦⎥ ⎪⎩ x3 ⎪⎭ ⎪⎩− 16. 9.

9165 ⎥ ⎢22.110101⎥⎦ ⎣ ⎦⎣ The multiplication can be implemented as in a11 = 2.44949 × 6.00002 a 32 = 6.45366 + 4.1481 0 0 1.1833 = 225 a 31 = 2.0000 1.110101⎥ ⎢ 6 .0000 2.9165 = 225 a 33 = 22.123724 2 + 4.U]=lu(A) L = 9.45366⎤ ⎥⎢ [ A] = [U ]T [U ] = ⎢6.14) to give ⎡ 2. >> [L.0000 U = 10.0000 -3.0000 -0.9165 6.123724 22.45366 × 2. (9.3519 The result of Example 9.0000 -6.99999 a 22 = 22.0000 -5.123724 = 15 a 22 = 6.0000 1.44949 ⎤ ⎡2.44949 6.0000 -1.1101012 = 979.123724 × 22.7000 5.0000 2.0002 91 .45366 2 + 20.000001 a12 = 6.0000 1.45366 20.123724 4.44949 = 15 a13 = 22.1833 × 20.0000 0 0 2.1000 0 1.9165 × 4.4000 0 -1.45366 = 55.00002 a 21 = 2.1833 2 = 54.1833 20.45366 × 6.44949 = 55.44949 × 22.123724 × 2.9165 2 + 6.1833 4.0000 5.123724 2 + 20.3000 0.Verification that [L][U] = [A].4 can be substituted into Eq. >> L*U ans = 10.44949 2 = 6.0000 -0.7 1.0000 Check using the lu function.

(b) >> A = [8 20 15.20 80 50.303301) = = 2.071068) 2 = 5.4772 0 5.1640 (c) The solution can be obtained by hand or by MATLAB. 2 u 22 = a 22 − u12 = 80 − (7.0711 5.303301) 2 − (2.8284 0 0 7.250. (9.16) can be used to determine u12 = a12 20 = = 7. >> d=U'\b d = 92 .071068 5. (9. Using MATLAB: >> b = [50.15 50 60].282177) 2 = 5.477226 For the third row (i = 3). (9. Eq.303301 u11 2.071068 u11 2.282177 u 22 5.071068(5.163978 Thus. Eq.100].828427 For the second row (i = 2).3033 2.14) to see if their product yields the original matrix [A]. This is left for an exercise.2822 5.828427 u13 = a13 15 = = 5.282177 ⎥ ⎢ 5.477226 u 23 = a 23 − u12 u13 50 − 7.15) is employed to compute u11 = a11 = 8 = 2.477226 2. 2 2 u 33 = a 33 − u13 − u 23 = 60 − (5. the Cholesky decomposition yields ⎡2.828427 Then.8 (a) For the first row (i = 1).163978 ⎥⎦ ⎣ The validity of this decomposition can be verified by substituting it and its transpose into Eq.303301⎤ [U ] = ⎢ 5.828427 7.9. >> U = chol(A) U = 2.

7344 4.0711 5.8284 0 0 7. for k = 1:i-1 s = s + U(k. if m~=n.8828 -1.1640 Check with the chol function >> U = chol(A) U = 2.n] = size(A). j) = (A(i. j) .2822 5. error('Matrix A must be square').9 Here is an M-file to generate the Cholesky decomposition without pivoting function U = cholesky(A) % cholesky(A): % cholesky decomposition without pivoting.8 >> A = [8 20 15.17. for j = i + 1:n s = 0.15 50 60].4772 0 5. i) * U(k.4772 0 5. j).7187 9. i) .1640 93 .3033 2. >> cholesky(A) ans = 2. end U(i.8218 -8. i).8284 0 0 7. end for i = 1:n s = 0. 9.0711 5.8756 >> x=U\d x = -2. for k = 1:i-1 s = s + U(k. % input: % A = coefficient matrix % output: % U = upper triangular matrix [m.20 80 50. end U(i. i) ^ 2. end end Test with Prob.6777 22.3033 2.s) / U(i.2822 5.s). i) = sqrt(A(i.

Thus.CHAPTER 10 10.055556⎪⎭ which can be solved by back substitution for the first column of the matrix inverse.7 ⎥ ⎢ 0 − 5 .7 ⎥ ⎨ x 2 ⎬ = ⎨ ⎢0 ⎬ ⎢⎣ 0 0 5. the LU decomposition is −1 ⎤ 0 0⎤ ⎡10 2 ⎡ 1 [ L]{U ] = ⎢− 0. − 1 ⎤ ⎧⎪ x1 ⎫⎪ ⎧⎪ 1 2 ⎡10 ⎫⎪ − 0 .1 First. multiply the first row by f31 = 1/10 = 0. 0 0⎤ ⎧⎪ d1 ⎫⎪ ⎧⎪1⎫⎪ ⎡ 1 1 0⎥ ⎨d 2 ⎬ = ⎨0⎬ ⎢− 0.4 1.351852⎥⎦ The first column of the matrix inverse can be determined by performing the forwardsubstitution solution procedure with a unit vector (with 1 in the first row) as the right-handside vector.148148 1⎥⎦ ⎪⎩ d 3 ⎪⎭ ⎩⎪0⎪⎭ and solved with forward substitution for {d}T = ⎣1 0.148148 1⎥⎦ ⎢⎣ 0 0 5. The result is 2 − 1⎤ ⎡10 ⎢ 0 − 5.7 ⎥ ⎢⎣ 0 0. 94 .148148 and subtract the result from the third row to eliminate the a32 term.4 1.1 − 0.3 5 .4 ⎢⎣ 0 0 5.1 and subtract the result from the third row to eliminate the a31 term. can be set up as.055556⎦ .8 5.7 ⎥ ⎢⎣ 0. Then.351852⎥⎦ ⎪⎩ x3 ⎪⎭ ⎪⎩− 0.3 ⎢⎣ 0. the lower-triangular system.3 − 0.8/(–5. compute the LU decomposition The matrix to be evaluated is ⎡ 10 2 − 1⎤ ⎢− 3 − 6 2 ⎥ ⎢⎣ 1 1 5 ⎥⎦ Multiply the first row by f21 = –3/10 = –0.1 − 0.4 1. 2 −1 ⎤ ⎡10 1.351852⎥⎦ Therefore.4) = –0.3 and subtract the result from the second row to eliminate the a21 term.3 1 0 ⎥ ⎢ 0 − 5 . This vector can then be used as the right-hand side of the upper triangular system.1⎥⎦ Multiply the second row by f32 = 0.

8) is formulated as 0 0⎤ ⎧⎪ d1 ⎫⎪ ⎧⎪0⎫⎪ ⎡ 1 1 0⎥ ⎨d 2 ⎬ = ⎨1⎬ ⎢− 0.186851].110727 0 0⎤ [ A] −1 = ⎢− 0. and the results are used with [U] to determine {x} by back substitution to generate the second column of the matrix inverse.1 − 0. (9.0000 -0.058824 -0.3 ⎢⎣ 0.00692.0000 -0.0000 -0. and the results are used with [U] to determine {x} by back substitution to generate the third column of the matrix inverse.010381 0. -0. Eq. 0.027682 0.010381 0.⎡ 0.110727 [ A] −1 = ⎢− 0.038062 0⎤ ⎡ 0.176471 0.0000 0.027682 0. >> A = [10 2 -1.058824 − 0.058824 0 0⎥ ⎢⎣ − 0. >> AI = [0.110727 [ A] −1 = ⎢− 0.058824 − 0.010381 0.0000 1.176471 0⎥ ⎢⎣ − 0.038062 0. >> A*AI ans = 1.2 The system can be written in matrix form as ⎡− 8 1 − 2 ⎤ [ A] = ⎢ 2 − 6 − 1 ⎥ ⎢⎣− 3 − 1 7 ⎥⎦ ⎧⎪ − 38⎫⎪ {b} = ⎨− 34 ⎬ ⎪⎩− 20⎪⎭ Forward eliminate f21 = 2/(−8) = −0.-3 -6 2.25 f31 = −3/(−8) = 0.110727 0.375 95 .148148 1⎥⎦ ⎪⎩ d 3 ⎪⎭ ⎪⎩0⎪⎭ This can be solved with forward substitution for {d}T = ⎣0 1 0.027682 0⎥⎦ Finally.058824⎥ ⎣⎢ − 0. The following MATLAB session can be used to implement this check.058824.00692 ⎤ ⎡ 0. -0.0000 0.0000 1. the same procedures can be implemented with {b}T = ⎣0 0 1⎦ to solve for {d}T = ⎣0 0 1⎦ .0000 10.186851⎦⎥ This result can be checked by multiplying it times the original matrix to give the identity matrix.1 1 5].010381 0 0⎥⎦ To determine the second column. 0.176471 0.038062 0.0000 -0.148148⎦ .

8) is formulated as 0 0⎤ ⎧⎪ d 1 ⎫⎪ ⎧⎪0⎫⎪ ⎡ 1 1 0⎥ ⎨d 2 ⎬ = ⎨1⎬ ⎢− 0.25 ⎬ ⎢ 0 − 5.375/(−5.75 − 1.375 0. 0 0⎤ ⎧⎪ d 1 ⎫⎪ ⎧⎪1⎫⎪ ⎡ 1 1 0⎥ ⎨d 2 ⎬ = ⎨0⎬ ⎢− 0.115282 0 0⎤ [ A] −1 = ⎢ − 0.029491 0 0⎥ ⎢⎣− 0.375 0. the lower-triangular system.25 1 0⎥ ⎢ 0 − 5. (9.0.5 ⎥ ⎨ x 2 ⎬ = ⎨ 0.434783⎪⎭ which can be solved by back substitution for the first column of the matrix inverse.⎡− 8 −2 ⎤ 1 − 5.75 ⎢⎣ 0.434783⎦ .75) = 0.25 ⎢⎣ 0.23913 1⎥⎦ ⎢⎣ 0 0 8.75 − 1.23913 1⎥⎦ ⎪⎩ d 3 ⎪⎭ ⎪⎩0⎪⎭ This can be solved with forward substitution for {d}T = ⎣0 1 − 0.053619 0 0⎥⎦ To determine the second column. 96 . can be set up as.375 7. Eq.5 ⎥ [ A] = ⎢ 0 ⎢⎣ 0 − 1.75 ⎥⎦ Forward eliminate f32 = −1.25 ⎢⎣ 0. This vector can then be used as the right-hand side of the upper triangular system.5 ⎥ [ L]{U ] = ⎢− 0.108696⎥⎦ The first column of the matrix inverse can be determined by performing the forwardsubstitution solution procedure with a unit vector (with 1 in the first row) as the right-handside vector.108696 ⎥⎦ Therefore. ⎡ .23913 ⎡− 8 1 −2 ⎤ [ A] = ⎢ 0 − 5. the LU decomposition is −2 ⎤ 0 0⎤ ⎡ − 8 1 ⎡ 1 − 1. Thus.23913⎦ .375 0. and the results are used with [U] to determine {x} by back substitution to generate the second column of the matrix inverse.25 − 0.5 ⎥ ⎢⎣ 0 0 8.108696⎥⎦ ⎪⎩ x3 ⎪⎭ ⎪⎩− 0.75 ⎢⎣ 0 0 8.23913 1⎥⎦ ⎪⎩ d 3 ⎪⎭ ⎪⎩0⎭⎪ and solved with forward substitution for {d}T = ⎣1 0. 1 − 2 ⎤ ⎧⎪ x1 ⎫⎪ ⎧⎪ 1 ⎡− 8 ⎫⎪ − 1.

02590673575130 0.4 The mass balances can be written and the result written in matrix form as 97 .029491 0.06079447322971 0.029491 − 0.285 g m3 10.⎡ .3 The following solution is generated with MATLAB. >> format long >> AI = inv(A) AI = 0.2073 227. Therefore.0124352.01278065630397 0.-4 -1 12].053619 − 0. >> format short >> c = AI*b c = 320.9534 + 2.034853⎤ [ A] −1 = ⎢ − 0.0259067(500) + 0.01243523316062 0. the same procedures can be implemented with {b}T = ⎣0 0 1⎦ to solve for {d}T = ⎣0 0 1⎦ .03212435233161 0.115282 − 0. ⎡ .0.053619 − 0. (a) >> A = [15 -3 -1. the increase in the mass input to reactor 3 needed to element a13 induce a 10 g/m3 rise in the concentration of reactor 1 can be computed as ∆b3 = g 10 = 804.00932642487047 0.0124352 d (d) The decrease in the concentration of the third reactor will be ∆c 3 = 0.16622 − 0.1667 0.5026 (c) The impact of a load to reactor 3 on the concentration of reactor 1 is specified by the −1 = 0.123324 ⎦⎥ 10.2021 321.029491 0⎥⎦ Finally.-3 18 -6.009326(250) = 12.0.029491 − 0.013405 0⎤ [ A] −1 = ⎢ − 0.032172⎥ ⎣⎢− 0.3316 = 15. and the results are used with [U] to determine {x} by back substitution to generate the third column of the matrix inverse.07253886010363 0.16622 0⎥ ⎢⎣− 0.02072538860104 0.013405 − 0.09015544041451 (b) >> b = [3800 1200 2350]'.115282 − 0.

1698 0.0063 0.4330 0.5 0 0. 0 1 0. -0.0189 0.866 − 1 −1 0 0 0 ⎥ ⎪⎪ F3 ⎪⎪ = ⎪ F2. >> A = [0.2500 The concentration in reactor 5 can be computed using the elements of the matrix inverse as in.0 -1 9 0 0.866 0 0 − 1⎥⎦ ⎪⎪ V2 ⎪⎪ ⎪ 3.5 0 0 0 − 1 0 ⎥ ⎨ H 2 ⎬ ⎨ F2.5 0 0 0 -1 0.0000 0 -1.1132 0.5 0 0 0 ⎥⎪ V ⎪ ⎪F ⎪ ⎢⎣ 0 0 − 0.h ⎪ ⎩ 3 ⎭ ⎪⎩ F3.0000 0 0 0 0 0 0 -1. >> AI = inv(A) AI = 0.5000 -1.0189 0.-3 -1 0 0 4].3396 0.0600 0.0000 0 98 0 1.2500 -0. h ⎪ ⎢ − 0 .8660 0.0000 0 0 0 0 0 0 0 -1.1698 0.528 10. >> inv(Q) ans = 0.981 + 7.v ⎪⎭ MATLAB can then be used to solve for the matrix inverse.5 The problem can be written in matrix form as ⎧ F1.0000 -0. −1 −1 c5 = a 51 Q01c 01 + a 53 Q03 c 03 = 0.866 0 0 -1].5 0 0 0. 0. h ⎫ − 0.5000 -0.5 0 0 0.866 0 0 0.866 0 -0. -0.866 -1 0 -1 0 0.8660 0.547 = 24.7500 0 0 0 -1.4330 0.0746 0.0896 0. 0 0 -0.0909 0 0 0 0 0.0875 0.0189 0 0 0 0.v ⎪ ⎪ ⎪ 0 0.0000 -0.2500 -0.v ⎬ ⎢ 0 1 0.0189(8)50 = 16.0189 0.4330 0.1698 0.-3 3 0 0 0.5 0 0 0 0 ⎤ ⎧ F1 ⎫ ⎪ ⎡ 0.5 ⎪ ⎪ ⎢− 0.0 -1 -8 11 -2.1698(5)20 + 0.866 F1.0 − 1 0 0 ⎤ ⎧ c1 ⎫ ⎧Q01c 01 ⎫ ⎡6 0 0 0 ⎥ ⎪⎪c 2 ⎪⎪ ⎪⎪ 0 ⎪⎪ ⎢− 3 3 ⎢ 0 − 1 9 0 0 ⎥ ⎨c 3 ⎬ = ⎨Q03 c 03 ⎬ ⎢ 0 − 1 − 8 11 − 2⎥ ⎪c 4 ⎪ ⎪ 0 ⎪ ⎢⎣− 3 − 1 0 0 4 ⎥⎦ ⎪c ⎪ ⎪ 0 ⎪ ⎭ ⎩ 5⎭ ⎩ MATLAB can then be used to determine the matrix inverse >> Q = [6 0 -1 0 0.0377 0.0000 .0455 0.866 0 0 0 ⎥ F2 ⎢ 0 .

v + a 25 F3.8000 1.1) ans = 2.2 -6 -1.0000 -0.0000 1.3: >> A = [15 -3 -1.1 1/(-9) 3/(-9). h = 0.The forces in the members resulting from the two forces can be computed using the elements of the matrix inverse as in.8000 >> norm(A.inf) ans = 11 Prob.3333 0. 10.h = −0.0000 -0. >> norm(A.6 The matrix can be scaled by dividing each row by the element with the largest absolute value >> A = [8/(-10) 2/(-10) 1.7 Prob.h = 0. 10. >> norm(A.inf) ans = 2 10.0667 1.v + a15 F3.2: >> A = [-8 1 -2.866(−2000) + 0(−500) = −1732 + 0 = −1732 10. −1 −1 F1 = a12 F1.1111 -0.4000 MATLAB can then be used to determine each of the norms.'fro') ans = 1.-3 18 -6.'fro') ans = 13 >> norm(A.433(−2000) + 1(−500) = 866 − 500 = 366 −1 −1 F3 = a 32 F1.-4 -1 12] 99 .2000 -0.-3 -1 7].9920 >> norm(A.v + a 35 F3.1 -1/15 6/15] A = -0.5(−2000) + 0(−500) = −1000 + 0 = −1000 −1 −1 F2 = a 22 F1.

inf) Warning: Matrix is close to singular or badly scaled.49 7 1].6586 >> norm(A.) > In cond at 45 ans = 3. >> A = [16 4 1.1 0.8 0.4 2 1.9 16 25 36.3333⎪ + 2. (Type "warning off MATLAB:nearlySingularMatrix" to suppress this warning.5333⎥⎦ The row-sum norm of the inverse is ⎪-2.6667.8963e+016 (b) Row-sum norm >> cond(A.8 + 0. Results may be inaccurate.inf) 100 .2922e+018 10.3333 2.'fro') ans = 27.inf) ans = 27 10.8 (a) Spectral norm >> A = [1 4 9 16. >> cond(A.037487e-019.1 − 0 . the condition number is Cond[A] = 57(5.0667 ⎤ − 1 . The inverse is ⎡− 0.5 ⎢⎣ − 2.4 ⎥ ⎢ 1. RCOND = 3.9 (a) The matrix to be evaluated is ⎡16 4 1⎤ ⎢ 4 2 1⎥ ⎢⎣49 7 1⎥⎦ The row-sum norm of this matrix is 49 + 7 + 1 = 57.1667 0. Therefore.16 25 36 49].4 9 16 25.5333 = 5.>> norm(A.6667) = 323 This can be verified with MATLAB. >> cond(A) ans = 8.

sum(A(6.0349 0.6032 1.:)).6025e+013 The digits of precision that could be lost due to ill-conditioning can be calculated as >> c = log10(N) c = 13.3468 1.:)).7188 The solution can then be generated by left division >> x = A\b 101 .2048 Thus. sum(A(2.1294 Frobenius norm: >> cond(A. sum(A(4. about 13 digits could be suspect. sum(A(3. sum(A(10.7773 0.9307 0. >> N = cond(A) N = 1.:)).49 7 1].0199 1.'fro') ans = 217.8467 0.4843 10.9290 2. sum(A(5.0000 (b) Spectral norm: >> A = [16 4 1.:))] b = 2.:)).:)).:)). >> cond(A) ans = 216.10 The spectral condition number can be evaluated as >> A = hilb(10). sum(A(9. sum(A(8. sum(A(7.:)).:)). A right-hand side vector can be developed corresponding to a solution of ones: >> b=[sum(A(1.ans = 323.:)).4 2 1.1682 1.

x6=5.x5=3.0000 1.x3^5 x3^4 x3^3 x3^2 x3 1. this means that about 11 to 12 digits are suspect.0000 0.x = 1.x6^5 x6^4 x6^3 x6^2 x6 1] A = 1024 32 16807 100000 243 3125 256 16 2401 10000 81 625 64 8 343 1000 27 125 16 4 49 100 9 25 4 2 7 10 3 5 The spectral condition number can be evaluated as >> N = cond(A) N = 1.3822e-004 >> e=mean(abs(x-1)) e = 1.9997 1.11 First.0001 The maximum and mean errors can be computed as >> e=max(abs(x-1)) e = 5.x4=10. some of the results are accurate to only about 3 to 4 significant digits. 10.0000 1.x5^5 x5^4 x5^3 x5^2 x5 1.0003 0.9999 1.x2=2.8662e-004 Thus. Because MATLAB represents numbers to 15 significant digits.x3=7.0005 0.9995 1. the Vandermonde matrix can be set up >> x1 = 4. >> A = [x1^5 x1^4 x1^3 x1^2 x1 1.0000 1.x2^5 x2^4 x2^3 x2^2 x2 1.1611 102 1 1 1 1 1 1 .x4^5 x4^4 x4^3 x4^2 x4 1.4492e+007 The digits of precision that could be lost due to ill-conditioning can be calculated as >> c = log10(N) c = 7.

sum(A(5. 103 . about 7 digits might be suspect.99999999999991 1.Thus.:)). for this case.sum(A(3.00000000000542 0.sum(A(4. Thus.:)).sum(A(2.:)).:)).:)).00000000000075 0. the condition number tends to exaggerate the impact of ill-conditioning. Because MATLAB represents numbers to about 15 significant digits.420774940034789e-012 >> e = mean(abs(x-1)) e = 2. A right-hand side vector can be developed corresponding to a solution of ones: >> b=[sum(A(1.:))] b = 1365 63 19608 111111 364 3906 The solution can then be generated by left division >> format long >> x=A\b x = 1. sum(A(6.99999999999630 The maximum and mean errors can be computed as >> e = max(abs(x-1)) e = 5.00000000000000 0. this means that about 3 digits are suspect.99999999999703 1.154110223528960e-012 Some of the results are accurate to about 12 significant digits.

6875 0 .7188 197.25 56.4 x1 + 0.9375 ε a .4(79.1 = 79.9375 206.76% 104 maximum εa 100.6875 × 100% = 22.875 0.6875) = 150.25) + 0.7188 126.8 Second iteration: x1 = 41 + 0.7188 − 159.8 x2 = 25 + 0.32% 22.1 (a) The first iteration can be implemented as x1 = 41 + 0.4 x 2 41 + 0.6875 − 51.32% 150.8 x2 = 25 + 0.2 = 150.9375 − 56.9375) = 206.8 The error estimates can be computed as ε a .875) = 79.75% 206.9688 εa 100.6875 150.6875 0.25 × 100% = 35.25 0 .69% 79.4(51.4(150.6875 ε a.4(0) = = 56.875 159.7188 0.9375 0.32% .875 × 100% = 62.8 0.4 x3 25 + 0.4(159.00% 100.4 x 2 105 + 0.75% 37.CHAPTER 11 11.11% 23.69% 62. The entire computation can be summarized as iteration 1 2 3 unknown x1 x2 x3 x1 x2 x3 x1 x2 value 51.00% 62.4(56.00% 100.3 = 206.4(0) = = 51.00% 35.6875 79.875) = = 159.7188 The remainder of the calculation proceeds until all the errors fall below the stopping criterion of 5%.6875) + 0.8 x3 = 105 + 0.4(56.8 0 .8 x3 = 105 + 0.8 0.

4 5 6 x3 x1 x2 x3 x1 x2 x3 x1 x2 x3 230.4(61.14) = 179.46% 1.4 x 2 105 + 0.26% 3.5 x2 = 25 + 0.8711 167.8 Relaxation yields: x 2 = 1.45 0 .62% 4.4 x3 = 105 + 0.4(200.2(88.1211 and x3 = 250.4(62) = = 168.86% 7. (b) The same computation can be developed with relaxation where λ = 1.8 Relaxation yields: x 3 = 1.24 0 .37% 3.25) − 0.25 0 .208) = 231.8 0 .8 0 .8 0.4(202.4(93.5) = 93. after 6 iterations.45 0.50% 2.9922 161.11% 15.1211 250.2(51.4(0) = = 62 0 .24) − 0.8105 10.354 0 .2344 150.17% 37.4 x 2 41 + 0.2344 221.8711 239.5) + 0.65% 7.2(61.2(0) = 202.2(62) − 0.45) − 0.8105.4 x 3 25 + 0.14 Second iteration: x1 = 41 + 0.84) + 0.9922 233.4844 241.26% 5.4(0) = = 51.4) = 200.2(168.4(62) = 88.2422 247.2(74. First iteration: x1 = 41 + 0.208 x3 = 105 + 0.45) − 0.65% 10.8 105 .2(0) = 74.5% and we arrive at the result: x1 = 167.2.21% 15.8 Relaxation yields: x1 = 1.04% 2.50% Thus.2(179.84 x2 = 25 + 0.8 Relaxation yields: x 2 = 1. the maximum error is 3.4 x1 + 0.8711. x2 = 239.8 Relaxation yields: x1 = 1.2(0) = 61.

622.1968 − 202.78% 42.Relaxation yields: x 3 = 1.84 − 61.42298 244.3 = 237.45 88.7 = 10 10 x2 = − 61. The entire computation can be summarized as iteration 1 2 3 4 unknown x1 x2 x3 x1 x2 x3 x1 x2 x3 x1 x2 x3 value 51.9 = −6.78% 237.9 = −6 −6 x3 = − 21.5 74.8568 237.99528 243.49056 252.38% 15.00% 34.14) = 237.08% 5.2 = 200.84% 200.2( 231.208 − 74.46% 62.1968 The error estimates can be computed as ε a .00% 100.62 = 5 5 Second iteration: 106 . 11.1968 162.14 93.00% 2.84% 14.82% 0.7) − 2(0) = 8 .6222 εa 100.4 × 100% = 62. After 6 iterations.839% 42.423.4 202. relaxation speeds up convergence.389 and x3 = 253.5 − x1 − x 2 − 21.84 200.42% maximum εa 100.379% 4. x2 = 244.1 = 93.354) − 0.5 + 3x1 − 2 x 3 − 61.000% 62.5 − (2.46% 93.45 179.2 The first iteration can be implemented as x1 = 27 − 2 x 2 + x3 27 − 2(0) + 0 = 2.38866 253.208 ε a .00% 100.997% and we arrive at the result: x1 = 171.5 + 3(2.7) − 8.44433 relaxation 61.55498 171.23898 253.354 231.997% Thus.354 151.70% 6.2768 249.99528 169.1968 The remainder of the calculation proceeds until all the errors fall below the stopping criterion of 5%.24 231.2(202.14 × 100% = 14.5 × 100% = 34.25 62 168. the maximum error is 4.208 237.84 ε a.

55% − 5.1 = 0.01% 0.523687 8.3 The first iteration can be implemented as x1 = 27 − 2 x 2 + x3 27 − 2(0) + 0 = 2.5 − (0.934467 − (−6.914333 -5.00007.7 8.14% 0.9) − 6.62) = 7.51% 12.258 − 2. after 5 iterations.99928 0.7 × 100% = 947% 0.30% 0.55% 50.258) − 2(−6.59% 0.73% 1.20% 5.x1 = 27 − 2(8.00674 0.500253.500253 8.62 0.497326 7.934467 The remainder of the calculation proceeds until all the errors fall below the stopping criterion of 5%.914333 ε a .62 = 0.30% 0.258 7.59% and we arrive at the result: x1 = 0.5 + 3(0.914333 = −5. 11. The entire computation can be summarized as iteration 1 2 3 4 5 unknown x1 x2 x3 x1 x2 x3 x1 x2 x3 x1 x2 x3 x1 x2 x3 value 2.00% 100.00% 946. the maximum error is 0.01% maximum εa 100% 946% 50.62) × 100% = 11.00% 100.914333 −6 x3 = − 21.999091 -5.3 = − 5.914333 − 8.00007 εa 100.9 -6.93447 0.000112 and x3 = −6.258 10 x2 = − 61.010001 -6.19% 1.12% 0.934467 5 The error estimates can be computed as ε a .45% 11.59% Thus.000112 -6.45% 7.9 × 100% = 12.73% 5.7 = 10 10 107 .2 = 7. x2 = 8.258) − 7.258 ε a.

25 = −6.50% 5.28% 7.3 = 0.7 10.7) − 2(−4.5476 8.26% 10.493702 7.843333 -5.2 = 7.3 = − 6.59% − 6.28% 37.3) = 7.89 5 The error estimates can be computed as ε a .25) − 4. The entire computation can be summarized as iteration 1 2 3 4 5 unknown x1 x2 x3 x1 x2 x3 x1 x2 x3 x1 x2 x3 x1 x2 value 2.00% 1127.47% 2.00% 1127.89 − ( −4.1 = 0.92% 0.00% 100.75% 108 maximum εa 100.25 × 100% = 37.466667 − 10.466667 ε a .5 − 0 − 0 = = −4.x2 = − 61.89 The remainder of the calculation proceeds until all the errors fall below the stopping criterion of 5%.3 0.5 − x1 − x 2 − 21.045389 -5.47% .3 5 5 Second iteration: x1 = 27 − 2(10.466667 −6 x3 = − 21.5 + 3x1 − 2 x 3 − 61.466667 -6.03% 5.51% 2.25 = −6 −6 x3 = − 21.7 × 100% = 1127% 0.7) − 10.50% 4.258 ε a.5 + 3(2.25 -4.5 − ( 2.517667 7.5 + 3(0) − 2(0) = 10.00% 100.22 7.83733 0.80% 18.59% 57.27% 57.89 0.27% 37.9722 0.985467 εa 100.22 − 2.3) × 100% = 37.22 10 x2 = − 61.

1842 ε a .99695 and x3 = −5. after 6 iterations.501047 7. x2 = 7.8889 18 18 c3 = 2350 + 4c1 + c 2 2350 + 4(253.4012 15 c2 = 1200 + 3( 294.47% 0.00% .4012) + 6(289.0186 0.4012 − 253.4012) + 212. 11.8889 289.15% 311.3 = 311.6491 The remainder of the calculation can be summarized as iteration 1 unknown x1 x2 x3 value 253.8889 × 100% = 48.3519 × 100% = 7.00% 109 maximum εa 100.6491 12 The error estimates can be computed as ε a .3519 = 294.47% Thus.1842 − 108.2 = 212.47% and we arrive at the result: x1 = 0.3519) = 212.3519 12 12 Second iteration: c1 = 3800 + 3(108.92% 1.1842 18 c3 = 2350 + 4(294.99583.00% 100.3519 εa 100.x3 x1 x2 x3 6 -6.1 = 294.00% 100.38% 10.14% 0.3333 108.99583 0.3333) + 6(0) = = 108.8889 = = 289.501047.3333 × 100% = 13.68% 212.889) + 289.95% 294.4012 ε a.6491 − 289.99695 -5.3333) + 108.77% 1.4 The first iteration can be implemented as c1 = 3800 + 3c 2 + c3 3800 + 3(0) + 0 = 253. the maximum error is 1.3333 = 15 15 c2 = 1200 + 3c1 + 6c 3 1200 + 3(253.1842 = 311.

94076 = 7 7 The error estimates can be computed as 110 .08631) + ( −2.2021 and x3 = 321.0516 227.00% 1.98% 2.68% 7.5402 321.0598 321.761905 = 7 7 Second iteration: x1 = − 20 − 7.761905) = 4. x2 = 227.08631 −8 x2 = − 38 − 2 x1 + x3 − 38 − 2(4.43% 0.2073.5026.60% 0.2 3 4 5 x1 x2 x3 x1 x2 x3 x1 x2 x3 x1 x2 x3 294.23% Note that after several more iterations.761905) = 8.3254 226.95% 48. we arrive at the result: x1 = 320.23% 0.1842 311.5 The equations must first be rearranged so that they are diagonally dominant − 8 x1 + x 2 − 2 x3 = −20 2 x1 − 6 x 2 − x3 = −38 − 3 x1 − x 2 + 7 x3 = −34 (a) The first iteration can be implemented as x1 = − 20 − x 2 + 2 x 3 − 20 − 0 + 2(0) = 2 .3075 319.155754 = −1.00% 4.08631) + 8.155754 = −6 −6 x3 = − 34 + 3x1 + x 2 − 34 + 3( 4.4388 13.9579 319.5) + 0 = 7.23% 0.09% 48. 11.1535 320.87% 1.166667 = −2.166667 = −6 −6 x3 = − 34 + 3 x1 + x 2 − 34 + 3(2.6491 316.4012 212.5) + 7.5468 223.15% 7.166667 + 2(−2.68% 7.5 = −8 −8 x2 = − 38 − 2 x1 + x3 − 38 − 2( 2.37% 0.43% 0.

94076 The remainder of the calculation proceeds until all the errors fall below the stopping criterion of 5%.2(0) = 3 x2 = − 38 − 2 x1 + x3 − 38 − 2(3) + 0 = 7.004659.94076 − (−2.92% maximum εa 100.8 x3 = − 34 + 3 x1 + x 2 − 34 + 3(3) + 8.99168 -1.3 = − 1.08631 8.00% 38.92% and we arrive at the result: x1 = 4.2(0) = −2.31% 2.13% 8.166667 -2.155754 -1.08631 ε a.5) − 0.7771429 111 .2( −2.08631 − 2.31% 2.166667 × 100% = 12.333333 = −6 −6 Relaxation yields: x 2 = 1.7619 4.82% 4.5 × 100% = 38.3142857) − 0.5 7.004659 7.2(0) = 8.99168 and x3 = −1.31% − 1.04% 2.13% 42.94076 4. x2 = 7.82% 12.ε a .99919 100. First iteration: x1 = − 20 − x 2 + 2 x 3 − 20 − 0 + 2(0) = 2 .05% 2. The entire computation can be summarized as iteration 0 1 2 3 unknown x1 x2 x3 x1 x2 x3 x1 x2 x3 x1 x2 x3 value εa 0 0 0 2. after 3 iterations. the maximum error is 2.155754 − 7.92% Thus.99919.2(2.5 = −8 −8 Relaxation yields: x1 = 1.8 = = −2.333333) − 0.2 = 8.2(7.761905) × 100% = 42.2.00% 100.00% 42.155754 ε a . (b) The same computation can be developed with relaxation where λ = 1.1 = 4.3142857 7 7 Relaxation yields: x 3 = 1.00% 100.

71% 32.2166857 ε a .7771429 = 8.9873047 7.7319837) − 0.2166857 = −1.0336312 8.2942857) − 0.94% 2.5531429 ε a.8 + 2(−2.8467453 -2.00% 100.7319837 = 7 7 Relaxation yields: x 3 = 1.5531429) + 8.00% 100.9383056 112 εa 100.2166857 x3 = − 34 + 3 x1 + x 2 − 34 + 3(4.49% 5.3 = − 1.5229518 − (−2.8 × 100% = 7.248146 4.314286 4.8 -2.2166857 − 8.1 = 4.353% 32.10% 82.3139048 -1.0695595 -1.2(−2.11% 7.5 7.Second iteration: − 20 − x 2 + 2 x3 − 20 − 8.7727572 -2.9078237 7.2942857 8.777143 4.3139048) − 0.884759 3.2(4.3333333 -2.5531429) − 2.11% 4.522952 3.1% 8.731984 3.2942857 = −8 −8 x1 = Relaxation yields: x1 = 1.49% 4.9700747 relaxation 3 8.2(3) = 4.2( −1.40% maximum εa 100.38% 19.00% 34.2(8.28% 2.280% .945323 3.12728 4.3139048 = −6 −6 Relaxation yields: x 2 = 1.26% 7.7771429) × 100% = 82.2(8.2 = 8. The entire computation can be summarized as iteration 1 2 3 4 5 unknown x1 x2 x3 x1 x2 x3 x1 x2 x3 x1 x2 x3 x1 x2 value 2.7771429) = −1.35% 20.257% 19.000% 82.12892 -1.35% − 1.7771429) = 4.5229518 The remainder of the calculation proceeds until all the errors fall below the stopping criterion of 5%.8) = 8.5531429 − 3 × 100% = 34.2166857 -1.5531429 8.5531429 x2 = − 38 − 2 x1 + x3 − 38 − 2(4.9678445 7.7787598 7.0846055 8.5229518 The error estimates can be computed as ε a .

03% 199.2 0.49984 -0.29% 113 maximum εa 100.5 1.91% 455.68% 127.7 0.11% 3.0122254.00% 100. Rather. if they can be ordered as −2x + 4y − 5z = −3 2y – z = 1 −x + 3y + 5z = 7 For this case.595% and we arrive at the result: x1 = 4.16% 67.0272613 -1.022594 4.x3 x1 x2 x3 6 -2.0272613 and x3 = −1. it will oscillate.0122254 8.7496 1.07% 1.7504 1.990866 -2.595% Thus.6 As ordered. 1).4 -1 1.979007 8.748 0. Set 1: 8x + 3y + z = 12 2x + 4y – z = 5 −6x +7z = 1 Set 3: 3x + y − z = 3 x + 4y – z = 4 x + y +5z =7 Because it is not diagonally dominant.00% 250. none of the sets will converge.60% 8.72% 466. However.499968 2.050162 4.04% 62. The way that this occurs depends on how the equations are ordered.248 0.0124354 -1. x2 = 8.24992 0.20% 40. the maximum error is 3.49% 66.11% 1.67% 137. they will converge on the solution of (1.00% 137.00% 250.71% 199.20% .66% 66.26% 40. For example.496 -0.979007.04% 455.00% 58. it will also not diverge. Gauss-Seidel iterations yields iteration 1 2 3 4 5 6 7 unknown x1 x2 x3 x1 x2 x3 x1 x2 x3 x1 x2 x3 x1 x2 x3 x1 x2 x3 x1 value 1.0048286 8.66% 466.26% 127.48 2.33% 191.068% 3.4992 2.00% 100. 1.74992 εa 100.74 1. 11. After 6 iterations. relaxation actually seems to retard convergence. if Set 1 and 3 are reordered so that they are diagonally dominant.76 1. 1. Set 2 will not converge on the correct solution of (1.99% 127. However.5 0. 1).

31% 188.79% 243.499994 -0.85% 79.82 3.8 13.42442 εa 100.75002 1.264 -3.32% 167.792 -1.29% 466.57504 -4.00% 200.5 − y f 2 ( x.374029 19.93507 3.66% 66.81% 243.67% 466.4584 6.62% 244.80% 241.00% 151.65% 40. y ) = − x 2 + x + 0 .31% 317.94% 355.7251 -1.00% 100.00% 100.06% maximum εa 100.249997 0.81% 163.9168 -16.3752 3.749984 1.32% 241.36% 209.69% 128.94% 195.5 2.14% 323.36% 317.14% 206.94 5.12% 323. Gauss-Seidel iterations yields iteration 1 2 3 4 5 6 7 8 unknown x1 x2 x3 x1 x2 x3 x1 x2 x3 x1 x2 x3 x1 x2 x3 x1 x2 x3 x1 x2 x3 x1 x2 x3 value -7 0.06% 11.00% 231.17% 231.69% 186.2 -0. y ) = x 2 − y − 5 xy The partial derivatives can be computed and evaluated at the initial guesses 114 .32% 152.65% Alternatively.91% 144.88 -14.29005 -17.7 The equations to be solved are f 1 ( x .00% 127.10% 179.07% 355.64502 6.67% 140.528 17.687014 -4.4 -2.499999 66.8 x2 x3 x1 x2 x3 0.15008 19.32% 244. they can be ordered as −x + 3y + 5z = 7 2y – z = 1 −2x + 4y − 5z = −3 For this case.5 3.

0 ∂y = −1 − 5 x = −1 − 5(1.6) = 6.94(−3. 0 ∂x ∂f 2.96(−1.2) − 1.075% 0.000% 11.191% 0.94)(−3.233319 1.6) − (−6.4 = 2 x − 5 y = 2(1.4) − (−0.2 The values of the functions can be evaluated at the initial guesses as f 1.6) = 0.2 1.685% 0.2 − − 6.26129 1.5 − 1.234243 1.000% εa2 588.2 = −0.0 ∂x = −2 x + 1 = −2(1.96)(−1) = 1.212245 0.2 2 + 1.0 = −1.96 These values can be substituted into Eq.2 2 − 5(1.∂f 1.2) = −7 They can then be used to compute the determinant of the Jacobian for the first iteration is − 1. 0 ∂y = −1 ∂f 2.2 0.233318 y 1.212245 εa1 4.859% 2. The results are summarized as iteration 0 1 2 3 4 x 1. (11.2 = −6.12) to give x1 = 1.2 − − 0.211619 0.4(−7) − (−1)(−3.2)(1.2) = −3.2 The computation can be repeated until an acceptable accuracy is obtained.2 + 0.26129 6.6 ∂f 1.295% 0.174194 6.2 x 2 = 1.94 f 2.2) + 1 = −1.0 = 1.889% 17.174194 0.8 (a) The equations can be set up in a form amenable to plotting as y = x2 −1 y = 5 − x2 These can be plotted as 115 .2) − 5(1.

391941) 2 − 1 = 0. the solution is moving away from the solution that lies at approximately x = y = 1.5 4 3 2 1 0 -1 0 0. successive substitution does not work First iteration: x = 5 − y 2 = 5 − (1.9375) 2 = 2. For this case.658312) 2 − 1 = 1. An alternative solution involves solving the second equation for x and the first for y.030048) 2 − 1 = 3.5 -2 Thus.581139) 2 = 1.606592) 2 = 1.581139 Second iteration: x = 1.6.12094 Thus. a solution seems to lie at about x = y = 1.5) 2 = 1.5 1 1.75) 2 = 1. the first equation can be solved for x and the second solved for y. For example.030048 y = (2.658312 y = (1.606592 y = 5 − (1.581139 = 1. successive substitution does work First iteration: x = y + 1 = 1.391941 y = (1.555269 Third iteration: 116 . For this case. (b) The equations can be solved in a number of different ways.75 Second iteration: x = 5 − (1.581139 y = 5 − x 2 = 5 − (1.6.9375 Third iteration: x = 5 − (0.5 + 1 = 1.5 2 2.

2 x 2 = 1.6) − (−6.2 + 0.2 The values of the functions can be evaluated at the initial guesses as f 1.94(−3.561553.94 f 2.2)(1. y ) = x 2 − y − 1 f 2 ( x.600485 ψ 1.2 The computation can be repeated until an acceptable accuracy is obtained.2) − 1.2 2 − 5(1. (11.561553 1.604167 1.0 ∂x ∂f 1.6) = 0.12) to give x1 = 1. 0 ∂x ∂f 2.96)(−1) = 1.174194 6.5 1.598521 y = (1.0 = −1.94)(−3.4(−7) − (−1)(−3.6) = 6.600485 and y = 1. 0 = −2 x ∂y = −1 = −2 y They can then be used to compute the determinant of the Jacobian for the first iteration is − 1.2 − − 6.494% 0.598521) 2 − 1 = 1.600489 1.4) − (−0.2 2 + 1.555269) 2 = 1.000% 0.96(−1.5 − 1.2 = −0. y ) = 5 − y 2 − x 2 The partial derivatives can be computed and evaluated at the initial guesses ∂f 1.061% 0. the calculation converges on the solution of x = 1.561553 εa1 6.2 = −6.5625 1.0 = 1. (c) The equations to be solved are f 1 ( x.26129 6.0 = 2x ∂y ∂f 2.563564 After several more iterations.000% 117 εa2 4. The results are summarized as iteration 0 1 2 3 ξ 1.2 − − 0.230% 0.000% .96 These values can be substituted into Eq.5 1.x = 5 − (1.

4 8.023104 0.8624 = 0.121104 0.565504 0.4 9.200704 0.652 12.023104 0. We assume that if a number falls on the border between bins.021904 0.4 9. it is placed in the lower bin.8 9.1 10.063504 0.494267 c.28% 9.703041 25 − 1 sy = s y2 = 0.8 10.2 The data can be sorted and then grouped.8 9.3 10.063504 2.021904 0.3 0.6 9.1 9.8 10.300304 0.7030412 = 0.898704 0.200704 0.4 11.002704 0.9 9.559504 0.725904 0.021904 0.1 The data can be tabulated as i 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Σ y= y (yi – y )2 8.121104 0.559504 0.565504 11.9 241. lower 7.5 9.703041 × 100% = 7.v.CHAPTER 12 12.023104 0.6 8.5 10.204304 3.715904 0.4 10 9.725904 0.8 10.5 upper 8 Frequency 1 118 .069504 0.8624 241.3 = 9. = 0.2 7.9 8.652 25 11.5 9.2 10 9.063504 0.

140625 0.140625 1.140625 119 12 .35 27.8 8.890625 0.390625 0.5 0 4 7 6 5 1 1 Frequency The histogram can then be constructed as 8 7 6 5 4 3 2 1 0 7 8 9 10 11 Bin 12.65 28.175625 2.390625 0.14063 0.390625 0.390625 0.25 26.455625 0.45 27.65 28.65 28.65 27.030625 0.640625 0.5 9 9.05 28.45 27.65 28.65 27.35 28.65 29.85 26.3 The data can be tabulated as i 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 y 28.5 10 10.180625 0.85 28.500625 2.5 11 11.55 29.050625 13.65 27.5 9 9.5 11 8.25 31.65 (yi – y )2 0.140625 0.275625 0.65 27.105625 0.140625 1.35 28.5 10 10.950625 0.65 27.180625 0.680625 2.65 26.805625 0.55 28.

v.0125 = 1.5 27 27.5 Upper 26.85 26.075625 0.5 28 28. = 1.1057512 = 1.5 31 31.600625 33.5 29 29.105751 28 − 1 (b) s y = (c) s y2 = 1.0125 784.5 29 29.625625 0. Lower 26 26.025 28 33.25 26 27 28 Σ (a) y = 26.5 30 30.025 (e) The data can be sorted and grouped.75 27.5 30 30.105751 × 100% = 3.380625 1.222685 (d) c.75 27.5 31 31.95% 28.5 32 Frequency 1 4 3 7 4 6 1 1 0 0 0 1 The histogram can then be constructed as 8 7 Frequency 6 5 4 3 2 1 0 26 27 28 29 30 31 Bin 120 32 .25 784.7 = 28.7 1.5 27 27.5 28 28.

4 The sum of the squares of the residuals for this case can be written as n ∑ (y Sr = i − a1 x i ) 2 i =1 The partial derivative of this function with respect to the single parameter a1 can be determined as ∂S r = −2 ∂a1 ∑ [( y i − a1 x i ) xi ] Setting the derivative equal to zero and evaluating the summations gives ∑y − a1 i ∑x i which can be solved for a1 = ∑y ∑x i i So the slope that minimizes the sum of the squares of the residuals for a straight line with a zero intercept is merely the ratio of the sum of the dependent variables (y) over the sum of the independent variables (x).8100 9.0E+08 1.6879 9. 12.2 × 10 ) − 200.4426 200.2E+10 a1 = 5(1.5 i 1 2 3 4 5 Σ xi 0 20000 40000 60000 80000 200000 yi 9.925.4426) = −3.0225 × 10 −6 = 9.000(48.614) − 200.5682 48.6E+09 6.6278 9.025 + 1.130751. That is.80942 5 5 x iy i 0 194974 387516 577668 765456 1925614 Therefore. between 28. 12.10575096 = 29.4426 x i2 0 4.6E+09 3.7487 9.000 − 3.4E+09 1.4% of the values which is not that far from 68%.10575096 = 26.025 – 1. the line of best fit is (using the nomenclature of the problem) 121 .(f) 68% of the readings should fall between y − s y and y + s y .919249 and 28.000 a0 = 48. Twenty values fall between these bounds which is equal to 20/28 = 71.0225 × 10 −6 10 2 5(1.

000) = 9.487 ⎝ 10 / 28 ⎠ This is close to the standard value of 8.3164 T n= 1 kg 28 g/mole ⎛ 10 ⎞ R = 30.1077 2 R = 0.6431825 12.4 0.000 m can therefore be computed as g = 9.999 0.2 0 0 2 4 6 8 122 10 150 .7 Linear regression gives 0.6 y = 0. 12.0454x + 0.3164T (r2 = 0.999) 12000 10000 8000 6000 -50 0 50 100 ⎛ p⎞V R=⎜ ⎟ ⎝T ⎠ n p = 30.0225 × 10 −6 y The value at 55.80942 − 3.80942 − 3.3164⎜ 3 ⎟ = 8.47 + 30.314 J/gmole.0225 × 10 −6 (55.g = 9.6 Regression gives p = 8100.

a plot of ln(y/x) versus x should yield a straight line with an intercept of lnα4 and an intercept of β4.287854 0.2 0 0 2 4 6 8 10 One alternative that would force a zero intercept is a power fit 0. if the linear slope is valid.832581 1.9024 0.8387 0.45529 -1.0454x.2 0 0 2 4 6 8 10 However. An alternative approach would to assume that the physically-unrealistic non-zero intercept is an artifact of the measurement method.014903 1.18 ln(y/x) 2.1 0. x 0.6 0. 12.3 1.05716 -0.1827x 2 R = 0.30259 123 .4 0. we might try y = 0.4069 y = 0.8 y 0. Therefore.85 0.28 0.80359 -2.5 1.733969 -0.6 0.4 0. if the model holds.75 1.Forcing a zero intercept yields y = 0.35 0.45 1.8602 -1.25 1.2 0.4 0.9 1.7 1.6 0. this seems to represent a poor compromise since it misses the linear trend in the data.55 0.061x 2 R = 0.8 The function can be linearized by dividing it by x and taking the natural logarithm to yield ln( y / x) = ln α 4 + β 4 x Therefore.25 0.

218876 4.5 1 1.5 .279319 2 6 5 4 3 2 2 2.5 2 12.106606 6.9481 ln F 3. β4 = −2.9974 0 0.248495 5.4733 and α4 = e2.4733 x This equation can be plotted together with the data: 2 1 0 0 0.661786 xe −2.248495 4.912023 4.2682 3 2 1 0 -1 -2 -3 2 R = 0.y = -2.688879 3.661786.4733x + 2.995732 3.940171 6.1. m/s 10 20 30 40 50 60 70 80 F.5 1 1.309918 6.302585 2. and the fit is y = 9.721426 7. N 25 70 380 550 610 1220 830 1450 ln v 2.5 2 Therefore.5 4 124 4.2682 = 9.2941 7 R = 0.401197 3.5 3 3. plotted and fit with a straight line v.094345 4.9842x .382027 8 y = 1.9 The data can be transformed.413459 7.

274137 x 1.9842 12.9842 ln x − 1.371489 7..185387 6.9842 and the leading coefficient is e−1.907755 6. This conclusion is based on • • • A power model does not result in a linear plot Bacterial decay is known to follow an exponential model The exponential model by definition will not produce negative values.10 (a) The data can be plotted 2000 1600 1200 800 400 0 0 10 20 30 The plot indicates that the data is somewhat curvilinear.The least-squares fit is ln y = 1.e.802395 6.476972 6. The exponential fit can be determined as t (hrs) 4 8 12 16 20 24 c (CFU/100 mL) 1590 1320 1000 900 650 560 ln c 7. An exponential model (i.274137.2941 The exponent is 1. Therefore.327937 125 . the result is the same as when we used common or base-10 logarithms: y = 0.2941 = 0. a semilog plot) is the best choice to linearize the data.

0532t Consequently the concentration at t = 0 is 1978.y = -0.954243 126 .0532 and the lead coefficient (α1) is e7.5902 = 1978.08 d − 0.63 CFU/100 ml.9887 7.2 6.120574 3 2.201397 3.0532t ⎛ 200 ⎞ ln⎜ ⎟ = −0.0532t ⎝ 1978.63.5902 7.63 ⎠ t= ⎝ = 43.8 6.11 (a) The exponential fit can be determined with the base-10 logarithm as t (hrs) 4 8 12 16 c (CFU/100 mL) 1590 1320 1000 900 log c 3. Here is a plot of the fit along with the original data: 2400 2000 1600 1200 800 400 0 0 10 20 30 (b) The time at which the concentration will reach 200 CFU/100 mL can be computed as 200 = 1978.63e −0.0532x + 7.63 ⎠ ⎛ 200 ⎞ ln⎜ ⎟ 1978. and the fit is c = 1978.0532 12.63e −0. the coefficient of the exponent (β1) is −0.6 2 R = 0.4 6 0 10 20 30 Therefore.

748188 y = -0.63(10) −0.63 ⎠ ⎛ 200 ⎞ log10 ⎜ ⎟ 1978.2 3.9887 0 10 20 30 Therefore.20 24 650 560 2.0231t ⎝ 1978.63 CFU/100 ml.2964 3.1 3 2.0231t ⎛ 200 ⎞ log10 ⎜ ⎟ = −0.0231x + 3.3 3.0231 and the lead coefficient (α5) is 103.63.7 2 R = 0.0231t Consequently the concentration at t = 0 is 1978.302585α 5 127 .812913 2.08 d − 0.8 2.0231 Thus. (b) The time at which the concentration will reach 200 CFU/100 mL can be computed as 200 = 1978. The relationship between β1 and β5 can be developed as in e −α1t = 10 −α 5t Take the natural log of this equation to yield − α 1t = −α 5 t ln 10 or α 1 = 2. the coefficient of the exponent (β5) is −0.9 2.63 ⎠ ⎝ t= = 43. and the fit is c = 1978. the results are identical to those obtained with the base-e model.2964 = 1978.63(10) −0.

342423 0.361728 0.3799 and the lead coefficient is a = 10−0.3821 0.05 70 75 80 85 90 The value of the surface area for a 95-kg person can be estimated as A = 0.96 Therefore.0.4149.1 2.3799 Here is a plot of the fit along with the original data: 2.37 logA = 0. the power is b = 0.954243 log A 0.92 1.88 1.34 m 2 128 .15 2.845098 1.32 0.3821 = 0.8 1.36 2 R = 0.22 2.348305 0.9711 0.15 2.4149(95) 0.35 0.354108 0.939519 1.3 2. and the fit is A = 0.23 2.12 2.26 2.322219 0.31 1.913814 1.1 2.12 The power fit can be determined as W (kg) 70 75 77 80 82 84 87 90 A (m2) 2.346353 0.3799logW .875061 1.25 2.3 log W 1.84 1.3799 = 2.332438 0.35 2.886491 1.12.34 0.33 0.90309 1.924279 1.326336 0.4149W 0.2 2.2 2.

768Mass 0.52288 log Met 3.845098 1.818 = 65.477121 1.748188 3.7497 Here is a plot of the fit along with the original data: 8000 6000 4000 2000 0 0 100 200 300 12. and the fit is Metabolism = 65.778151 0.9997) 129 400 .3 Metabolism (kCal/day) 5600 1700 1100 100 30 log Mass 2. the power is b = 0.13 The power fit can be determined as Mass (kg) 300 70 60 2 0.477121 4 3 2 logMet = 0.12.7497logMass + 1.9935 0 -1 0 1 2 3 Therefore.230449 3.6363 log σ (r2 = 0.041393 2 1.768.818 1 2 R = 0.30103 -0.14 Linear regression of the log transformed data yields logε& = −5.7497 and the lead coefficient is a = 101.41 log B + 2.

2 -3.9 1 1.779 N/m2.685γ& (r2 = 0.685 and τy = 2.7 0.001 0 0 5 10 15 12.15 Linear regression of the data yields τ = 2.002 0.4 -2.004 0.779 + 0. µ = 0.0.6363 and the untransformed model is ε& = 3.2 -2.005 0.41 = 3.8 -3. B = 10 -5.88975 × 10 -6 σ 2.1 1.003 0.6363 A plot of the data and the model can be developed as 0.977121) 8 6 4 2 0 0 2 4 Therefore.6 Therefore. 130 6 .88975 × 10 -6 m = 2.8 0.

56 9.8 0.010724 Linear regression of the transformed data yields log τ = −0.2 Therefore.989118) 1. µ = 10–0.872156 0.12.13808 + 0.113943 log(stress) 0.1 1 0.45 8.041393 2. The power model is therefore.6 1.16 The data can be transformed strain 50 70 90 110 130 stress 5.54298 log γ& (r2 = 0.25 log(strain) 1.8 2 2.99 7.7 0.09 10.72765γ& 0.69897 1.958564 1.72765 and n = 0.6 1.777427 0.9 0.845098 1. τ = 0.54298.932474 0.54298 = 0.954243 2.54298 A plot of the power model along with the data can be created as 12 8 4 0 0 50 100 131 150 .

1 The data can be tabulated and the sums computed as i 1 2 3 4 5 6 7 8 Σ x 10 20 30 40 50 60 70 80 360 y 25 70 380 550 610 1220 830 1450 5135 x2 100 400 900 1600 2500 3600 4900 6400 20400 x3 1000 8000 27000 64000 125000 216000 343000 512000 1296000 x4 10000 160000 810000 2560000 6250000 12960000 24010000 40960000 87720000 xy 250 1400 11400 22000 30500 73200 58100 116000 312850 x2y 2500 28000 342000 880000 1525000 4392000 4067000 9280000 20516500 Normal equations: 360 20400 ⎤ ⎧⎪a 0 ⎫⎪ ⎧⎪ 5135 ⎫⎪ ⎡ 8 20400 1296000 ⎥ ⎨ a1 ⎬ = ⎨ 312850 ⎬ ⎢ 360 ⎢⎣20400 1296000 87720000⎥⎦ ⎪⎩a 2 ⎪⎭ ⎪⎩20516500⎪⎭ which can be solved for the coefficients yielding the following best-fit polynomial F = −178.037202v 2 Here is the resulting fit: 2000 1500 1000 500 0 -500 0 20 40 60 80 100 The predicted values can be used to determined the sum of the squares. Note that the mean of the y values is 641.CHAPTER 13 13.8393 338.6607 ( yi − y) 2 380535 327041 68579 132 (y − ypred)2 1485 7892 1709 .12202v + 0.875.4821 + 16. i x 1 2 3 10 20 30 y 25 70 380 ypred -13.5417 158.

4
5
6
7
8
Σ

40
50
60
70
80

550
610
1220
830
1450

525.9226
720.625
922.7679
1132.351
1349.375

8441
1016
334229
35391
653066
1808297

580
12238
88347
91416
10125
213793

The coefficient of determination can be computed as
r2 =

1808297 − 213793
= 0.88177
1808297

The model fits the trend of the data nicely, but it has the deficiency that it yields physically
unrealistic negative forces at low velocities.
13.2 The sum of the squares of the residuals for this case can be written as

Sr =

∑ (y
n

i

− a1 x i − a 2 x i2

)

2

i =1

The partial derivatives of this function with respect to the unknown parameters can be
determined as
∂S r
= −2
∂a1

∑ [( y

i

− a1 x i − a 2 xi2 ) x i

]

∂S r
= −2
∂a 2

∑ [( y

i

− a1 x i − a 2 x i2 ) xi2

]

Setting the derivative equal to zero and evaluating the summations gives

(∑ x )a + (∑ x )a = ∑ x y
2
i

3
i

1

2

i

(∑ x )a + (∑ x )a = ∑ x
3
i

4
i

1

2

i

2
i yi

which can be solved for
a1 =

a2

∑x y ∑x −∑x y ∑x
∑ x ∑ x − (∑ x )
i

4
i

i

2
i

2
i

i

3
i

3 2
i

4
i

∑x ∑x y −∑x y ∑x
=
∑ x ∑ x − (∑ x )
2
i

2
i

2
i

i

i

4
i

i

3
i

3 2
i

The model can be tested for the data from Table 12.1.

133

x
10
20
30
40
50
60
70
80
Σ

x2
100
400
900
1600
2500
3600
4900
6400
20400

y
25
70
380
550
610
1220
830
1450

a1 =

x3
1000
8000
27000
64000
125000
216000
343000
512000
1296000

x4
10000
160000
810000
2560000
6250000
12960000
24010000
40960000
87720000

312850(87720000) − 20516500(1296000)

a2 =

20400(87720000) − (1296000) 2

xy
250
1400
11400
22000
30500
73200
58100
116000
312850

x2y
2500
28000
342000
880000
1525000
4392000
4067000
9280000
20516500

= 7.771024

20400(20516500) − 312850(1296000)
= 0.119075
20400(87720000) − (1296000)

Therefore, the best-fit model is
y = 7.771024 x + 0.119075 x 2

The fit, along with the original data can be plotted as
2500
2000
1500
1000
500
0
0

20

40

60

80

100

13.3 The data can be tabulated and the sums computed as
i
1
2
3
4
5
6
7
8
Σ

x
3
4
5
7
8
9
11
12
59

y
1.6
3.6
4.4
3.4
2.2
2.8
3.8
4.6
26.4

x2
9
16
25
49
64
81
121
144
509

x3
27
64
125
343
512
729
1331
1728
4859

x4
81
256
625
2401
4096
6561
14641
20736
49397

Normal equations:

134

x5
243
1024
3125
16807
32768
59049
161051
248832
522899

x6
729
4096
15625
117649
262144
531441
1771561
2985984
5689229

xy
4.8
14.4
22
23.8
17.6
25.2
41.8
55.2
204.8

x2y
14.4
57.6
110
166.6
140.8
226.8
459.8
662.4
1838.4

x3y
43.2
230.4
550
1166.2
1126.4
2041.2
5057.8
7948.8
18164

59
509
4859 ⎤ ⎧a 0 ⎫ ⎧ 26.4 ⎫
⎡ 8
509
4859
49397 ⎥ ⎪ a1 ⎪ = ⎪ 204.8 ⎪
⎢ 59
⎢ 509 4859 49397 522899 ⎥ ⎨a 2 ⎬ ⎨1838.4⎬
⎢⎣4859 49397 522899 5689229⎥⎦ ⎪a ⎪ ⎪⎩18164 ⎪⎭
⎩ 3⎭
which can be solved for the coefficients yielding the following best-fit polynomial
y = −11.4887 + 7.143817 x − 1.04121x 2 + 0.046676 x 3

Here is the resulting fit:
8
6
4
2
0
-2

0

5

10

15

The predicted values can be used to determined the sum of the squares. Note that the mean
of the y values is 3.3.
i
1
2
3
4
5
6
7
8
Σ

x
3
4
5
7
8
9
11
12

ypred

y
1.6
3.6
4.4
3.4
2.2
2.8
3.8
4.6

1.83213
3.41452
4.03471
3.50875
2.92271
2.4947
3.23302
4.95946

( yi − y) 2
2.8900
0.0900
1.2100
0.0100
1.2100
0.2500
0.2500
1.6900
7.6000

The coefficient of determination can be computed as
r2 =

7.6 − 1.2997
= 0.829
7 .6

13.4
function p = polyreg(x,y,m)
% polyreg(x,y,m):
%
Polynomial regression.

135

(y − ypred)2
0.0539
0.0344
0.1334
0.0118
0.5223
0.0932
0.3215
0.1292
1.2997

% input:
%
x = independent variable
%
y = dependent variable
%
m = order of polynomial
% output:
%
p = vector of coefficients
n = length(x);
if length(y)~=n, error('x and y must be same length'); end
for i = 1:m+1
for j = 1:i
k = i+j-2;
s = 0;
for l = 1:n
s = s + x(l)^k;
end
A(i,j) = s;
A(j,i) = s;
end
s = 0;
for l = 1:n
s = s + y(l)*x(l)^(i-1);
end
b(i) = s;
end
p = A\b';

Test solving Prob. 13.3:
>> x = [3 4 5 7 8 9 11 12];
>> y = [1.6 3.6 4.4 3.4 2.2 2.8 3.8 4.6];
>> polyreg(x,y,3)
ans =
-11.4887
7.1438
-1.0412
0.0467

13.5 Because the data is curved, a linear regression will undoubtedly have too much error.
Therefore, as a first try, fit a parabola,
>>
>>
>>
>>

format long
T = [0 5 10 15 20 25 30];
c = [14.6 12.8 11.3 10.1 9.09 8.26 7.56];
p = polyfit(T,c,2)

p =
0.00439523809524

-0.36335714285714

Thus, the best-fit parabola would be

c = 14.55190476 − 0.36335714T + 0.0043952381T 2

136

14.55190476190477

8 11.21500 7.395579365T + 0.4 10.61 Thus.35786 10.16 12 8 4 0 0 5 10 15 20 25 30 We can use this equation to generate predictions corresponding to the data.00729523809524 -0.6 12.55855 rounded 14.000064444T 3 We can use this equation to generate predictions corresponding to the data.3) p = -0.6 12.04286 8.8 11.3 10.8 11.00006444444444 0.56 c-pred 14.3 10.c.09 8.09116 8.60020 12.09 8.600238095 − 0.26 7.6 12. 137 . We can.26 7.30949 10.1 9. although the plot looks good.55190 12.26331 7. the best-fit cubic would be c = 14.39557936507936 14. fit a third-order polynomial >> p = polyfit(T. When these values are rounded to the same number of significant digits the results are T 0 5 10 15 20 25 30 c-data 14.1 9.007295238T 2 − 0.56 c-pred 14.8 11.1 9. therefore. discrepancies occur in the third significant digit.26 7.60023809523810 Thus.09048 9.09044 9.04 8.60690 rounded 14. When these values are rounded to the same number of significant digits the results are T 0 5 10 15 20 25 30 c-data 14.3 10.84500 11.1 9.79663 11.09 8. the predictions and data agree to three significant digits.6 12.56 Thus.22 7.

87741631305987 Thus.4 10. A one-to-one line is included to show how the predictions diverge from a perfect fit.3 8.6 The multiple linear regression model to evaluate is o = a 0 + a1T + a 2 c The [Z] and y matrices can be set up using MATLAB commands in a fashion similar to Example 13. This can be seen even better by generating predictions for all the data and then generating a plot of the predictions versus the data.09 8.13.26 7.1 9.20123809523810 -0.10492857142857c We can evaluate the prediction at T = 12 and c = 15 and evaluate the percent relative error as >> cp = a(1)+a(2)*12+a(3)*15 cp = 9.03 8.3 10.52214285714286 − 0.09-cp)/9.3 10.73 6.1 9.85 11.6 12.52214285714286 -0.17 7. the error is considerable.09)*100 ea = 4.20123809523810T − 0. 138 . >> T = [t t t]'.56 12.2]'.35 6.96 8.53335714285714 >> ea = abs((9. The coefficients can be evaluated as >> a = Z\y a = 13.46 6.08 7.4. >> y = [14.9 11. the best-fit multiple regression model is o = 13.8 11. >> format long >> t = [0 5 10 15 20 25 30].10492857142857 Thus. >> c = [zeros(size(x)) 10*ones(size(x)) 20*ones(size(x))]'. >> Z = [ones(size(T)) T c].

08 7.336423T + 0.73 6. 13.00574444444444 -0. Then.10492857c The model can then be used to predict values of oxygen at the same values as the data.03 8.35 6. = [T T T]'.85 11.3 10.09 8. = [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]'.7 The multiple linear regression model to evaluate is y = a 0 + a1T + a 2 T 2 + a 3T 3 + a 4 c The [Z] matrix can be set up as in >> T >> T >> c >> o >> y 7.1 9. the least-squares fit is y = 14.000043704T 3 − 0.1 9. = [14.(13.6 12. = [0 0 0 0 0 0 0 10 10 10 10 10 10 10 20 20 20 20 20 20 20]'. It should be noted that this is particularly the case for the dependency on temperature.027143 − 0. 139 .26 7.10) >> format long >> a = (Z'*Z)\[Z'*y] a = 14.4 10.46 >> Z = 0:5:30.10492857142857 Thus.00574444T 2 − 0. the coefficients can be generated by solving Eq.2]'.3 8.16 12 8 4 4 8 12 16 The cause for the discrepancy is because the dependence of oxygen concentration on the unknowns is significantly nonlinear. These predictions can be plotted against the data to depict the goodness of fit.8 11.17 6. = [o T T.56 12.^2 T.33642328042328 0.02714285714287 -0.96 8.00004370370370 -0.9 11.3 10.^3 c].

y = [15.1 17.09 mg/L. the coefficients can be generated by solving Eq.(13.4609 + 9. x2 = [0 1 2 1 2 1 2 1 2]'.10) >> a = (Z'*Z)\[Z'*y] a = 14.7 45.>> yp = Z*a >> plot(y. the least-squares fit is y = 14.4 40.7043x 2 140 .2]'. >> a(1)+a(2)*12+a(3)*12^2+a(4)*12^3+a(5)*15 ans = 9.16781492063485 which compares favorably with the true value of 9.4609 9.yp. the prediction can be made at T = 12 and c = 15. 13.7043 Thus. Then.5 35.7 25.8 The multiple linear regression model to evaluate is y = a 0 + a1 x1 + a 2 x 2 The [Z] matrix can be set up as in >> >> >> >> >> x1 = [0 1 1 2 2 3 3 4 4]'.1 29.9 12.0252 -5.0252 x1 − 5. Z = [o x1 x2 y]. o = [1 1 1 1 1 1 1 1 1]'.'o') Finally.6 20.

the least-squares fit is log Q = 1.9]'.001 .38 .^2) SST = 1.5609 2.01 .8888 13. the coefficients can be generated by solving Eq.001 . [o log10(D) log10(S)] Then.9 .01 .13 . >> yp = Z*a >> SSR = sum((yp .6 .24 .9978 >> syx = sqrt(SSR/(length(y)-3)) syx = 0.05]'.mean(y)).6 .9 The multiple linear regression model to evaluate is log Q = log α 0 + α 1 log( D) + α 2 log(S ) The [Z] matrix can be set up as in >> >> >> >> >> D S Q o Z = = = = = [. [1 1 1 1 1 1 1 1 1]'. [.31 1.3 .y).9 .10) >> a = (Z'*Z)\[Z'*log10(Q)] a = 1.95 5.0587e+003 >> r2 = (SST .3 .05 .001 .(13. These predictions can be used to determine the correlation coefficient and the standard error of the estimate.^2) SSR = 4.69 .6279 0.04 .82 2. [.5609 + 2.7397 >> SST = sum((y .6279 log( D) + 0.66]'.5320 Thus.3 .9955 >> r = sqrt(r2) r = 0.The model can then be used to predict values of the unknown at the same values as the data.SSR)/SST r2 = 0.6 .01 .5320 log(S ) Taking the inverse logarithm gives 141 .05 .

142 .5t + 4. Then.^2).Im.5*t) exp(-0.3775 Thus.1]'.3t + Ce −0.6279 S 0.10 The linear regression model to evaluate is p (t ) = Ae −1.05*t)].pp) 13.5609 D 2.5320 13.*exp(-Im/a(2)+1).8 3.05t The fit and the data can be plotted as >> pp = Z*a >> plot(t. function f = fSSR(a.1 1.6279 S 0.t.p. the coefficients can be generated by solving Eq.7778e −1.5 1.05t The unknowns can be entered and the [Z] matrix can be set up as in >> p = [7 5.3872e −0.'o'.5 2.5*t) exp(-0.3775e −0.3*t) exp(-0.3813D 2.05*t)]. the least-squares fit is p (t ) = 3.2 1.2 3.7778 4.5 1 2 3 4 5 6 7 8 9]'.8 1.2 2. >> t = [0.10) >> Z = [exp(-1. >> Z = [exp(-1. >> a = (Z'*Z)\[Z'*p] a = 3.5320 = 36.3*t) exp(-0. an M-file function must be created to compute the sum of the squares.3872 1.Pm) Pp = a(1)*Im/a(2).(13.11 First. f = sum((Pm-Pp).3t + 1.Q = 101.5t + Be −0.

6 .2 .1 . >> plot(I. [200.'o'.9 1. The data can then be entered as >> x = [.7124 221.xm.25 1. f = sum((ym-yp). >> Pp = a(1)*I/a(2).7 1. I. The minimization of the function is then implemented by >> a = fminsearch(@fSSR.7124 − +1 I e 221.35 0. function f = fSSR(a.*exp(-I/a(2)+1).3 1. 143 .25 0.18].*exp(a(2)*xm).12 First.^2).9]. an M-file function must be created to compute the sum of the squares.I.P. >> y = [0.ym) yp = a(1)*xm.28 0.8239 The fit along with the data can be displayed graphically.45 1. 200].8239 The best-fit model is therefore I P = 238.8239 221. >> P = [99 177 202 248 229 219 173 142 72].5 1. [].55 0.75 1.85 0.4 .The data can then be entered as >> I = [50 80 130 200 250 350 450 550 700]. P) a = 238.Pp) 13.

737e-5 2.*exp(a(2)*x).The minimization of the function is then implemented by >> a = fminsearch(@fSSR.431e-5 2.063e-8 5.5217 x The fit along with the data can be displayed graphically.x.423e-5 2. >> a = linregr(1.12). >> v0 = [6. x.078e-11 7. a plot of 1/v0 versus 1/[S]3 should yield a straight line with a slope of K/km and an intercept of 1/km.1.5217 The best-fit model is therefore y = 9. [].^3.01 .43e-5 2. y) a = 9.13 (a) The model can be linearized by inverting it.05 ./v0) a = 1. >> S = [. >> yp = a(1)*x.'o'. >> plot(x.788e-6 1. [1.8545 -2. K 1 1 1 = + 3 v0 k m [S ] km If this model is valid.8545 xe −2.64527391375701 4.yp) 13.13997346408367 144 .431e-5].y.595e-9 6. The slope and intercept can be implemented in MATLAB using the M-file function linregr (Fig.1 . 12.5 1 5 10 50 100]./S.0e+004 * 1. 1].

1 .595e-9 6. >> km=1/a(2) km = 2.These results can then be used to compute km and K.S. the best-fit model is v0 = 2.Sm.423e-5 2.01 .v0m) v0p = a(1)*Sm.43e-5 2.431e-5 2. 145 .v0p) (b) An M-file function must be created to compute the sum of the squares.737e-5 2.v0. function f = fSSR(a./(a(2)+Sm.^3.415474419523452e-005 >> K=km*a(1) K = 0.^3. f = sum((v0m-v0p).39741170517893 Thus.5 1 5 10 50 100]. We will use a log-log plot because of the wide variation of the magnitudes of the values being displayed./(K+S.431e-5].078e-11 7.415474 × 10 −5 [ S ]3 0.063e-8 5. >> loglog(S.05 .39741 + [ S ]3 The fit along with the data can be displayed graphically.^3).^2).^3). The data can then be entered as >> S = [. >> v0p = km*S.788e-6 1.'o'. >> v0 = [6.

39976314533880 The best-fit model is therefore v0 = 2. v0) a = 0.399763 + [ S ]3 The fit along with the data can be displayed graphically. [].^3).S.00002430998303 0. [2e-5. >> loglog(S.v0p) 146 . >> v0p = a(1)*S.'o'. 1]. We will use a log-log plot because of the wide variation of the magnitudes of the values being displayed./(a(2)+S.^3.The minimization of the function is then implemented by >> format long >> a = fminsearch(@fSSR.v0. S.431 × 10 −5 [ S ]3 0.

259887 + 0. the point at (5.7 3−4 4−3 147 .7 + (−2.259887 + (3.5) = 4.5) f 2 (3. However.4 − 2.4 − 4) = 5.4 − 3)(3.4 − 4)(3.5 + ( −4.4 − 3)(3.333333) 5−4 f 3 (3.4) = 3 .5333333 − (−2.CHAPTER 14 14.5)(3.1 (a) Newton’s polynomial.7 + − 3.4 − 3)(3.4 − 4) 2.4) = 4.4) = 5.4 − 4) 2 .4 − 3 6 .5) (3.4 − 4 3 .259887 Third order: 0−7 − (−3.5 f(x2) = 2 f(x3) = 7 f(x4) = 0 Note that based purely on the distance from the unknown.333333) (3.5 − (−2.4 − 3) = 4. because it provides better balance and is located only a little bit farther from the unknown. Ordering of points: x1 = 3 x2 = 4 x3 = 2.4 − 2.5 (3.5 x4 = 5 f(x1) = 6.7 + 2.5) 5−3 − 2.5 + 2 − 6.5) 5−3 = 5.333333) − (−2.5 + 2 = 4.5 − 4 (3.333333)(3.259887 + (3.95152 5−3 (b) Lagrange polynomial.333333) 5−4 = 5.4) = 6.4 − 3)(3.4 − 4)(3.4 − 3)(3. First order: f 1 (3. 5). the fourth point would be (2.5 − 3 = 4.4 − 3) = 6.4 − 4)(3.4 − 3)(3.8 − (−3.333333) 5 − 2 .5 − 3 = 4. 0) is chosen.4 − 2. First order: f 1 (3.7 4−3 Second order: 7−2 − (−4.333333 − (−4.

95152 (2.5 Second order: f 2 ( 4) = 12.5 Third order: f 3 (4) = 10.5) (3.25 Fourth 0 Note that the fact that the fourth divided difference is zero means that the data was generated with a third-order polynomial.4 − 4)(3.4 − 2.5 + (4 − 3)(4 − 5)2 = 10.4 − 2.4 − 4) 6.25 = 10 Fourth order: f 3 (4) = 10.5) (4 − 3)(4 − 2.25 Second 2 2.4 − 3)(3.75 Third 0.25 5.5) 7+ 0 = 4.5) (2.5)(3.5 + ( 4 − 3)(4 − 2.2 The points can be ordered so that they are close to and centered around the unknown.75 1.3 Lagrange polynomial.4 − 5) (3.5 + (4 − 3)(4 − 5)(4 − 2)0.25 + 7.5 − 4)(2.4 − 2.5)(3.5 + (4 − 3)(4 − 5)(4 − 2)(4 − 6)0 = 10 14. First order: f 1 (4) = 5.25 + 19.4 − 3)(3.4) = (3.5) (3.5 3−5 5−3 148 .25 8 6.75 First 7.4 − 2.4 − 2.4 − 3)(3.4 − 4)(3.5 + 2+ 7 = 5.4 − 5) 2 6.4 − 5) (3.4 − 3)(3.5)(4 − 5) (3 − 4)(3 − 2.75 4 36 4.259887 (3 − 4)(3 − 2.4 − 4)(3.4 − 4)(3. First order: f 1 ( 4) = 4−5 4−3 5.4 − 3)(3.25 19.5) 14.25(4 − 3) = 12.4) = (3.5 − 4) Third order: f 3 (3.25 0.5 − 5) (5 − 3)(5 − 4)(5 − 2. A divided-difference table can then be developed as x 3 5 2 6 1 f(x) 5.75 = 12.5 − 3)(2.5 − 3)(2.5)(3 − 5) + (3.Second order: f 2 (3.

A divided-difference table can then be developed as T.03 + 8.15(15 − 0) + 0.555 − 9.0026 0.17 first -0.08 − 9. 10 and 15 at c = 15.0025(15 − 0)(15 − 10) = 10.03 11. c = 15) = 9.0026(12 − 10)(12 − 15) = 9.75 (3 − 5)(3 − 2)(3 − 6) (5 − 3)(5 − 2)(5 − 6) + (4 − 3)(4 − 5)(4 − 6) ( 4 − 3)(4 − 5)(4 − 2) 4+ 36 = 10 (2 − 3)(2 − 5)(2 − 6) (6 − 3)(6 − 5)(6 − 2) 14.Second order: f 2 ( 4) = (4 − 5)(4 − 2) (4 − 3)(4 − 2) (4 − 3)(4 − 5) 5.4 (a) The points can be ordered so that they are close to and centered around the unknown.5 (3 − 5)(3 − 2) (5 − 3)(5 − 2) (2 − 3)(2 − 5) Third order: f 3 ( 4) = (4 − 5)(4 − 2)(4 − 6) (4 − 3)(4 − 2)(4 − 6) 5. c = 15) = 12.555 20 − 10 These values can then be used to determine the result at T = 12.53 (12 − 10) = 9.214(12 − 10) + 0.3 8.6564 Third order: f 3 (4) = 9.25 + 19.1 − 0. f 2 (T = 5.96 − 10.25 + 19.003667 third 0.53 + 8.20867 second 0. quadratic interpolation can be used to generate values for T = 5.000107(12 − 10)(12 − 15)(12 − 5) = 9.53 20 − 10 f 1 (T = 15.1 9.14 15 − 10 (c) First. oC 10 15 5 20 c = 10 g/L 10.8 − 0.03 (15 − 10) = 8.6564 + 0.214 -0.1 (15 − 10) = 9.65192 (b) First.227 -0. f 1 (T = 10.1 + 8.000107 Second order: f 2 ( 4) = 10.75 + 4 = 10. c = 15) = 10. f 1 (T = 12.7375 149 . c = 15) = 9. linear interpolation can be used to generate values for T = 10 and 15 at c = 15.

2 0.^2).2500 7./(1+x.3 − 0.07 x 2 = 0.11402714932127 150 0.12(15 − 0) + 0.y. >> fx = [3.1500 1.65158371040724 .00069% after 16 iterations.107(15 − 0) + 0.6 1.644957 0.fx. >> p = polyfit(x.8 1. c = 15) = 11.2) p = -0.93 x= 0.15 x 3 +1. c = 15) = 10.9]. >> format long >> x = [3 4 5].54 These values can then be used to determine the result at T = 12.5 or f ( x) = −0.5225 f 2 (T = 15.2156 is obtained with εa = 0.7375 − 0.00465(12 − 5)(12 − 10) = 9.5000 Therefore. >> x = [1 2 3 4]. a value of 2. >> y = x. the roots problem to be solved is 1.01040723981900 0.25 x + 5.5 x 2 −5.93 x 2 = x 2 0. c = 15) = 10.1016 14.f 2 (T = 10.07 (b) A quadratic interpolating polynomial can be fit to the last three points using the polyfit function. >> p = polyfit(x. Using initial guesses of xl = 2 and xu = 3.3) p = -0.0006(15 − 0)(15 − 10) = 8.15 x 3 +1.6 (a) Analytical: 0.93 + 0.^2.93 = x2 1 + x2 0.5000 -5.9 = 0 Bisection can be employed the root of this polynomial.5 x 2 −5.6 = −0. f 2 (T = 12.93 = 3.5 MATLAB can be used to generate a cubic polynomial through the first 4 points in the table. 14.1 − 0.25 x + 7.243(12 − 5) + 0.0003(15 − 0)(15 − 10) = 9.

01040724)(−0.2714932 or f ( x) = 0.00633484162896 -0.006334842 x 3 − 0.y.6729442 Thus.93 = 0.08642533936652 0.11402715 x + 0.4117647 x + 0.3) p = 0. the best fit quadratic is f 2 ( x) = −0.6515837 or f ( x) = −0.006334842 x 3 − 0.61883 is obtained. the two last points are used for linear interpolation.08642534 x 2 + 0.11402715) = 7.6515837 We must therefore find the root of 0.2784163) 2(0.41176470588235 0.Thus.6585068 Bisection can be employed the root of this polynomial.4117647 x − 0.01040724 x 2 + 0.^2) >> p = polyfit(x.7 (a) Because they bracket the unknown.01040724 x 2 + 0. >> format long >> x = [2 3 4 5].11402715 x − 0.67294421. a value of 3. 14.11402715 x + 0.08642534 x 2 + 0.4117647 x + 0. (c) A cubic interpolating polynomial can be fit to the last four points using the polyfit function. 151 .2784163 The quadratic formula yields x= − 0.2714932 We must therefore find the root of 0./(1+x.006334842 x 3 − 0. Using initial guesses of xl = 3 and xu = 4. >> y=x.01040724 x 2 + 0.08642534 x 2 + 0.2835775 3. the best fit cubic is f 3 ( x) = 0.27149321266968 Thus.93 = −0.^2.11402715) 2 − 4(−0.11402715 ± (0. the estimate is 3.

1074 0.4147 6.0761 Thus.12547 − 0. we can generate this polynomial by subtracting 6.0.6487 0.8950 In MATLAB.2) p = 354.6077 (c) The inverse interpolation can be implemented in MATLAB.f 1 (0.118) ans = 6. the value of the specific volume corresponding to an entropy of 6.3450 >> polyval(p.1144 0.2358 -64.1074.3450 We must therefore find the root of 6.5453 6. p = 354.12547].45 p = 354.45 from the constant coefficient of the polynomial >> p(3)=p(3)-6.2358 -64.2358 -64. T 300 D 1.8 This problem is nicely suited for the Newton interpolating polynomial. we can order the data so that the points are closest to and centered around the unknown. to the level of significance reported in the table the estimated entropy is 6.7664]. >> roots(p) ans = 0.45 = 354. 14.2358 x 2 − 64.45 is 0.139 152 . we can use the roots function to determine the solution.11144) = 6.8950 Then.9976 9.7664 − 6.5453 + 6.3450 or 6.118) = 6.5453 (0.9976 9. as in part (b).2358 x 2 − 64. First.6077 Therefore.11144 (b) The quadratic interpolation can be implemented easily in MATLAB.9976 2. we can fit a quadratic polynomial to the data to yield.s.9976 x + 9.118 − 0.45 = 354. First.9976 x + 2. >> s = [6. >> p = polyfit(v. >> v = [0.10377 0.

the linear estimate is 1.60000E-06 1.367 0.003440 -0.002260 -0.028888 The cubic estimate is also 1.93333E-10 -1.0279 − 2.93333 −10 (330 − 300)(330 − 350)(330 − 400)(330 − 250) = 1.003420 -0.77333E-12 First-order (linear) fit: f 1 (330) = 1. Fifth-order (quintic) fit: f 2 (330) = 1.0287 + 4 × 10 −9 (330 − 300)(330 − 350)(330 − 400) = 1.00000E-09 -4.0358 Thus.350 400 250 450 200 0.00000E-08 -3.00344(330 − 300) = 1.029.0358 + 1. Fourth-order (quartic) fit: f 4 (330) = 1.139 0.02902 153 .76000E-08 fourth -2.0279 The quartic estimate now seems to be diverging slightly by moving to a value of 1.367 0.18000E-05 1.51200E-05 third 4. This may be an initial indication that the higher-order terms are beginning to induce slight oscillations.003796 second 1. Second-order (quadratic) fit: f 2 (330) = 1.028.967 0.77333 −12 (330 − 300)(330 − 350)(330 − 400)(330 − 250)(330 − 450) = 1.967 0.0289 − 2.854 1.854 1.036 to the level of significant digits provided in the original data. Third-order (cubic) fit: f 3 (330) = 1.708 Then we can generate the divided difference table.0287 The quadratic estimate is 1.029 to the level of significant digits provided in the original data.708 first -0.759 1.759 1.18 × 10 −5 (330 − 300)(330 − 350) = 1.003040 -0.16000E-05 7.139 − 0.60000E-11 fifth -2. T 300 350 400 250 450 200 D 1.

0e+003 * -2.854].029. >> format long >> D = [1. MATLAB can be used to fit a cubic polynomial through the four points that bracket this value.0000 0.967 0.) > In polyfit at 78 p = 0.3) Warning: Polynomial is badly conditioned. Inverse interpolation can be now used to determine the temperature corresponding to the value of density of 1.0097 2. Remove repeated data points or try centering and scaling as described in HELP POLYFIT.139 0. >> p = polyfit(T. To do this.139 0.3300 Thus.3670 1. To do this.0000 -0. This acts to both reduce the magnitudes of the temperatures and centers them on zero. Interestingly.8237 0.Oscillations are now evidently occurring as the fifth-order estimate now jumps back up to slightly above a value of 1. we will merely subtract the value at the midpoint of the temperature range (325) from all the temperatures.967 0.0000 0.2130 Then we can use the roots function to determine the temperature that corresponds to this value >> roots(p) ans = 1. (Type "warning off MATLAB:polyfit:RepeatedPointsOrRescale" to suppress this warning.D.3670 1. because of the large values of the temperatures. Now let’s perform the inverse interpolation. On the basis of the foregoing.2420 Let’s disregard this warn and proceed to adjust the polynomial so that it can be used to solve the inverse interpolation problem. we subtract the specified value of the density from the polynomial’s constant coefficient >> p(4)=p(4)-1.029. >> D =[1.854]. First.5938 0.029 p = 0. >> T = [250 300 350 400].0000 -0. I would conclude that the cubic equation provides the best approximation and that a value of 1.0097 3. even though the polynomial is badly conditioned one of the roots corresponds to T = 330 as expected. but with scaling. we get an error message.029 is a sound estimate to the level of significant digits provided in the original data. 154 .

10 Third-order case: The MATLAB polyfit function can be used to generate the cubic polynomial and perform the interpolation.26878060289231 0.D.223891 -0.0000 -0. >> p = polyfit(i.0000 45.V.765198 0. >> polyval(p.0000 148.01681250000000 We can set up the roots problem >> p(4)=p(4)-1.00000000400000 0.0000 The interpolating polynomial is therefore V = 148i 3 + 45i The polyval function can be used to determine the interpolation at i = 0.0.6480 14. we arrive at the expected result of 330.25 0. the cubic fit can be generated with no error message.04581250000000 -0.029 p = 0.5].00496634199799 By adding back the offset of 325.325.511828 0.00001150000000 -0.5) p = 0.0000 -0.>> T = [250 300 350 400].048384].5 1].1.5625 41 193]. >> T = T .0e+003 * -3.25 0.9 A MATLAB session provides a handy way to solve this problem >> i = [-1 -0.00000000400000 0.3) p = 0.00344250000000 0.0000 0. >> Tinv = r(3)+325 Tinv = 3.14874694489127 0. >> p = polyfit(T.00344250000000 1.299663419979927e+002 14. Then.00001150000000 We can then use the roots function to determine the temperature that corresponds to the given density >> r = roots(p) ans = 1. >> J = [0.10) ans = 4.5 -0. 155 .5625 13. >> x = [1 1.5 2 2. >> V = [-193 -41 -13.

1).1. pop = [249.765198 0. >> ea = abs((Jtrue-Jpred)/Jtrue)*100 ea = 5. p = polyfit(ts.>> p = polyfit(x.1955)/35.9673 The built-in function besselj can be used to determine the true value which can then be used to determine the percent relative error >> Jtrue = besselj(0.260052 0.5) p = -0.260052].J.5 3].048384 -0.1.511828 0.2400 -0.J.2461e-004 14.3) p = 0.82) Jpred = 0.3705 0. >> J = [0. First order: >> >> >> >> t = [1990 1980].5 2 2.0035 0.1014 >> Jpred = polyval(p.0045 1.3283 >> Jtrue = besselj(0.4330 0.223891 -0.J.1. >> ea = abs((Jtrue-Jpred)/Jtrue)*100 ea = 0.3284 >> Jtrue = besselj(0.511828 0.0008 >> Jpred = polyval(p.0027 0.0916 -0.82) Jpred = 0.6.5 2 2.223891 -0.0231 -0.1. >> J = [0.82) Jpred = 0. ts = (t . 156 .pop. >> p = polyfit(x.1.82).9409 >> Jpred = polyval(p.1.11 In the same fashion as Example 14.1692 0.46 227.82).0043 Fourth-order case: >> x = [1 1.5 3 0.765198 0.0670 -0.048384 -0.5].0115 -0. >> p = polyfit(x.82) Jtrue = 0.0302 Fifth-order case: >> x = [1 1.3284 0.4) p = -0.3284 >> ea = abs((Jtrue-Jpred)/Jtrue)*100 ea = 0.23]. MATLAB can be used to evaluate each of the cases.938470].

(2000-1955)/35) ans = 273. using higher-order approximations is moving the prediction closer to the actual value of 281. >> polyval(p. >> polyval(p.(2000-1955)/35) ans = 271.4200 Although the improvement is not great. >> p = polyfit(ts.>> polyval(p.05].4).pop.9900 Fourth order: >> t = [t 1950]. >> p = polyfit(ts.67].42 that occurred in 2000.pop. >> ts = (t .1955)/35. >> p = polyfit(ts. >> ts = (t . the addition of each term causes the prediction for 2000 to increase.(2000-1955)/35) ans = 274. >> ts = (t . 157 .6900 Second order: >> t = [t 1970].2). >> pop = [pop 180.27].pop. Thus.1955)/35. >> pop = [pop 152.(2000-1955)/35) ans = 271.3). >> polyval(p. >> pop = [pop 205.1955)/35.7400 Third order: >> t = [t 1960].

xx).31535 5.21) and (15.xx.248963 d 0.16598 c 0 0.52282 -9.y.840249 -1.99585 6.yy) 158 .058091 3.CHAPTER 15 15. yy = spline(x. xx = linspace(1. plot(x.5 3 1 ⎥ ⎪c 4 ⎪ ⎪− 24⎪ ⎢ ⎢ 1 4 1⎥ ⎪c5 ⎪ ⎪ 15 ⎪ ⎢ ⎥⎪ ⎪ ⎪ ⎪ 1⎦⎥ ⎪⎩c6 ⎪⎭ ⎩⎪ 0 ⎭⎪ ⎣⎢ These equations can be solved for the c’s and then Eqs.41909 -5.5 ⎥ ⎪⎪c3 ⎪⎪ ⎪⎪ − 6 ⎪⎪ ⎢ ⎥⎨ ⎬ = ⎨ ⎬ 0.5 2 0.40664 -6.1 (a) The simultaneous equations for the natural spline can be set up as ⎡1 ⎤ ⎧ c1 ⎫ ⎧ 0 ⎫ ⎢1 3 0. y = [1 5 7 8 2 1].5).970954 4.'o'.08299 These can be used to generate the following plot of the natural spline: 10 8 6 4 2 0 0 2 4 6 (b) The not-a-knot spline and its plot can be generated with MATLAB as >> >> >> >> >> x = [1 2 2.5 ⎥ ⎪c ⎪ ⎪ 0 ⎪ ⎪ ⎢ ⎥⎪ 2 ⎪ ⎪ ⎢ 0.029046 -0.087137 -0.414938 -2. (15.5 3 4 5].y.18) can be used to solve for the b’s and the d’s. The coefficients for the intervals can be summarized as interval 1 2 3 4 5 a 1 5 7 8 2 b 3.

yy = interp1(x. plot(x. y = [1 5 7 8 2 1]. particularly between the last points.2 The simultaneous equations for the clamped spline with zero end slopes can be set up as 159 .xx.y.yy) 15.xx.'pchip'). (c) The piecewise cubic Hermite polynomial and its plot can be generated with MATLAB as >> >> >> >> >> x = [1 2 2.y. xx = linspace(1.'o'.5 3 4 5].5).Notice how the not-a-knot version exhibits much more curvature.

⎡ 1 0 .0923 13.7385 106.5 ⎪ ⎢ ⎥⎪ ⎪ ⎪ 0.5 ⎤ ⎧ c1 ⎫ ⎧ 0 ⎫ ⎢0.7077( d − 1) 3 where T = temperature and d = depth.93846 -58.18) can be used to solve for the b’s and the d’s.44615 -3.21) and (15.7077 -66.7538 -24.8615 91.87692 -31.5 2 0. 0 50 100 0 1 2 3 Inspection of the plot indicates that the inflection point occurs in the 3rd interval.66154 -12.5 ⎪ ⎢ ⎥⎪ ⎪ ⎪ c 0 .2462(d − 1) 160 .0769 -5. The cubic equation for this interval is T3 ( x) = 55 − 58.8615(d − 1) 2 + 106. The coefficients for the intervals can be summarized as interval 1 2 3 4 5 6 a 70 70 55 22 13 10 b 0 -7.93846 12.7538 -68.5 1 ⎦ ⎩c7 ⎭ ⎩ ⎭ ⎣ These equations can be solved for the c’s and then Eqs.729 + 640.5 ⎢ ⎥ ⎨c 4 ⎬ = ⎨ 144 ⎬ ⎢ ⎥ ⎪c5 ⎪ ⎪ 36 ⎪ 0.5 2 0.13846 c 15. This equation can be differentiated twice to yield the second derivative d 2T3 ( x) dx 2 = −137.2462 -47.5 ⎥ ⎪c ⎪ ⎪ − 90 ⎪ ⎪ ⎢ ⎥⎪ 2 ⎪ ⎪ ⎢ ⎥ ⎪c3 ⎪ ⎪− 108⎪ 0.5 2 0. (15.5 2 0.55385 d -31.2462(d − 1) − 68. Note that we are plotting the points as depth versus temperature so that the graph depicts how the temperature changes down through the tank. 5 18 ⎪ ⎪ ⎪ ⎪ ⎢ ⎥ 6 ⎪ ⎪ ⎪ ⎪ ⎢ ⎥ 0.2 -7.5538 The fit can be displayed in graphical form. 5 2 0 .

1.'--') (b) The piecewise cubic Hermite polynomial fit can be set up in MATLAB as >> >> >> >> >> >> x = linspace(0./((xx-0.9).^2+0.21511 m.yh.9).04)-6.^2+0.xx.'pchip').04)-6.04)-6.y.^2+0.3 (a) The not-a-knot fit can be set up in MATLAB as >> >> >> >> >> >> x = linspace(0./((xx-0.01)+1. plot(x.04)-6. yh = 1.^2+0.^2+0.yh./((x-0.'--') 161 .9).11).11).xx.1). xx = linspace(0.^2+0.3). yh = 1./((xx-0. y = 1./((xx-0.^2+0.^2+0.9). y = 1.xx.xx).This can be set equal to zero and solved for the depth of the thermocline as d = 1.y. plot(x.xx./((x-0. yy = spline(x.yy.01)+1.1.xx.y./((x-0.3). yy = interp1(x.1).01)+1.'o'. 15.yy.y.'o'./((x-0.3). xx = linspace(0.01)+1.3).

199148 b 0.0018 -0.9E-06 1.00072 c 0 -4.00138 -0. The coefficients for the intervals can be summarized as interval 1 2 3 4 5 6 a 0 0.39E-06 d -1.001489 ⎪ ⎢ ⎪ ⎪ ⎪ ⎪ ⎢ 1 ⎥⎦ ⎩c7 ⎭ ⎩ 0 ⎭ ⎣ These equations can be solved for the c’s and then Eqs.01946⎪ ⎪ ⎢ ⎥⎪ 2 ⎪ ⎪ ⎢ ⎥ ⎪c3 ⎪ ⎪− 0.6E-07 1.1000).21) and (15.4 The simultaneous equations for the clamped spline with zero end slopes can be set up as 0 ⎫ ⎡ 1 ⎤ ⎧ c1 ⎫ ⎧ ⎢100 400 100 ⎥ ⎪c ⎪ ⎪− 0.15.xx.735759 0.xx.824361 1 0.*exp(-xx/200+1).8 0.7E-05 -7.001843 ⎪ 200 800 200 ⎪ ⎢ ⎥⎪ ⎪ ⎪ 200 800 200⎥ ⎪c6 ⎪ ⎪ 0.406006 0. plot(x.yc.yy.2 0 0 500 1000 (b) The not-a-knot fit can be set up in MATLAB as >> >> >> >> >> >> x = [0 100 200 400 600 800 1000].'o'.13E-07 1.*exp(-x/200+1).005128 -0.3E-07 1.4 0.y.'--') 162 .82E-09 -8.7E-06 2.2 1 0.18) can be used to solve for the b’s and the d’s. xx = linspace(0.00923⎪ 100 600 200 ⎪ ⎢ ⎥⎪ ⎪ ⎪ 200 800 200 ⎢ ⎥ ⎨c 4 ⎬ = ⎨− 0.00031 -0. yc = xx/200.y. yy = spline(x.009801 0.3E-09 The fit can be displayed in graphical form as 1.31E-08 2.7E-10 -2.6 0. y = x/200. (15.00098⎬ ⎢ ⎥ ⎪c5 ⎪ ⎪ 0.xx).

y.*exp(-xx/200+1). plot(x.yc.y.6 -0. 15. y = [0 0 0 1 1 1].1000).5 (a) The not-a-knot fit can be set up in MATLAB as >> >> >> >> >> x = [-1 -0. plot(x.yy. xx = linspace(0.2 0.1).yy) 163 . xx = linspace(-1. yy = interp1(x.'--') Summary: For this case.xx).'o'.xx.xx.*exp(-x/200+1). the not-a-knot fit is the best. yc = xx/200.6 1].(c) The piecewise cubic Hermite polynomial fit can be set up in MATLAB as >> >> >> >> >> >> x = [0 100 200 400 600 800 1000].xx.'pchip').y.y. yy = spline(x.xx.2 0.'o'. y = x/200.

y.ys.2 0. xx = linspace(-1.'pchip'). plot(x.y. ys = [0 y 0]. plot(x.6 -0.6 1].2 0.y.xx).'o'.1).6 1]. yy = interp1(x. yy = spline(x.2 0.6 -0. xx = linspace(-1.1).xx. y = [0 0 0 1 1 1].yy) 164 . y = [0 0 0 1 1 1].(b) The clamped spline with zero end slopes can be set up in MATLAB as >> >> >> >> >> >> x = [-1 -0.xx.'o'.xx.2 0.yy) (c) The piecewise cubic Hermite polynomial fit can be set up in MATLAB as >> >> >> >> >> x = [-1 -0.

i+1) = h(x.c(i)) / 3 / h(x. y) .15. i. i).1 a(i) = y(i). i) hh = x(i + 1) . n. d. i. xi) for ii = 1:n . i). x. m = length(xx). % The vector x specifies the points at which the data y is given.6 An M-file function to implement the natural spline can be written as function yy = natspline(x. d.h(x. bb(i) = 3 * (fd(i + 1.1). for i = 1:n .xx) % natspline(x. i .000001 & xi <= x(ii + 1) + 0. b. c. d(i) = (c(i + 1) . function fdd = fd(i. n = length(x).xx): % uses a natural cubic spline interpolation to find yy. a. for i = 2:n-1 aa(i. i) / 3 * (2 * c(i) + c(i + 1)). bb(n) = 0. x. x. aa(i. y) fdd = (y(i) . c.0. xx(i)). aa(n. the values % of the underlying function y at the points in the vector xx.y(j)) / (x(i) . y) . break end end 165 . end function hh = h(x. n. b(i) = fd(i + 1. aa(i. function yyy = SplineInterp(x.n) = 1.1. i . a.1) = 1.y.x(j)).1) + h(x.x(i). i)). x. aa(1. i . y)).i) = 2 * (h(x. b.i-1) = h(x. j.fd(i. end for i = 1:m yy(i) = SplineInterp(x.000001 yyy=a(ii)+b(ii)*(xi-x(ii))+c(ii)*(xi-x(ii))^2+d(ii)*(xi-x(ii))^3.y. bb(1) = 0.1 if xi >= x(ii) . end c = aa\bb'.

5 . These values can then be added to the y vector and the spline function invoked to develop the clamped fit: 166 .0925 x 4 − 1.9125*x.yy.y.9125*xx.xx.3: >> >> >> >> >> x = [3 4.444*x.'--') (b) The function can be differentiated to give f ' ( x) = 0.069 This function can be evaluated at the end nodes to give f'(1) = 6.The program can be used to duplicate Example 15. y = 0.y.'o'.5].^3-15.^2+27.xx.xx.5 7 9].^5-0.1.5 1 2. xx = linspace(3.yy) 15.9).0185*x.7 (a) The not-a-knot fit can be set up in MATLAB as >> >> >> >> >> >> x = [1 3 5 6 7 9].9). plot(x.^4+3.211 and f'(9) = 11.1.069*xx-14. xx = linspace(1.7375 x 2 − 30. yc = 0.'o'. plot(x.0185*xx.y.xx).456*xx.069*x-14. yy = spline(x.xx). yy = natspline(x.y.912 x + 27.787.^3-15. y = [2.^2+27.456*x.^4+3.yc.776 x 3 + 11.^5-0.444*xx.

>> yd = [6.yd.xx). >> plot(x.xx.yy.xx.'--') 167 . >> yy = spline(x.y.211 y 11.787].yc.'o'.

5e − 2 x ] 4 0 = 4 + 0.88%) (c) composite trapezoidal rule n = 2: (4 − 0) 0 + 2(0.47%) . ∫ t 0 ⎛ gc d ⎞ gm tanh ⎜ t ⎟ dt = ⎜ m ⎟ cd ⎝ ⎠ gm 2 gc d2 t gm cd ⎛ gc d ⎞⎤ m ⎡ t ⎟⎥ ⎢ln cosh⎜ ⎜ m ⎟⎥ gc d ⎣⎢ ⎝ ⎠⎦ 0 ⎡ ⎤ ⎛ gc d ⎞ t ⎟ − ln cosh(0)⎥ ⎢ln cosh⎜ ⎜ m ⎟ ⎢⎣ ⎥⎦ ⎝ ⎠ Since cosh(0) = 1 and ln(1) = 0.500167731 (b) single application of the trapezoidal rule (4 − 0) 0 + 0.CHAPTER 16 16.5e − 2 ( 0 ) = 3. this reduces to ⎛ gc d ⎞ m t⎟ ln cosh⎜ ⎜ m ⎟ cd ⎝ ⎠ 16.86466 + 0.999665 = 3.35%) n = 4: (4 − 0) 0 + 2(0.3437 8 (d) single application of Simpson’s 1/3 rule 168 (ε t = 4.981684 + 0.96303 4 (ε t = 15.999665 = 2.2 (a) The analytical solution can be evaluated as ∫ 4 0 [ (1 − e − 2 x ) dx = x + 0.99752) + 0.5e − 2 ( 4 ) − 0 − 0.1 A table of integrals can be consulted to determine 1 ∫ tanh dx = a ln cosh ax Therefore.99329 2 (ε t = 42.999665 = 1.981684) + 0.

999665 = 3.28427 6 (ε t = 6.19%) 16. 169 (ε t = 0.42518 ⎜ − 0⎟ 12 ⎝2 ⎠ (f) Simpson’s 3/8 rule.17%) (e) composite Simpson’s 1/3 rule (n = 4) (4 − 0) 0 + 4(0.47059 12 (ε t = 0.12132) + 6 = 12.18%) (c) composite trapezoidal rule n = 2: ⎛π ⎞ 9 + 2(8.14805) + 6 = 12.0550%) ⎜ − 0⎟ 6 ⎝2 ⎠ (e) composite Simpson’s 1/3 rule (n = 4) ⎛π ⎞ 9 + 4(8.25%) n = 4: ⎛π ⎞ 9 + 2(8.12132 + 7.84%) (f) Simpson’s 3/8 rule.3111%) (d) single application of Simpson’s 1/3 rule ⎛π ⎞ 9 + 4(8.388365 8 (ε t = 3.78097 ⎜ − 0⎟ ⎝2 ⎠ 2 (ε t = 5. ( 4 − 0) 0 + 3(0.981684) + 0.86466 + 0.99752) + 2(0.7716 + 7.26896 ⎜ − 0⎟ 4 ⎝2 ⎠ (ε t = 1.386125 ⎜ − 0⎟ 8 ⎝2 ⎠ (ε t = 0.424778 (b) single application of the trapezoidal rule ⎛π ⎞9+6 = 11.999665 = 3.995172) + 0.14805) + 2(8.4316 (ε t = 0.981684) + 0.12132) + 6 = 12.12132) + 6 = 12.930517 + 0.(4 − 0) 0 + 4(0.77164 + 8.999665 = 3.0032%) .3 (a) The analytical solution can be evaluated as ∫ π /2 0 (6 + 3 cos x) dx = [6 x + 3 sin x ]0 π /2 = 6(π / 2) + 3 sin(π / 2) − 6(0) − 3 sin(0) = 12.

7%) 6 (e) composite Simpson’s 1/3 rule (n = 4) (4 − (−2)) − 29 + 4(1.6%) n = 4: (4 − (−2)) − 29 + 2(1. (4 − (−2)) − 29 + 3(1 + 31) + 1789 = 1392 8 (ε t = 26.0243%) 16.3125) + 1789 = 1516.875 8 (ε t = 37.9375 + (−2) + 131.42779 ⎜ − 0⎟ 8 ⎝2 ⎠ (ε t = 0.⎛π ⎞ 9 + 3(8. (4 − (−2)) 7(−29) + 32(1.5) + 6 = 12.3%) (c) composite trapezoidal rule n = 2: (4 − (−2)) − 29 + 2(−2) + 1789 = 2634 4 (ε t = 138.3125) + 7(1789) = 1104 90 170 (ε t = 0%) .9375 + 131.4%) (d) single application of Simpson’s 1/3 rule (4 − (−2)) − 29 + 4(−2) + 1789 = 1752 (ε t = 58.59808 + 7.3125) + 2( −2) + 1789 = 1144.4 (a) The analytical solution can be evaluated as 4 ∫ 4 −2 ⎡ x2 x6 ⎤ − x4 + ⎥ (1 − x − 4 x + 2 x ) dx = ⎢ x − 2 3 ⎦ −2 ⎣ 3 =4− 5 (−2) 2 ( −2) 6 46 42 − 44 + − (−2) + + (−2) 4 − = 1104 3 2 3 2 (b) single application of the trapezoidal rule (4 − (−2)) − 29 + 1789 = 5280 2 (ε t = 378.9375) + 12(−2) + 32(131.09%) (g) Boole’s rule.5 12 (ε t = 3.6685%) (f) Simpson’s 3/8 rule.

09524 + 0.60653 0.195395 = 0.49659 0.1 − 0) 0.49659 + 0.1 − 0) 0.30119 = 0.90484 + (0.3 − 0.0131%) 6 16.38674 0.95 − 0.7 − 0.35%) (c) Trapezoidal and Simpson’s Rules (0.7) 0.1) + (0.110312 + 0.30119 + (0.698897 (ε t = 0.90484 + 0.38674) + 0.2 − 0.2 0 = −e −1.1) 2 8 + (1.085992 = 0.110416 + 0.60653 + 0.5 (a) The analytical solution can be evaluated as ∫ 1.33333( −2) + 4(−2) 3 − 2(−2) 4 = 21.90484 + (0.7) + (1.16.69880579 (b) Trapezoidal rule (0.7 − 0.5 − 0.6 (a) The integral can be evaluated analytically as.33333 y − 4 y 3 + 2y4 ] 2 -2 21.33333( 2) − 4(2) 3 + 2(2) 4 − 21.90484 + 3(0.33333 (b) The composite trapezoidal rule with n = 2 can be used the evaluate the inner integral at the three equispaced values of y.74082 + 0.70126 (ε t = 0. y = −2: (4 − 0) − 12 + 2(−24) − 28 = −88 4 y = 0: (4 − 0) 0 + 2(4) + 16 = 24 4 171 .49659 1 + 0.2 0 [ e − x dx = − e − x ] 1.2 − (−e 0 ) = 0.33333 − 12 y 2 + 8 y 3 dy [21.2 − 0.38674 + 0.60653) + 0.134735 + 0.49659 + 4(0.74082 + 0.09524 + 0.74082 1 + 0.164566 + 0.957) 2 2 2 + (0. 4 ∫ 2 ⎡ x3 2 3 x ⎤ − + 3 y x y ⎢ ⎥ dy −2 3 2 ⎦0 ⎣ ∫ ( 4) 3 ( 4) 2 − 3 y 2 ( 4) + y 3 dy −2 3 2 ∫ 2 2 2 −2 21.3) 2 2 2 0.40826 + 0.5) = 0.

66667 6 y = 0: (4 − 0) 0 + 4(4) + 16 = 21.33333 which is perfect 16.33333 − 0 × 100% = 100% 21.33333 = 21.33333 6 which represents a percent relative error of εt = 21.66667 + 4(21.33333 6 y = 2: (4 − 0) − 12 + 4(8) + 36 = 37. (c) Single applications of Simpson’s 1/3 rule can be used the evaluate the inner integral at the three equispaced values of y. 6 ⎡ x4 4 ∫ ∫ −4 0 4 6 −4 0 ∫ ∫ 3 ⎤ ⎢ − 2 yzx ⎥ dy dz = ⎣ 4 ⎦ −1 20 − 8 yz dy dz = 4 6 −4 0 ∫ ∫ 20 − 8 yz dy dz ∫ [20 y − 4 zy ] 4 −4 2 6 0 dz = 172 ∫ 4 120 − 144 z dz −4 .33333 6 These results can then be integrated in y to yield (2 − (−2)) − 90.33333) + 37. y = −2: ( 4 − 0) − 12 + 4(−24) − 28 = −90.33333 − 21.(4 − 0) y = 2: − 12 + 2(8) + 36 = 40 4 These results can then be integrated in y to yield − 88 + 2(24) + 40 =0 4 (2 − (−2)) which represents a percent relative error of εt = 21.33333 × 100% = 0% 21.33333 which is not very good.7 (a) The integral can be evaluated analytically as.

4

[

120 − 144 z dz = 120 z − 72 z 2

−4

]

4
−4

= 120(4) − 72(4) 2 − 120(−4) + 72(−4) 2 = 960

(b) Single applications of Simpson’s 1/3 rule can be used the evaluate the inner integral at
the three equispaced values of y for each value of z,

z = −4:
y = 0:

(3 − (−1))

− 1 + 4(1) + 27
= 20
6

y = 3:

(3 − (−1))

23 + 4(25) + 51
= 116
6

y = 6:

(3 − (−1))

47 + 4(49) + 75
= 212
6

These results can then be integrated in y to yield
( 6 − 0)

20 + 4(116) + 212
= 696
6

z = 0:
y = 0:

(3 − (−1))

− 1 + 4(1) + 27
= 20
6

y = 3:

(3 − (−1))

− 1 + 4(1) + 27
= 20
6

y = 6:

(3 − (−1))

− 1 + 4(1) + 27
= 20
6

These results can then be integrated in y to yield
( 6 − 0)

20 + 4( 20) + 20
= 120
6

z = 4:
y = 0:

(3 − (−1))

− 1 + 4(1) + 27
= 20
6

y = 3:

(3 − (−1))

− 25 + 4(−23) + 3
= −76
6

173

(3 − (−1))

y = 6:

− 49 + 4(−47) − 21
= −172
6

These results can then be integrated in y to yield
( 6 − 0)

20 + 4(−76) − 172
= −456
6

The results of the integrations in y can then be integrated in z to yield
( 6 − 0)

696 + 4(120) − 456
= 960
6

which represents a percent relative error of

εt =

960 − 960
× 100% = 0%
960

16.8 (a) The trapezoidal rule can be implemented as,

d = (2 − 1)

7 + 8 .5
5.5 + 7
6 + 5.5
5+6
+ (3.25 − 2)
+ (4.5 − 3.25)
+ (6 − 4.5)
2
2
2
2

+ (7 − 6)

7+5
7+7
6+7
6+6
8 .5 + 6
+ (8 − 7)
+ (8.5 − 8)
+ (9.3 − 8.5)
+ (10 − 9.3)
= 58.425
2
2
2
2
2

(b) The polynomial can be fit as,
>>
>>
>>
>>

format long
t = [1 2 3.25 4.5 6 7 8 8.5 9.3 10];
v = [5 6 5.5 7 8.5 6 6 7 7 5];
p = polyfit(t,v,3)

p =
-0.00657842294444
4.46645555949356

0.01874733808337

The cubic can be plotted along with the data,
>> tt = linspace(1,10);
>> vv = polyval(p,tt);
>> plot(tt,vv,t,v,'o')

174

0.56859435273356

The cubic can then be integrated to estimate the distance traveled,
d=

10

− 0.006578t 3 + 0.018747t 2 + 0.568594t + 4.46646 dt

1

[

]

10

= − 0.001645t 4 + 0.006249t 3 + 0.284297t 2 + 4.46646t 1 = 58.14199

16.9

D
0

ρgw(z)(60 – z)

ρgzw(z)(60 – z)

z
60
50
40
30
20
10
0

w(z)
200
190
175
160
135
130
122

f t = 60

7.1809 + 4(6.3765 + 4.7088 + 1.8639) + 2(5.2974 + 3.4335) + 0
× 10 7 = 2.5480 × 10 9
3(6)

ρgzw( z )( D − z ) dz = 60

d=

0
1.8639E+07
3.4335E+07
4.7088E+07
5.2974E+07
6.3765E+07
7.1809E+07

0
9.3195E+08
1.3734E+09
1.4126E+09
1.0595E+09
6.3765E+08
0

0 + 4(0.63765 + 1.4126 + 0.93195) + 2(1.0595 + 1.3734) + 0
× 10 9 = 5.5982 × 1010
3(6)

5.5982 × 1010
= 21.971
2.5480 × 10 9

16.10 (a) Trapezoidal rule:
f = 30

0 + 2(54.937 + 51.129 + 36.069 + 27.982 + 19.455) + 13.311
= 996.1363
2(6)

175

30
f =

0 + 2( 274.684 + 511.292 + 586.033 + 559.631 + 486.385) + 399.332
2(6)
13088.45
=
= 13.139 m
996.1363
996.1363

(b) Simpson’s 1/3 rule:
f = 30

30
f =

0 + 4(54.937 + 36.069 + 19.455) + 2(51.129 + 27.982) + 13.311
= 1042.294
3(6)

0 + 4( 274.684 + 586.033 + 486.385) + 2(511.292 + 559.631) + 399.332
3(6)
13215.97
=
= 12.6797 m
1042.294
1042.294

176

5% is iteration → εt → εa → 1 2 4 8 1 20.87500000 25.94133333 33.CHAPTER 17 17.87808000 Thus.0000% 0.1613% 1.14585 x 2 + 2 x 0 = 34.84320000 21.5% is iteration → εt → εa → 1 2 4 1 6.0000% 2.8256% 9.8333 12 ( 2 ) ⎥ x ⎦1 1 2 3 3 The tableau depicting the implementation of Romberg integration to εs = 0. I= ∫ 2 1 2 3⎞ ⎛ ⎜ 2 x + ⎟ dx = x⎠ ⎝ ⎡ 4x 3 I =⎢ + 12 x − ⎣ 3 ∫ 2 1 4 x 2 + 12 + 9 x − 2 dx 2 4( 2) 3 9 9⎤ 9 4(1) 3 = + − − − 12(1) + = 25.8646(4 + 4 x d ) 3 − 4.01094 x 5 + 0.2 (a) The integral can be evaluated analytically as.87808000 4 0. the result is 25.31250000 25.000000% 34.81973333 3 0.1699% 27.62500000 26. (c) The transformations can be computed as x= (8 + 0) + (8 − 0) x d = 4 + 4 xd 2 dx = 8−0 dx d = 4dx d 2 These can be substituted to yield I= ∫ [− 0.6908% 25.93760000 33.94453333 34.0048% 0.9355% 27. 17.9064% 19.83709184 3 0. the result is exact.6766% 34.83456463 Thus.87808 (b) The tableau depicting the implementation of Romberg integration to εs = 0.91680000 30.83456.95594388 2 0.1562(4 + 4 x d ) 2 + 6.2917(4 + 4 x d ) + 2 4dx d 177 .0098% 25.1 The integral can be evaluated analytically as.84920000 2 42.3854 x 3 + 3. [ ] 8 I = − 0.21615 x 4 − 1.0547(4 + 4 x 1 −1 d ] ) 4 + 0.87808000 34.

^4+0. >> I = quad(y.5555556 f (−0.38491615 55.5+1. (c) Using MATLAB >> format long >> I = quad(inline('x.1562*x.83949598 2 5.2917*x+2').774596669) = 34. (b) The transformations can be computed as x= (3 + 0) + (3 − 0) x d = 1.87808 which is exact.0.27625849 44.8646*x.5dx d The transformed function can be evaluated using the values from Table 17.8 %.5x 1 −1 d ] )e1. (d) >> format long >> y = inline('-0.8) I = 34.*exp(x)').5350% 90.5 + 1.5% is iteration → εt → εa → 1 2 4 1 119.17107385 (a) The tableau depicting the implementation of Romberg integration to εs = 0.The transformed function can be evaluated using the values from Table 17.1020% 0.21305531 which represents a percent relative error of 0.5 xd 1.1 I = 0.0.577350269) + f (0.3579% 41.102 %.8579% 43.5 + 1.5 x d 2 dx = 3−0 dx d = 1.^3-4.0547*x.5555556 f (0.774596669) + 0.6075058 which represents a percent relative error of 3.3) 178 .5dx d 2 These can be substituted to yield I= ∫ [(1.577350269) = 39.57337260 41.8888889 f (0) + 0.1 I = f (−0.8349% 26.^2+6. the analytical solution can be evaluated simply as I= ∫ 3 0 [ ] 3 xe x dx = e x ( x − 1) 0 = 41.3 Although it’s not required.36057514 3 0.87808000000000 17.

577350269) = 0. >> I = quadl(inline('x.3) I = 41.1131% 847.0922% 1027.5555556 f (0.965502083 which represents a percent relative error of 0.835 %.17107466800178 which represents a percent relative error of 2×10−6 %.22995126 4 0.86564547 933.035826% 1051.75dx d 2 These can be substituted to yield I= 2 π ∫ 1 −1 [e − ( 0.75+ 0.*exp(x)').5 − 0 dx d = 0.20139037 2 19.67034112 1020.75 x d 2 dx = 1.1×10−8 %.75dx d The transformed function can be evaluated using the values from Table 17.75 xd ) 2 ]0.774596669) + 0. 17.1 I = 0.5555556 f (−0.5 (a) The tableau depicting the implementation of Romberg integration to εs = 0.774596669) = 0.4 The exact solution can be evaluated simply as >> format long >> erf(1.75 + 0.5% is iteration → εa → 1 2 4 8 1 199.1 I = f (−0.49455856 1051.66621287 685.974173129 which represents a percent relative error of 0.04507345 179 3 1.I = 41.96610514647531 (a) The transformations can be computed as x= (1.8888889 f (0) + 0. 17.17107385090233 which represents a percent relative error of 1.60670352 .5 + 0) + (1.577350269) + f (0. (b) The transformed function can be evaluated using the values from Table 17.93212300 1016.062 %.5 − 0) x d = 0.5) ans = 0.27190634 1049.0.

21768866 15.41111155 4 0.085280043451920e+003 The quadl function converges rapidly.93396 (c) Interestingly.577350269) + f (0.30) Warning: Maximum function count exceeded.6 The integral to be evaluated is I= ∫ (10e 1/ 2 0 −t sin 2πt ) 2 dt (a) The tableau depicting the implementation of Romberg integration to εs = 0. (b) The transformations can be computed as x= (30 + 0) + (30 − 0) x d = 15 + 15 x d 2 dx = 30 − 0 dx d = 15dx d 2 These can be substituted to yield I = 200 ∫ ⎡ 15 + 15 x d − 2.38523686. (Type "warning off MATLAB:quad:MaxFcnCount" to suppress this warning.00000000 15.48081663 15.0.) > In quad at 88 I = 1.5(15+15 xd ) / 30 ⎤ e ⎢ ⎥ 15dx d −1 22 + 15 x d ⎣ ⎦ 1 The transformed function can be evaluated using the values from Table 17. singularity likely.Note that if 8 iterations are implemented. the method converges on a value of 1053.5*x/30)').055900924411335e+003 17.0. the quad function encounters a problem and exceeds the maximum number of iterations >> format long >> I = quad(inline('200*x/(7+x)*exp(-2.40142910 2 25.30) I = 1.025340% 15.1% is iteration → εa → 1 2 4 1 0.5*x/30)').41501768 .0000% 20.16326649 15.0824% 15. This result is also obtained if you use the composite Simpson’s 1/3 rule with 1024 segments.16502516 15.1 I = f (−0. but does not yield a very accurate result: >> I = quadl(inline('200*x/(7+x)*exp(-2.577350269) = 1162.41546811 180 3 2.

0725% 12.098313% 13.375dx d 2 .25 + 0.577350269) + f (0.375 x d 2 181 dx = 0.8 15.313728 = 11.25dx d 2 These can be substituted to yield I= ∫ [10e 1 − ( 0.684096 + 4.74249225 13.1 I = 0.8888889 f (0) + 0.14200015 2 25.25dx d For the two-point application.5 − 0 dx d = 0.375 + 0.684915) = 15.75 0 r ⎞ ⎛ 10⎜1 − ⎟ ⎝ 0.25 x d ) 0.5555556 f (0.5555556(2.25 + 0.1 I = f (−0.*sin(2*pi*x)).0.65755 (c) >> format long >> I = quad(inline('(10*exp(-x).75 + 0) + (0.237449) + 0.75 − 0 dx d = 0.25 xd ) −1 ] 2 sin 2π (0.67030554 12.88063803 13.41260804934509 17.0000% 10.73199355 4 0.41195836 (b) The transformations can be computed as x= (0.99782 For the three-point application.74550712 (b) The transformations can be computed as x= (0.5 + 0) + (0.5555556 f (−0.5555556(1.75 ⎠ 1/ 7 2πr dr (a) The tableau depicting the implementation of Romberg integration to εs = 0.0.8888889(15.774596669) = 0.774596669) + 0.55755148 13.25 x d 2 dx = 0.^2').5 − 0) x d = 0. the transformed function can be evaluated using the values from Table 17.00000000 8.577350269) = 7. the transformed function can be evaluated using the values from Table 17.7 The integral to be evaluated is I= ∫ 0.67014971 3 1.75 − 0) x d = 0.1% is iteration → εa → 1 2 4 8 1 0.5) I = 15.16327) + 0.25 + 0.00272915 11.

4179% 317.375 + 0. the transformed function can be evaluated using the values from Table 17.86219465 323.375 x d )⎥ 0.5t + 2e 0.43168560836254 17.*x').34961426 4 0.5*x)+2*exp(0.577350269) = 14.8) I = 3.26095167 340.223483672542467e+002 17.9 (a) The integral can be evaluated analytically as.1 I = f (−0.15*x))') >> I = quadl(y.15t ) dt (a) The tableau depicting the implementation of Romberg integration to εs = 0. 4 ∫ ⎡ x3 x2 ⎤ − 3y 2 x + y 3 ⎢ ⎥ dy −2 3 2 ⎦0 ⎣ ∫ ( 4) 3 ( 4) 2 − 3 y 2 ( 4) + y 3 dy −2 3 2 ∫ 2 2 2 −2 21.59571622 322.75 ⎠ ⎢⎣ ⎝ ⎥⎦ ∫ 1 For the two-point application.47335665 2 7.8 The integral to be evaluated is ∫ I= 8 2 (9 + 4 cos 2 0.0.34374398 3 0.77171 (c) >> format long >> I = quad(inline('10*(1-x/0.25568988 322.577350269) + f (0.75).1054% 322.001212% 322.2.*(5*exp(-0.15529472 322.0.^(1/7)*2*pi.33333 − 12 y 2 + 8 y 3 dy 182 .68170896 326.375 + 0.^2).75) I = 14.4*x).4t )(5e −0.375dx d −1 0.1% is iteration → εa → 1 2 4 8 1 411.375 x ⎞1 / 7 ⎤ d I= ⎢10⎜1 − ⎟ 2π (0.These can be substituted to yield 2 ⎡ ⎛ 0.34570788 (b) >> format long >> y = inline('(9+4*cos(0.

3333 183 .^2+x*y.^2-3*y.[21. >> dblquad(inline('x.2) ans = 21.0.33333( −2) + 4(−2) 3 − 2(−2) 4 = 21.-2.4.33333( 2) − 4(2) 3 + 2(2) 4 − 21.^3').33333 (b) The operation of the dblquad function can be understood by invoking help.33333 y − 4 y 3 + 2y4 ] 2 -2 21. >> help dblquad A session to use the function to perform the double integral can be implemented as.

5 dt y ∫ The integrals can be evaluated to give.37932 0.269586 0.1 (a) The analytical solution can be derived by the separation of variables.109863 Euler method (h = 0.351837 0.25 1.5t + C 4 ln y = Substituting the initial conditions yields C = 0.5 -0.92773 -0.25 0.040434 (c) Midpoint method (h = 0.5 -0.5 1 1.17324 0.5 0.5 2 y 1 0.03906 0.5): t 0 0.303162 0.188424 0.625 0.415156 1.60976 184 dym/dt -0.92773 -0.074707 0.5 -0.25): t 0 0.25 0.5 1 1. Substituting this value and taking the exponential gives y = et 4 / 4 −1.591802 dy/dt -1.75 ym 0.25795 0.25 0.25 1.625 0.34375 -0.078125 0.54047 -0.344153 1. t4 − 1.5 2 y 1 0.536133 0.75 1 1.346471 0.393066 0.353292 .75 1.5 1.73718 -0.113525 dy/dt -1.529695 dy/dt -1.164871 0.2781 -0.75 2 y 1 0.058594 0.183548 0.778417 tm 0.09421 0.5) t 0 0.5t (b) Euler method (h = 0.CHAPTER 18 18. ∫ dy = t 3 − 1.13737 2.

9034 k3 -1.6615 -0.25) RK4 2 M idpoint 18.5 1 1. Substituting this value and rearranging gives ⎛ x2 + x + 2 ⎞ ⎟ y = ⎜⎜ ⎟ 2 ⎝ ⎠ 2 Some selected value can be computed as x y 0 0.75 1.5 1 1.3883 0.5 2 ye 0.7008 ym 0.5 Euler (h=0.5) Analytical 1 1.75 k2 -0. ∫ dy y ∫ = 1 + 2 x dx The integrals can be evaluated to give.25 1.75 1.3404 0.1736 4.5 2 y 1.890625 2.(d) RK4 (h = 0.25 0.25 0.2869 0.1429 3.3154 0.4269 0.25 1.5 0.2511 0.7681 0.3157 0.5) t 0 0.1435 0.5131 k1 -1.9277 -0.5489 tm 0.6250 0.3960 0.1170 k4 -0.0000 0. 2 y = x + x2 + C Substituting the initial conditions yields C = 2.75 ym 0.2676 0.5912 -0.2 (a) The analytical solution can be derived by the separation of variables.1186 tm 0.2786 .0378 -0.4300 0.336914 1.3738 2.75 1 1.1401 -0.7607 All the solutions can be presented graphically as 3 2 1 0 0 0.5000 -0.3584 2.6720 13.1338 0.25 0.4866 te 0.1138 2.5 Euler (h=0.4811 0.743164 185 φ -1.

1

4

(b) Euler’s method:

y (0.25) = y (0) + f (0,1) h
f (0,1) = (1 + 2(0)) 1 = 1
y (0.25) = 1 + 1(0.25) = 1.25
y (0.5) = y (0.25) + f (0.25,1.25)0.25
f (0.25,1.25) = (1 + 2(0.25)) 1.25 = 1.67705
y (0.5) = 1.25 + 1.67705(0.25) = 1.66926
The remaining steps can be implemented and summarized as
x
0
0.25
0.5
0.75
1

y

dy/dx

1
1.25
1.66926
2.31526
3.26626

1
1.67705
2.584
3.804
5.42184

(c) Heun’s method:

Predictor:
k1 = (1 + 2(0)) 1 = 1
y (0.25) = 1 + 1(0.25) = 1.25
k 2 = (1 + 2(0.25)) 1.25 = 1.6771
Corrector:
y (0.25) = 1 +

1 + 1.6771
0.25 = 1.33463
2

The remaining steps can be implemented and summarized as
x

y

0
0.25
0.5
0.75
1

1
1.33463
1.88364
2.72772
3.97099

k1
1.0000
1.7329
2.7449
4.1290

xe
0.25
0.5
0.75
1

ye
1.25
1.76785
2.56987
3.75996

186

k2
1.6771
2.6592
4.0077
5.8172

dy/dx
1.3385
2.1961
3.3763
4.9731

(d) Ralston’s method:

Predictor:
k1 = (1 + 2(0)) 1 = 1
y (0.1875) = 1 + 1(0.1875) = 1.1875
k 2 = (1 + 2(0.1875)) 1.1875 = 1.49837
Corrector:
y (0.25) = 1 +

1 + 2(1.49837)
0.25 = 1.33306
3

The remaining steps can be implemented and summarized as
x

y

k1

0
0.25
0.5
0.75
1

1
1.33306
1.87974
2.72069
3.95998

1
1.73187
2.74208
4.12363

x + 3/4h
0.1875
0.4375
0.6875
0.9375

y + (3/4)k1h
1.1875
1.65779
2.39388
3.49387

k2
1.49837
2.41416
3.67464
5.37392

dy/dx
1.3322
2.1867
3.3638
4.9572

(e) RK4
x
0
0.25
0.5
0.75
1

y
1.0000
1.3369
1.8906
2.7431
3.9998

k1
1
1.73436
2.74997
4.14056

xm
0.125
0.375
0.625
0.875

0

0.2

ym
1.1250
1.5537
2.2343
3.2606

k2
1.32583
2.18133
3.36322
4.96574

xm
0.125
0.375
0.625
0.875

k3
1.34961
2.2202
3.42043
5.04368

ym
1.1657
1.6096
2.3110
3.3638

4
3
2
1
0
0.4

0.6

Euler

Heun

RK4

Ralston

0.8
Analytical

187

1

xe
0.25
0.5
0.75
1

ye
1.3374
1.8919
2.7457
4.0040

k4
1.73469
2.75096
4.14253
6.00299

φ
1.3476
2.2147
3.4100
5.0271

18.3 (a) Heun’s method:

Predictor:
k1 = −2(1) + (0) 2 = −2
y (0.5) = 1 + (−2)(0.5) = 0
k 2 = −2(0) + 0.5 2 = 0.25
Corrector:
y (0.5) = 1 +

− 2 + 0.25
0.5 = 0.5625
2

The remaining steps can be implemented and summarized as
t

y

0
0.5
1
1.5
2

1
0.5625
0.53125
0.82813
1.41406

k1
-2.0000
-0.8750
-0.0625
0.5938
1.1719

xi+1
0.5
1
1.5
2

yi+1
0
0.125
0.5
1.125

k2
0.2500
0.7500
1.2500
1.7500

dy/dt
-0.875
-0.0625
0.59375
1.17188

(b) As in Part (a), the corrector can be represented as

y i1+1 = 1 +

− 2 + (−2(0) + 0.5 2 )
0.5 = 0.5625
2

The corrector can then be iterated to give
y i2+1 = 1 +

− 2 + (−2(0.5625) + 0.5 2 )
0.5 = 0.28125
2

y i3+1 = 1 +

− 2 + (−2(0.28125) + 0.5 2 )
0.5 = 0.421875
2

The iterations can be continued until the percent relative error falls below 0.1%. This
occurs after 12 iterations with the result that y(0.5) = 0.37491 with εa = 0.073%. The
remaining values can be computed in a like fashion to give
t
0
0.5
1
1.5

y
1.0000000
0.3749084
0.3334045
0.6526523

188

2

1.2594796

(c) Midpoint method

k1 = −2(1) + (0) 2 = −2
y (0.25) = 1 + (−2)(0.25) = 0.5
k 2 = −2(0.5) + 0.25 2 = −0.9375
y (0.5) = 1 + ( −0.9375)0.5 = 0.53125
The remainder of the computations can be implemented in a similar fashion as listed below:
t
0
0.5
1
1.5
2

y
1
0.53125
0.48438
0.77344
1.35547

dy/dt
-2.0000
-0.8125
0.0313
0.7031

tm
0.25
0.75
1.25
1.75

ym
0.5
0.328125
0.492188
0.949219

dym/dt
-0.9375
-0.0938
0.57813
1.16406

(d) Ralston’s method:

k1 = −2(1) + (0) 2 = −2
y (0.375) = 1 + (−2)(0.375) = 0.25
k 2 = −2(0.25) + 0.375 2 = −0.3594
y (0.25) = 1 +

− 2 + 2( −0.3594)
0.5 = 0.54688
3

The remaining steps can be implemented and summarized as
t

y

0
0.5
1
1.5
2

1
0.54688
0.50781
0.80078
1.38477

k1
-2.0000
-0.8438
-0.0156
0.6484

t + 3/4h
0.375
0.875
1.375
1.875

y + (3/4)k1h
0.25
0.230469
0.501953
1.043945

All the versions can be plotted as:

189

k2
-0.3594
0.3047
0.8867
1.4277

dy/dt
-0.9063
-0.0781
0.58594
1.16797

4 8.87 3807.73 62.25 59.61 3483.95 .8 y = 0.69 4355.80 k1 45.5 1 1.76 62.11 81.1.5 1 0.80 70. The estimate of the population growth rate is kg = 0.53 2916.84 56.63 54. a semi-log plot (ln p versus t) should yield a straight line with a slope of kg.04 67. along with the linear regression best fit line is shown below.60 3052.06 3193.31 k2 47.06 80.81 74.29 64.81 3645.49 51.6 R = 0.15 3335.00 2792.66 3984.97 80.82 77.68 73.60 φ 47.4 (a) The solution to the differential equation is p = p0 e kgt Taking the natural log of this equation gives ln p = ln p 0 + k g t Therefore.66 61.46 3051.66 4161.84 3984. The plot.5 2 Heun without corr Ralston M idpoint Heun with corr 18.00 67.26.91 56.82 77.2 8 7.41 84.41 4556.64 3645.91 k3 47.40 pmid 2668.9976 2 8.808 8.84 190 pmid 2673.78 k4 49.64 3490. 8.0178x .55 3187.45 3814.5 0 0 0.94 56.80 70.77 74.52 51.85 4169.43 51.92 67.29 64.48 4354.64 54.8 1940 1960 1980 2000 (b) The ODE can be integrated with the fourth-order RK method with the results tabulated and plotted below: t 1950 1955 1960 1965 1970 1975 1980 p 2555.41 49.0178/yr.00 pend 2792.99 3335.54 4548.58 2922.25 59.02 4759.

18 59.29 56.0 1975.90 8488.17 12650.2 3116.3 3271.5 191 ym 2690.50 126.09 14468.0 1980.5 1982.06 6791.52 73.45 15112.74 9260.97 75.46 101.68 115.23 58.555)e −0.85 256.74 224.23 196.06 110.36 68.8 4096.68 4980.57 126.57 92.1 52.45 120.98 75.79 164.35 126.2 2.15 72.5 1982.93 144.79 84.0 1985.13 61.5 1967.67 9690.54 5201.31 5949.52 13213.21 6502.5 (a) The analytical solution can be used to compute values at times over the range.43 8112.8 4453.98 6489.89 5685.03 5433.75 6791.43 5443.16 257.97 11082.8 k3 54.4 5010.6 k4 φ 56.5 1962.12 196.98 215.86 245.29 235.8 3425.3 3116.99 63.555 12.13 7106.5 1967.6 k2 54.5 1977.99 63.00 76.3 4271.2 4635.59 172.47 12089.17 59.000 − 2.90 180.05 150.36 96.5 1972.14 72.5 1962.1 3589.46 101.95 75.72 131.9 3752.7 2966.74 15111.5 1972.5 2971.22 9690.52 73.63 71.89 196.59 179.61 214.25 205.89 te 1955.88 tm 1952.05 110. (b) The ODE can be integrated with the fourth-order RK method with the results tabulated and plotted below: t 1950 1955 1960 1965 1970 1975 1980 1985 p-rk4 k1 2555.5 1977.55 73.79 150.02 7752.026(1955−1950) Values at the other times can be computed and displayed along with the data in the plot below.06 61.17 5202.61 88.68 8866.44 120.37 13238.70 10139.63 71.69 105.71 131.06 70.30 257.5 ym 2685.0 ye 2826.1985 1990 1995 2000 2005 2010 2015 2020 2025 2030 2035 2040 2045 2050 4759.81 65.93 144.25 8472.75 105.3 5202.86 215.74 115.2 3924.76 12651.5 1987.37 68.52 96.00 tm 1952.3 5012.38 12112.14 88.4 4823.84 11061.54 115.0 1970.5 1957.6 4638. For example.000 = 2.76 4971.85 11575.77 268.43 7766.27 58.87 245.41 68.826.81 8112.09 61.64 67.60 7422.20 58.555 + (12.80 180.82 75.0 4453.76 9277.57 105.31 138.24 205.24 137.66 71.88 234.6 3425.24 188.64 6214.60 172.5 1987.82 75.6 3584.0 1965.04 5937.86 .86 7093.01 16000 12000 8000 4000 0 1950 1970 1990 2010 2030 2050 18.24 10590.6 4095.9 3920.5 4823.25 188.07 137.35 6213.40 11575.88 164.27 8866.87 65.25 7422.97 150.15 5685.2 4274.0 1990.20 157.61 13827.8 3752.74 10591.47 96.96 13826.0 2826.16 235.83 65.20 10120.62 54.11 14441.19 157.60 164.5 1957. the value at t = 1955 can be computed as p = 2.0 1960.44 88.64 67.60 92.75 224.06 70.6 3266.

71 76.72 1995.7 7133.43 64. >> [t.21 73.09 70. 18.8 9415.80 62.21 71.1 9141.5 1997.75 62.56 54.5 2012.1 8537.5 2047.06 74.53 54.0 8208.1).23 71.5 1997.61 52.77 75.28 58.90 77.6 9415.0 2005. else % chute is opened dv = 9.1 77. the RK4 results are so close to the analytical solution that the two results are indistinguishable graphically.50 54.5 6943.2 77.23 58.9 7864. The Eulode function can then be used to generate results and display them graphically.8 9000.20 77.04 74. >> plot(t.83 68.6 7321.5 2027.2 8209.0 9283.2 77.81 .98 65.1990 1995 2000 2005 2010 2015 2020 2025 2030 2035 2040 2045 2050 5202.05 60.9 7319.62 77.1 6172.0 5782.4 6172.0 2030.5 2037.41 56.32 76.5 2047.5 6945.63 78.0 7505.32 76.7 8849.85 69.0 2020.71 76.5 5394.07 74.0.5 2042.5 2022. we develop a function to compute the derivative function dv = dvdt(t.0 2000.29 76.7 6367.5 2012.47 67.98 65.65 1992.94 77.3 8995.5 2002. end Notice how we have used an If statement to use a higher drag coefficient for times after the cord is pulled.47 67.[0 30].0 2035.v] = Eulode(@dvdt.87 77.5 8373.5 2027.25/80*v^2.21 77.41 56.5/80*v^2.0 2045.82 68.5 2007. v) if t < 10 % chute is unopened dv = 9.62 1992.8 6367.5 2032.3 5977.0 2010.9 8849.5 2042.0.00 77.76 62.0 2015.21 73.18 77.0 76.63 78.43 64.0 2025.5 2032.8 7134. 18.5 2017.6 We can solve this problem with the M-file Eulode (Fig.3 8693.v) 192 .5 2037. First.5 5783.09 70.91 77.7 6561.9 7504.68 10000 8000 6000 4000 2000 0 1950 1970 1990 pdata 2010 2030 panal 2050 p-rk4 Thus.2 8377.5 2017.00 77.4 6753.9 7687.6 8040.0.0 2050.5 2002.5 5395.0 7864.4 5588.20 71.9 8537.4 7684.81 .90 77.25 58.04 60.0 2040.77 75.94 77.5 5977.3).0 5588.01 65.73 77.5 2022.2 9278.5 8697.2 6753.5 6560.0 9141.5 2007.5 8036..

10035 5 4 3 y z 2 1 0 0 0.4) = −2(2) + 5(4)e −0 = 16 k1.7 (a) Euler’s method: t 0 0.2.84568 -1.1 0.4 (b) 4th-order RK method: k1. 2 = f 2 (0.3632 0.368 -3.18.3 0.730691 3.4 y z 2 3.35114 -3.77687 -3.05) = 2.99072 dz/dt -16 -10.05) = 3.810147 dy/dt 16 3.05) = 4 − 16(0.3 0.353004 4 2.2 193 .6 3.68486 -1.2.4) = − 2( 4) 2 = −16 2 y (0.965805 3.1 0.994714 0.2 0.2 0.1 = f 1 (0.8 z (0.4 1.658049 -2.05) = 2 + 16(0.

194 .2832) 2 = −13.480984.2832 k 3.480984 z (0.1) = 4 − 13. φ1 = 16 + 2(9.065342(2. 2 = f 2 (0.2832) = −2(2.149986 A plot of these values can be developed.628615 The remaining steps can be taken in a similar fashion and the results summarized as t 0 0.065342 z (0.05.1) = 3.1 0.1. 2 = f 2 (0.662824) = − 3.8) + 5(3.3718 2 y (0.05) = 4 − 14.65342 k 3.k 2. 2 = f 2 (0.1) = 2 + 10.1) = 2.05) = 2 + 9.3.05.065342.05 = 10.065342) + 5(3.2.8.8(3.336(0.05) = 2.3.1) = 2 + 10.662824) = −2(3.1.2) = − 2.301983 3.1 = f 1 (0.107758 z 4 2.3.3718(0.3.2832) = − 2.05.65342(0.410581 1.1 = f 1 (0.1) = 3.05) = 3.7139(0.041043 3.662824 k 4.336 2 y (0.2) 2 = −14.619671 + 10.916431 k 4.336 − 13.05.8.2.342571 3.1) = 4 − 13.041043 z (0.4 y 2 3.2.662824) 2 = −10.2832)e −0.3 0.8676 2 The k’s can then be used to compute the increment functions.41043(0.1 = f 1 (0.2 0.619671 k 2.2.628615 1.3.480984(3.2)e −0.65342) + 5.8676 = −13.2.05 = 9.1) = 2.3718) − 10.41043 6 φ2 = − 16 + 2(−14.480984) + 5(3.916431 = 10.065342.619671(0.2832)e −0.3.1 = 5.480984.7139 6 These slope estimates can then be used to make the prediction for the first step y (0.2) = −2( 2.2.845308 1.

4 y (h = 0.5 4 3 y z 2 1 0 0 0.8 0.1 0.2 0.9 0.67847 .4848014 z (h = 0.289 -1.2 0.26711 1.19 1.25901 (b) Euler (h = 0.552 -1.18743 dz/dt -1 -1. t 0 0.2 1.1).1344072 -0. dy =z dt dz = (1 − y 2 ) z − y dt (a) Euler (h = 0.620015 0.3 0.4 0.7711 0.134407 -0.4 18.1) 1 1.4896 0. The remainder of the computation would be implemented in a similar fashion and the results displayed in the plot below.8 0.8 y (h = 0. Here are the first few steps. The remainder of the computation would be implemented in a similar fashion and the results displayed in the plot below.2).455757 195 dz/dt -1 -1.45792 1.36 1.4557574 dy/dt 1 0.6200145 0.187433 dy/dt 1 0.77596 -1.3291115 z (h = 0.3 0.1 0.1) 1 0.2) 1 0.51085 -1.2 0. Here are the first few steps.2) 1 1.4896 0.6 0.6092 -1.7711 0.9 0. t 0 0.8 The second-order van der Pol equation can be reexpressed as a system of 2 first-order ODEs.1 1.64257 -1.

y (h = 0.619 -3. t 0 0.73 0.91 0.2129 yanalytical 1 0.9 -1.57 -4.19 -6.8 -2. The remainder of the computation would be implemented in a similar fashion and the results displayed in the plot below.2 0.619 -3.4 4 3 2 1 0 -1 0 -2 -3 -4 -5 yEuler zEuler dy/dt 1 1 0.1) z (h = 0.276 dz/dt -9 -9 -8.9 -1. Here are the first few steps along with the analytical solution.362358 yEuler yanal 1 2 196 3 4 .3 0. dy =z dt dz = −9 y dt (a) Euler.825336 0.955336 0.2) z (h = 0.62161 0.9 The second-order equation can be reexpressed as a system of two first-order ODEs.8 -2.1 0.2) 4 3 2 1 0 -1 0 2 4 6 8 10 -2 -3 -4 18.276 0 -0.1) y (h = 0.4681 0 -0.

7975(0. 2 = f 2 (0.8798 k 4.5950 = −8.5950 The k’s can then be used to compute the increment functions.9775. 2 = f 2 (0.45 k 3.1 = f 1 (0.0.1) = −0.1.45)(0.−0.45) = −0.1) = 1 − 0.45) = −9(1) = −9 y (0.9550 z (0.−0.1.−0.1) = −0.7975 y (0.0.05.1) = 0. 2 = f 2 (0.1.9775.05) = 1 + 0(0.9775) = −8.45 k 2.−0.−0.1.8865 The remaining steps can be taken in a similar fashion and the first few results summarized as 197 .45) − 0.8798) = −9(0.1) = 0 − 8.0.1) = 0. 2 = f 2 (0.1) = 1 + (−0.9550) = −8.05) = 1 z (0.1) = 0 − 8. φ1 = 0 + 2(−0.0) = z = 0 k1.45 k 3.1 = f 1 (0.05) = 0 − 9(0.45)(0.45 − 0.1 = f 1 (0.9553 z (0.05.(b) RK4.4466(0.05) = 0.0.05) = −0.4466 6 φ2 = − 9 + 2(−9 − 8.45 k 2. Here are the first few steps along with the analytical solution.05.1.45) = −0. The remainder of the computation would be implemented in a similar fashion and the results displayed in the plot below.8798 = −0.7975) − 8.45) = −9(0.05.8650 6 These slope estimates can then be used to make the prediction for the first step y (0.8798 k 4.9775 z (0.05) = 0 − 9(0.05) = 1 + ( −0.1.9550.8650(0.05) = −0.0) = −9 y = −9(1) = −9 y (0.8798) = −0.1 = f 1 (0.9550. k1.−0.

0000 0. maxit = 50.y0.36236 0.3624 0. end %if es blank set to 0.10 A MATLAB M-file for Heun’s method with iteration can be developed as function [t.h.9553 0.6938 -2.3 0. assign default values if nargin<6. end %if maxit blank set to 50 if nargin<5. tf = tspan(2).82534 0.tspan. A plot of all the values can be developed and indicates the same close agreement.62161 0.3498 -2.001.maxit) % [t.8865 -1.1 0.0708 z 0.y] = Heun(dydt.7960 -2. add an additional value of t 198 4 .00000 0.t 0 0.y] = Heun(dydt.4 0.07074 As can be seen. n = length(t). tf] where ti and tf = initial and % final values of independent variable % y0 = initial value of dependent variable % h = step size % es = stopping criterion (%) % optional (default = 0.5 y 1.h): % uses the midpoint method to integrate an ODE % input: % dydt = name of the M-file that evaluates the ODE % tspan = [ti. es = 0.es.001 ti = tspan(1). % if necessary.8253 0.9924 yanal 1. the results agree with the analytical solution closely.tspan.y0. t = (ti:h:tf)'.001) % maxit = maximum iterations of corrector % optional (default = 50) % es = (optional) stopping criterion (%) % maxit = (optional) maximum allowable iterations % output: % t = vector of independent variable % y = vector of solution for dependent variable % if necessary.0000 -0.2 0.95534 0. 4 3 2 1 0 -1 0 -2 -3 -4 -5 yRK4 yanal 1 2 3 18.6216 0.

0953 4.p]) 1.026*(1-p/12000)*p.8261 3. n = n+1.9950 2. >> disp([t. k2 = feval(dydt.t(i)+hh. if y(i+1) ~= 0.9800 1.1165 3. %preallocate y to improve efficiency iter = 0. y(i+1) = y(i) + (k1+k2)/2*hh. k1 = feval(dydt. for i = 1:n-1 hh = t(i+1) .5.y(i+1)).4527 4. First. Then the M-file can be invoked as in >> [t. y(i+1) = y(i) + k1*hh.9759 The following plot is generated 199 .0.9650 1. end y = y0*ones(n. while (1) yold = y(i+1).t(i).9850 1.0000 2. iter = iter + 1.9600 1.y) Here is the test of the solution of Prob.2555.8222 5. break. end if ea <= es | iter >= maxit.p]=Heun(@dpdt.t(i).9500 1. ea = abs((y(i+1) .% so that range goes from t = ti to tf if t(n)<tf t(n+1) = tf.7523 4.yold)/y(i+1)) * 100.1).9900 1. p) dp = 0.2012 5.9700 1.9550 1.5868 5.y(i)).5550 2. an M-file holding the differential equation is written as function dp = dpdt(t.[1950 2000].9750 1.5.4256 3. end end end plot(t.0e+003 * 1. 18.1).

18.tspan. end y = y0*ones(n.y0.t(i).h): % uses the midpoint method to integrate an ODE % input: % dydt = name of the M-file that evaluates the ODE % tspan = [ti.y(i)). add an additional value of t % so that range goes from t = ti to tf if t(n)<tf t(n+1) = tf. k1 = feval(dydt.026*(1-p/12000)*p. tf] where ti and tf = initial and % final values of independent variable % y0 = initial value of dependent variable % h = step size % output: % t = vector of independent variable % y = vector of solution for dependent variable ti = tspan(1). n = n+1. t = (ti:h:tf)'.t(i)+hh/2. tf = tspan(2). p) dp = 0.h) % [t. end plot(t.11 A MATLAB M-file for the midpoint method can be developed as function [t. ymid = y(i) + k1*hh/2. y(i+1) = y(i) + k2*hh. 200 . k2 = feval(dydt. an M-file holding the differential equation is written as function dp = dpdt(t. n = length(t).t(i).y] = midpoint(dydt.y) Here is the test of the solution of Prob.ymid).1).y0. First.y] = midpoint(dydt. 18. %preallocate y to improve efficiency for i = 1:n-1 hh = t(i+1) . % if necessary.tspan.5.

1163 1.8260 1.7521 1.5881 2.4253 1. % if necessary. tf] where ti and tf = initial and % final values of independent variable % y0 = initial value of dependent variable % h = step size % output: % t = vector of independent variable % y = vector of solution for dependent variable ti = tspan(1).9776 The following plot is generated 18.9850 4.2555.2021 1.h) % [t.9600 3.9650 3.p]) 1.y] = rk4(dydt.y0.tspan.y] = rk4(dydt.p]=midpoint(@dpdt.8227 1.9500 2.Then the M-file can be invoked as in >> [t. >> disp([t.y0.9900 5.9550 2.0e+003 * 1.5550 1.[1950 2000].h): % uses the fourth-order Runge-Kutta method to integrate an ODE % input: % dydt = name of the M-file that evaluates the ODE % tspan = [ti.12 A MATLAB M-file for the fourth-order RK method can be developed as function [t.0953 1.9950 5.5).9800 4.9700 3.4529 1. add an additional value of t 201 .tspan. tf = tspan(2).9750 4. t = (ti:h:tf)'. n = length(t).0000 5.

9000 3.0. k1 = feval(dydt.y) Here is the test of the solution of Prob. ymid = y(i) + k2*hh/2.5000 1. phi = (k1+2*(k2+k3)+k4)/6.t(i)+hh. y(i+1) = y(i) + phi*hh. an M-file holding the differential equation is written as function dy = dydx(x. ymid = y(i) + k1*hh/2.2544 0.t(i).1130 0.y(i)). >> disp([x.t(i)+hh/2.2000 1.0000 0.8906 0.0000 4.[0 1].% so that range goes from t = ti to tf if t(n)<tf t(n+1) = tf.ymid). k3 = feval(dydt.yend). Then the M-file can be invoked as in >> [x. n = n+1. %preallocate y to improve efficiency for i = 1:n-1 hh = t(i+1) .6000 2.4280 0. k2 = feval(dydt.7000 2.t(i)+hh/2.ymid).3000 1.y]) 0 1.6384 0.1. First.1).9584 0. 18.1).1000 1. k4 = feval(dydt.4410 1. y) dy = (1+2*x)*sqrt(y). end plot(t.t(i).1904 0. yend = y(i) + k3*hh.2.8000 2. end y = y0*ones(n.y] = rk4(@dydx.0000 The following plot is generated 202 .5440 0.4000 1.

k31 = feval(dy1dt.t(i)+hh/2.1).ymid2).ymid1. k21 = feval(dy1dt.dy2dt. k11 = feval(dy1dt.y2] = rk42(dy1dt.tspan.y2(i)). %preallocate y's to improve efficiency y2 = y20*ones(n. % if necessary.t(i).y10.y20. 203 . ymid1 = y1(i) + k21*hh/2. ymid1 = y1(i) + k11*hh/2.t(i). k12 = feval(dy2dt.t(i)+hh/2.h) % [t.t(i)+hh/2. The first program shown below is strictly developed to solve 2 equations.18.ymid2).ymid2).tspan. tf = tspan(2).y2] = rk42(dy1dt. n = n+1. add an additional value of t % so that range goes from t = ti to tf if t(n)<tf t(n+1) = tf.y20.ymid1.1). n = length(t).y1. ymid2 = y2(i) + k12*hh/2.y1(i). ymid2 = y2(i) + k22*hh/2.y2(i)). function [t.y1(i).y10.t(i).h): % uses the fourth-order RK method to integrate a pair of ODEs % input: % dy1dt = name of the M-file that evaluates the first ODE % dy2dt = name of the M-file that evaluates the second ODE % tspan = [ti. tf] where ti and tf = initial and % final values of independent variable % y10 = initial value of first dependent variable % y20 = initial value of second dependent variable % h = step size % output: % t = vector of independent variable % y1 = vector of solution for first dependent variable % y2 = vector of solution for second dependent variable ti = tspan(1). for i = 1:n-1 hh = t(i+1) .dy2dt. end y1 = y10*ones(n.13 Note that students can take two approaches to developing this M-file. k22 = feval(dy2dt.ymid1.y1. t = (ti:h:tf)'.

phi1 = (k11+2*(k21+k31)+k41)/6.h) 204 .ymid2). phi2 = (k12+2*(k22+k32)+k42)/6.1). 18.3000 3.y2.1078 1.4].t(i)+hh.8453 0.'--') Here is the test of the solution of Prob.1000 3.t(i)+hh/2.k32 = feval(dy2dt. >> disp([t.y1.y1. M-files holding the differential equations are written as function dy = dy1dt(t.t(i)+hh. yend1 = y1(i) + k31*hh. end plot(t.4106 0.6286 0.4000 3.@dy2dt.0000 4.yend1. y1.yend2).y2]) 0 2.tspan. First.0000 0.t. yend2 = y2(i) + k32*hh.1500 The following plot is generated A better approach is to develop an M-file that can be used for any number of simultaneous first-order ODEs as in the following code: function [t.2. y1(i+1) = y1(i) + phi1*hh.4. function dy = dy2dt(t.7. y2) dy = -y1*y2^2/2.3020 1.y1.yend1.y2]=rk42(@dy1dt.0410 2.2000 3.ymid1.y0. y2) dy = -2*y1 + 5*y2*exp(-t). y1. Then the M-file can be invoked as in >> [t. k41 = feval(dy1dt.y] = rk4sys(dydt. k42 = feval(dy2dt.3426 1. y2(i+1) = y2(i) + phi2*hh.yend2).0.[0 0.

y] = rk4sys(dydt.:) + phi*hh.'--') This code solves as many ODEs as are specified.y]=rk4sys(@dydtsys.ymid)'.y0.0. k3 = feval(dydt.y(:. First.3020 1.% [t.:) = y(i.y]) 0 2.h): % uses the fourth-order RK method to integrate a pair of ODEs % input: % dydt = name of the M-file that evaluates the ODEs % tspan = [ti.:) = y0.-y(1)*y(2)^2/2].4000 3. phi = (k1+2*(k2+k3)+k4)/6.ymid)'. for i = 1:n-1 hh = t(i+1) . ymid = y(i. y(i+1.3426 1.t(i)+hh. y) dy = [-2*y(1) + 5*y(2)*exp(-t).4106 0. tf] where ti and tf = initial and % final values of independent variable % y0 = initial values of dependent variables % h = step size % output: % t = vector of independent variable % y = vector of solution for dependent variables ti = tspan(1). add an additional value of t % so that range goes from t = ti to tf if t(n)<tf t(n+1) = tf.8453 0.:) + k3*hh.t(i)+hh/2.y(:. n = n+1. ymid = y(i. t = (ti:h:tf)'.yend)'.1078 1.:) + k2*hh/2.1000 3.:) + k1*hh/2. a single M-file holding the differential equations can be written as function dy = dydtsys(t. k4 = feval(dydt.1500 205 .2).t(i)+hh/2.t.[2 4]. end plot(t.tspan.1).:))'.3000 3.0410 2.[0 0.t(i). >> disp([t.4].6286 0. 18.0000 0.7.1).0000 4. k1 = feval(dydt. tf = tspan(2). end y(1. k2 = feval(dydt. yend = y(i.t(i). Here is the test of the solution of Prob.y(i.2000 3. n = length(t). Then the M-file can be invoked as in >> [t. % if necessary.

k1.1206 -0.5399 2.5 x 2.0096 The computation can be continued and the results plotted versus time: 16 x y 12 8 4 0 0 5 10 15 20 25 30 Notice that the amplitudes of the oscillations are expanding.6093 1. This is also illustrated by a state-space plot (y versus x): 16 12 8 4 0 0 4 8 12 16 (b) RK4.3985 1.9519 0.9639 0.6 k1.1) = 1.2497 2.1607 -0. Here is the first step in detail.0000 0.2000 -0.1) = −0. Here are the first few steps t 0 0.2.1 206 .7008 y 1. 2 = f 2 (0.9(1) + 0.7171 dy/dt -0.CHAPTER 19 19.1200 2.0000 2.4 0.9800 0.1 (a) Euler’s method.3896 2.4(2)(1) = −0.0359 0.1 0.7(2)(1) = 1.9404 dx/dt 1.5028 1.1 = f 1 (0.3 0.2.2 0.2000 1.5(2) − 0.2974 1.9440 0.0791 -0.

1) = 2 + 1.083564.0.993588 1.0.167179.167179 y (0.67128 k 2.0.743808 k 4.05) = 0.1 = f 1 (0.1.1) = 0.2.6(0.083564. 2 = f 2 (0.08.67128 + 1.6 + 2(1. 2 = f 2 (0.06682(0.1) = 2.995) = 1.05.0.1(0.1) = 0.1 = f 1 (0.05) = 1 − 0. φ1 = 1.x(0.042891 207 .671785 k 3.05.06766 x(0.996617) = 1.05.03291 = −0.3 0.05) = 0.671656 6 φ2 = − 0.348838 2.993365) = 1.1) = 2 + 1.2.545029 2.03291 The k’s can then be used to compute the increment functions.0.16766 y (0.05) = 2 + 1.755314 2.2.2.993318 The remaining steps can be taken in a similar fashion and the first few results summarized as t 0 0.1 = f 1 (0.06766 − 0.167179.05) = 1 − 9(0.995 k 2.001398 1.08 y (0.993365 k 4.1) = 2.996617 k 3.743808 = 1.671785(0.2 0.671785) + 1.05) = 2 + 1.1 + 2(−0.995) = −0.083564 y (0.0.017509 1.2.06635 x(0.993365) = −0.06682 6 These slope estimates can then be used to make the prediction for the first step x(0.996617) = −0.167166 2.08.06635(0.2.978663 y 1 0. 2 = f 2 (0.5 x 2 2.1) = 1 − 0.05) = 2.4 0.1 0.671656(0.05) = 2.993318 0.67128(0.05.1) = 1 − 0.1.06635) − 0.

5 4 3 2 1 0 0 1 2 3 4 5 (c) To implement ode45. 6 x y 4 2 0 0 5 10 15 20 25 30 This periodic nature is also evident from the state-space plot. the cycles do not amplify as time proceeds.4*y(1)*y(2)].y(:.1).-0.9*y(2)+0.y] = ode45(@predprey. function yp = predprey(t. the solution and plot can be obtained: >> [t. >> plot(t. Then. Because this is the expected behavior we can see that the RK4 is far superior to Euler’s method for this particular problem.y(:.[2 1]).[0 30].'y(predator)') 208 . Note that in contrast to Euler’s method.7*y(1)*y(2).t. first a function is developed to evaluate the predator-prey ODEs.A plot of all the values can be developed.5*y(1)-0.2).'--') >> legend('x(prey)'.y) yp = [1.

84678 5 17.92312 22.1 0.2 0.57588 -8.30717 The results from t = 0 to 20 can be displayed graphically as 50 x y z 40 30 20 10 0 -10 0 5 10 -20 -30 209 15 20 .5 0.6789 -13.07946 20.549578 -3.81088 0.2 (a) Here are the results for the first few steps as computed with the classical RK4 technique t 0 0.8 0.4 0.54419 -5.21784 -3.30744 28.1646 -5.89688 39.88719 -11.7 0.43947 35.9142 -10.80001 33.39903 29.19.9 1 x y z 5 9.3 0.70297 10.14148 29.36888 19.8741 -2.42037 -12.78147 17.43 -7.52924 -5.84128 -8.07462 22.6668 -6.6 0.43018 5 10.

2).28*y(1)-y(2)-y(1)*y(3).[0 20].'z') plot(y(:. Then.1).1). an underlying pattern emerges when we look at the statespace plots. 50 40 30 20 10 0 -20 -10 0 10 20 (b) To implement any of the MATLAB functions.The solution appears chaotic bouncing around from negative to positive values.[5 5 5]).y) yp = [-10*y(1)+10*y(2). 25 15 5 -20 -5 0 -10 10 20 -15 -25 And here is z versus x. plot(t.y(:.y(:. here is the plot of y versus x.3). first a function is developed to evaluate the Lorenz ODEs.'--'.y(:. For example.t.y] = ode23(@lorenz. function yp = lorenz(t.t.666667*y(3)+y(1)*y(2)].':') legend('x'.-2.2)) 210 .y(:. the solution and plots for the ode23 function can be obtained: >> >> >> >> [t.'y'. Although the pattern might appear random.

1).t.2)) (c) The ode45 again differs in the details of the time-series plot.y(:.'y'.':') >> legend('x'.[0 20].y(:.2). although qualitatively similar to the constant step RK4 result in (a).3). >> [t. >> plot(y(:.y] = ode45(@lorenz.y(:.1). the details are quite different. >> plot(t.'z') 211 .t.y(:.'--'. However.[5 5 5]). the state-space representation looks much more consistent.Notice how this plot.

t. Such solutions are said to be chaotic. the solution will tend to make a large jump. they begin to diverge slightly.y(:. they abruptly begin to diverge.y(:. Thereafter. The reason for this behavior is that these equations are highly sensitive to their initial conditions.3).'z') Close inspection of all the above results indicates that they all yield identical results for a period of time.'--'. It was this characteristic of these particular equations that led Lorenz to suggest that long-range weather forecasts might not be possible. after awhile.y] = ode23tb(@lorenz. After a number of steps.[5 5 5]).t. 19.[0 20].3 First step: 212 .(d) The ode23tb also differs in the details of the time-series plot.':') >> legend('x'. Thus.2). >> plot(t.y(:. When the discrepancy becomes large enough (which for these equations is not that much).'y'.1). the various solutions become uncorrelated. >> [t. because they all employ different algorithms.

% 1 2 3.143883 + 1 − 0.271558) + e −2. the true values being simulated in this problem are t y 0 0.4 Before solving.143883+[−0.271558)+e−2.143883) + e −2 − 0.271558-3. we can develop the analytical solution as y= t3 −t e3 Thus.0282 19.285532) = 2.579010 Corrector: y 2 = 3.285532 Corrector: y1 = 4.5(4.5 − 0.Predictor: y10 = 5.25 0.632337 213 .590189 Predictor Modifier: y20 = 2.579010) + e −3 0.573205 2.5(3.5 1 0.143883)+e−2]1 = 3.271558 + 1 − 0.5 0.5 = 3.573931 0.5(2. for comparative purposes.590189+4/5(3.285532) + e −2.573205 2 The corrector can be iterated to yield j yi+1j ε a .5(3.061 Second step: Predictor: y20 = 4.269562 3.5 = 2.5(4.5(3.222138+[−0.269562 2 The corrector can be iterated to yield j yi+1j ε a .% 1 2 2.271558 0.782868 0.5]1 = 2.

25 = 0.0.125.125) = 0.87839) − 0.999e −ti +1 h 214 .63188975.5) 2 − 0.5 = 0.5 (a) h < 2/100.633028629(0.87839 y (0. 19.633028629 Corrector: (First iteration): y (0.89233 k 3 = f (0.63178298 2 Corrector: (Second iteration): y (0.0.1) = 1(0) 2 − 1 = −1 y (0.86851 6 y (0.861328 y (0.25 = 0. (b) The implicit Euler can be written for this problem as ( ) y i +1 = y i + − 100.25) = 1 − 0.7339 + (0.7828723 + − 0.633028629) 0.125) = 1 − 0.7828723 + − 0.5) 2 − 0.87839(0.78040) = −0.73163 = −0.000 = 2×10−5.25) = 1 − 0.5) = 0.000 y i +1 + 99.7828723 This result compares favorably with the analytical solution. The second step can then be implemented with the non-self-starting Heun method: Predictor: y (0.0.25) 2 − 0.7339 + (0.861328(0.63178298(0.875) = −0.875 k 2 = f (0.7828723)0.25.63178298) 0.125) = 1 − 1(0.5) = 1 + (0.25) = 0.25) = 0.125) = 0.125.86851(0.73163 φ= − 1 + 2(−0.861328 − 0.7828723(0.78040 k 4 = f (0.89233) = −0.The first step is taken with the fourth-order RK: k1 = f (0.63189976 2 The iterative process can be continued with the final result converging on 0.5) = 0.

t y 0 0 0.000h The results of applying this formula for the first few steps are shown below.6 The implicit Euler can be written for this problem as y i +1 = y i + (30(sin t i +1 − y i +1 ) + 3 cos t i +1 )h which can be solved for y i +1 = y i + 30 sin t i +1 h + 3 cos t i +1 h 1 + 30h The results of applying this formula are tabulated and graphed below.2 0.2 1.12525 215 t y 3.4 0.6 -0.270163 3.67032 1.8 0.444484 0.2 -0.999e − ti +1 h 1 + 100.993242 0.4 0.877341 t y 2. A plot of the entire solution is also displayed t y 0 0.8 0.79745 .50089 4 -0.3 0.904638 1.622925 2.1 0.818731 1.952306 0.740819 1.4 0.6 2 y 0.5 0 1.which can be solved for y i +1 = y i + 99.606531 2 1 0 0 1 2 19.760677 t 1.

i + (999 x1.i +1 ⎫ = ⎧ x1.i +1 = x1.i +1 ⎬⎭ ⎨⎩ x 2 .i or substituting h = 0.5 0 1 2 3 4 -1 19.9 0.7E+07 x2 1 -149 7206 -353184 17305943 dx1/dt dx2/dt 2998 -147102 7207803 -3.i +1 = x1.15 353186 0. Thus.95⎤ ⎧ x1.i ⎫ 101 ⎥⎦ ⎨⎩ x 2 . t x1 0 1 0.i + (999 x1. because its easier to display.2 0.7 (a) The explicit Euler can be written for this problem as x1.53E+08 -1. if the matrix is inverted.i +1 )h or collecting terms (1 − 999h) x1.i +1 + 1999 x 2 .i +1 − 1999hx 2 .i +1 = x1.i )h x 2.05 150.i − 2000 x 2.5 0 -0.i + 1999 x 2.i 1000hx1.1 -7204.2 -1.5E+08 1.i )h Because the step-size is much too large for the stability requirements. 216 . the solution for the first step amounts to the matrix multiplication.i +1 = x 2 . we substitute the initial conditions for the right-hand side and solve the 2x2 system of equations.i + (− 1000 x1. to solve for the first time step.7E+10 (b) The implicit Euler can be written for this problem as x1. The best way to do this is with LU decomposition since we will have to solve the system repeatedly.i ⎬⎭ ⎣⎢ 50 Thus.i + ( − 1000 x1.5 1 0.i +1 + (1 + 2000h) x 2 . we will use the matrix inverse to obtain the solution.i +1 − 2000 x 2 . For the present case.05 and expressing in matrix format ⎡ − 48.73E+10 -3000 147100 -7207805 3.i +1 )h x 2 .i +1 = x 2. the solution is unstable.1.i +1 = x 2 .95 − 99.

08 Note that even though the choice of the initial condition removes the positive exponential terms. 186648 . Very tiny round off errors in the numerical solutions bring it to the fore.8.752568 = 3. A = 0. The plot shows the numerical solution (bold line) along with the exact solution (fine line).457057 3. Hence all of the following solutions eventually diverge from the analytical solution.752568 ⎤1 ⎨x ⎬ = ⎢ − 0.2 1 3.64705 The results are plotted below. x1 4 2 0 0 0. 217 .4t + 0. − 181472 ⎣ ⎦ 2 .8 (a) The exact solution is y = Ae 5t + t 2 + 0. y = t 2 + 0.292457 1 -1.i +1 ⎫ ⎡ 1886088 .{} { } ⎧ x1.72938 -1. ⎤ 3.1). 186648 . { }{ } ⎧ x1.62878 ⎨x ⎬ = ⎢ − 0. (b) 4th order RK. along with a solution with the explicit Euler using a step of 0.2 x2 19. ⎣ ⎦ ⎩ 2 .05 to 0.0005.i +1 ⎭ For the second step (from x = 0.15 0. it still lurks in the background.752568 3.9141⎥ − 184781 . 3.i +1 ⎫ ⎡ 1886088 .62878 3. 1 + i ⎩ ⎭ The remaining steps can be implemented in a similar fashion to give t x1 x2 0 0.93371 − 0.93371 − 0.84781 -1. .9141⎥ 1 = − 184781 .08 If the initial condition at t = 0 is 0.1 0.81472 -1.1 -2 0.05 0.4t + 0.

(e) >> [t. >> y0 = 0. 30 20 10 0 -10 0 -20 1 2 3 4 5 -30 RK4 Analytical ODE23s ODE23tb ODE45 19.y] = ode45(@dy1.y0).08.y0).tspan.y] = ode23tb(@dy1.9 (a) As in Example 17. >> tspan = [0.5.0.tspan.15 10 5 0 -5 0 1 2 3 4 -10 (c) function yp = dy(t.5]. >> [t.1) ans = 29.y] = ode23s(@dy1.tspan.y) yp = 5*(y-t^2). (d) >> [t. the humps function can be integrated with the quad function as in >> format long >> quad(@humps.y0).85832612842764 (b) Using ode45 is based on recognizing that the evaluation of the definite integral 218 .

3) + 0.0).0./((x-0.y] = ode45(@humpsODE.10 The nonlinear model can be expressed as the following set of ODEs./((x-0.81 and l = 0. >> [x. function dy = dpnon(t.6.85832514287622 19.78683736423308 1.00000000000000 29. Then.^2 + 0.04) . >> disp([x. Thus. the integral estimate is within 0.5 1].04 where y(0) = 0.81/0.3).01 ( x − 0.50000000000000 21.y]) 0 0 0.y]) 0 0 0.[0 0.00000000000000 29.[0 0.6 m.5 1]. Note that a better estimate can be obtained by using the odeset function to set a smaller relative tolerance as in >> options = odeset('RelTol'. we must solve the following initial-value problem: dy 1 1 = + −6 2 dx ( x − 0.1e-8).9) 2 + 0. To do this with ode45. dθ =v dt g dv = − sin θ dt l where v = the angular velocity. >> disp([x. A function can be developed to compute the right-hand-side of this pair of ODEs for the case where g = 9. we must first set up an M-file to evaluate the righthand side of the differential equation.^2+0.78356481821654 1.6*sin(y(1))].01% of the estimate obtained with the quad function.01) + 1.50000000000000 21. 219 . y) dy = [y(2).-9. the integral can be evaluated as >> [x.options).y] = ode45(@humpsODE. function dy = humpsODE(x.9).85525185285369 Thus.y) dy = 1.I= ∫ b a f ( x) dx is equivalent to solving the differential equation dy = f (x) dx for y(b) given the initial condition y(a) = 0.

'--') legend('nonlinear'.1).tl.81/0.[0 10].[0 10].tl.[pi/8 0]).6*y(1)].yn(:. Second.'linear') You should notice two aspects of this plot.1). First. because the displacement is small.yl(:.[pi/2 0]). [tl yl] = ode45(@dplin.-9. function dy = dplin(t. dθ =v dt g dv =− θ dt l A function can be developed as.[0 10].1).The linear model can be expressed as the following set of ODEs. the solution and plot can be obtained for the case where θ(0) = π/8.'--') legend('nonlinear'. Then. y) dy = [y(2).[pi/8 0]).[pi/2 0]). plot(tn.[0 10]. the two solutions diverge as the computation progresses.yn(:. the linear solution provides a decent approximation of the more physically realistic nonlinear case. the solution and plot can be obtained as.1). plot(tn. >> >> >> >> [tn yn] = ode45(@dpnon.'linear') 220 . For the larger initial displacement (θ(0) = π/8). [tl yl] = ode45(@dplin. Note that we only depict the displacement (θ or y(1)) in the plot >> >> >> >> [tn yn] = ode45(@dpnon.yl(:.

[t.pdata. 19.p.026*(1-p/12000)*p. plot(t.p] = ode45(@dpdt. function yp = dpdt(t. >> >> >> >> tspan = 1950:5:2000.tspan.t. The function ode45 can be used to integrate this equation and generate results corresponding to the dates for the measured population data.2555). there are now clear and significant discrepancies between the nonlinear and linear cases that are exacerbated as the solution progresses. pdata = [2555 2780 3040 3346 3708 4087 4454 4850 5276 5686 6079]'.11 A function can be developed to compute the right-hand-side of the ODE. p) yp = 0.'o') The sum of the squares of the residuals can be computed as 221 .Because the linear approximation is only valid at small displacements. A plot can also be generated of the solution and the data.

>> SSR = sum((p .2365e+004 222 .^2) SSR = 4.pdata).

025 ⎥ ⎨ ⎬ ⎬ = ⎨0.708333⎪⎭ εa = 0.05 0. After 10 iterations.0875 × 100% = 2.708333⎫⎪ ⎡0.71573.0875⎬ = 0.70710678⎫⎪ 0.025 0.75⎪⎭ ⎪⎩0.0625⎫⎪ ⎧⎪0.085355 = 11.0375 0.29% 0.0125⎤ ⎢ 0. 20.0125 0.060714⎪⎭ ⎪⎩0.71428571⎪⎭ εa = 0.71428571⎫⎪ 1 ⎢ 0.025 ⎥ − λ[ I ] = 0 ⎢⎣0.060714⎫⎪ 1 1 ⎢ 0.0875 Iteration 3: ⎧⎪0.2 (a) Minors: (2 − λ ) 3 −4 λ 4 8 3 − λ = − λ3 + 10λ2 + 101λ + 18 8 4 7 − λ − 2 10 7 − λ + 10 10 4 (b) The eigenvalues can be determined by finding the roots of the characteristic polynomial determined in (a).1 The matrix inverse can be evaluated and the power method expressed as ⎡0.025 0.0375 0.025 0.0125⎤ ⎧⎪1⎫⎪ ⎧⎪0.0375⎥⎦ ⎪⎩0. the relative error falls to 0. This can be done in MATLAB.75⎫⎪ ⎢ 0.0875 − 0.025 0.0125 0.075⎫⎪ ⎧⎪0.75⎫⎪ ⎧⎪0.0375⎥⎦ Iteration 1: ⎡0.71428571⎪⎭ ⎪⎩0.0125 0.085714⎨ ⎢⎣0.025 0.05 0.025 0.025 ⎥ ⎨1⎬ = ⎨ 0.1⎨ 1 ⎬ ⎢⎣0.025 0.0375 0.025 ⎥ ⎨ 1 ⎬ = ⎨0.0125⎤ ⎧⎪0.0375⎥⎦ ⎪⎩1⎪⎭ ⎪⎩0.05 0.025 0.1 × 100% = 14.CHAPTER 20 20.025 0.085714⎬ = 0.0125 0.0375 0.05 0.0625⎪⎭ ⎪⎩0. the smallest eigenvalue is 1/0.085355⎨ 1 ⎬ ⎪⎩0.0875⎨ ⎬ ⎢⎣0.025 0.085714 − 0. 223 .70710678⎪⎭ Thus.025 0.71428571⎫⎪ ⎧⎪0.75⎪⎭ Iteration 2: ⎡0.1 ⎬ = 0.00000884% with the result ⎧⎪0.075⎪⎭ ⎪⎩0.085714 The iterations can be continued.025 0.08% 0.0125⎤ ⎧⎪0.0375⎥⎦ ⎪⎩0.

0000 Third iteration: >> x = A*x x = 13.0949 16.>> a = [1.7368 0.2632 15.0000 Second iteration: >> x = A*x x = 13.5263 >> x = x/e x = 0. First iteration: >> x = A*x x = 14 15 19 >> e = max(x) e = 19 >> x = x/e x = 0.10 4 5].5263 >> e = max(x) e = 15. >> A = [2 2 10.2610 13. >> roots(a) ans = 16.7898 1.8407 0.0000 -18. >> x = [1 1 1]'.0926 -0.0526 12.0000 -101.2741 -6.0000 -10.8 3 4.0000].5661 >> e = max(x) e = 224 .7895 1.1815 (c) The power method for the highest eigenvalue can be implemented with MATLAB commands.

7753 16.1819 12.0000 Thus.5661 >> x = x/e x = 0.6667 -1.3889 -1.7902 1.8 3 4. after four iterations.2222 225 .16.2222 >> [e.0556 -0.6667 -5.811 0.1668 >> x = x/e x = 0.8154 0. >> x = [1 1 1]'. (d) The power method for the lowest eigenvalue can be implemented with MATLAB commands.790 1].i] = max(abs(x)) e = 1 i = 2 >> x = x/x(i) x = -0.2741 with a corresponding eigenvector of [0.0000 -0.2222 4.10 4 5].1668 >> e = max(x) e = 16. the result is converging on a highest eigenvalue of 16.3889 1.5556 First iteration: >> x = AI*x x = 0.0000 Fourth iteration: >> x = A*x x = 13.0000 -0.0000 0.1111 1.7905 1. >> A = [2 2 10.8005 0.0000 0. >> AI = inv(A) AI = -0.0000 0.

0000 -0.7778 0.3 MATLAB can be used to solve for the eigenvalues with the polynomial method. the matrix can be put into the proper form for an eigenvalue analysis by bringing all terms to the left-hand-side of the equation.5 ⎥ ⎨ x 2 ⎬ = 0 ⎢ 1. 7 3 ⎤ ⎧⎪ x1 ⎫⎪ ⎡ 4 − 9λ 8 − 4λ 2 ⎥⎨x2 ⎬ = 0 ⎢ 7 ⎢⎣ 3 2 1 − 2λ ⎥⎦ ⎪⎩ x3 ⎪⎭ Then.7469 >> [e.7002 >> [e.i] = max(abs(x)) e = 5.3333 ⎤ ⎧⎪ x1 ⎫⎪ 2−λ 0 .5085) = −0.4444 − λ 0.5 − λ ⎥⎦ ⎪⎩ x3 ⎪⎭ 226 .0000 -0.i] = max(abs(x)) e = 5. ⎡0.Second iteration: >> x = AI*x x = 1.1268 Third iteration: >> x = AI*x x = 1.5 1 0.1271 Thus.8889 0. 20.5073 i = 2 >> x = x/x(i) x = -0. each row can be divided by the coefficient of λ in that row.75 ⎢⎣ 1 .3328 1. after three iterations.5073 0.3341 1 -0.1815 with an eigenvector of [−0.8889 i = 2 >> x = x/x(i) x = -0. First.3341 1.8402 -5.9599 -5.1271]. the estimate of the lowest eigenvalue is converging on the correct value of 1/(−5.

3/2 2/2 1/2].36 2/. -1/.7778 0 0 -2.0370 -428.36 2/.5556 Then. the matrix can be put into the proper form by dividing each row by 0. >> x = [1 1 1 1]'.2917 >> e=roots(p) e = 2. >> A=[4/9 7/9 3/9. >> p=poly(A) p = 1.36 2/.7778 5.36 -1/.2723 3.6871 The roots of this equation represent the eigenvalues.2876 20.2500 0.0610 (b) The power method can be used to determine the highest eigenvalue: >> A = [2/.9954 -0.36 2/. 0 -1/.9444 -0.5556 -2.36 0 0.36 0.36 -1/.7778 5.36.4 (a) MATLAB can be used to solve for the eigenvalues with the polynomial method.0 0 -1/.5556 -2.-1/.5556 -2.36 2/. First iteration: >> x = A*x x = 227 . >> A = [2/.36 -1/.36 0.36 -1/.3386 0.36]. >> e = roots(p) e = 10.2222 162.0000 -2.36.36 0 0.7/4 8/4 2/4.7778 5.36.8388 1.36 -1/. the poly function can be used to generate the characteristic polynomial.0000 -22. 0 0 -1/.36 2/.6694 297.7778 0 0 -2.36] A = 5. First.0 -1/.MATLAB can then be used to determine the eigenvalues as the roots of the characteristic polynomial.0501 7. >> p = poly(A) p = 1.7778 0 0 -2.36 1/.

228 .5556 -2. the method does not converge on the highest eigenvalue.1667 -4. it converges on the second highest eigenvalue of 7.5556 >> e = max(x) e = 5.9444 >> x = x/e x = 1.7778 0 0 2. Rather.0000 -0.6000 1. After 9 iterations.5000 1.2.6180 −0.0000 Third iteration: >> x = A*x x = 6.7778 >> x = x/e x = 1 0 0 1 Second iteration: >> x = A*x x = 5.5000 -0.7778 5.5556 >> x = x/e x = 1.0000 -0.6180 1].2723 with a corresponding eigenvector of [1 −0.6000 -0.7778 -2.9444 >> e = max(x) e = 6.0000 The process can be continued.9444 -4.7778 >> e = max(x) e = 2.1667 6.

36 -1/.36. >> AI = inv(A) AI = 0.9600 >> x = x/e x = 0.4320 0.9450 229 .36 2/.2160 0.(c) The power method can be used to determine the lowest eigenvalue by first determining the matrix inverse: >> A = [2/.1440 0.7200 1.1440 0.0720 0.36 2/.7200 >> e = max(x) e = 1.36 0 0.5850 0.0800 0.2880 >> x = [1 1 1 1]'.2160 0.6667 1.36 -1/.2160 0.36 1/.6000 >> e = max(x) e = 0.0800 >> x = x/e x = 0.0000 0. First iteration: >> x = AI*x x = 0.36].6250 Third iteration: >> x = AI*x x = 0.36 0.-1/.0800 1.2160 0.0720 0.0 -1/.4320 0.9600 0.2880 0.0000 1.6000 0.9600 0.0000 1.2880 0.2880 0.0 0 -1/.1440 0.6250 1.1440 0.6667 Second iteration: >> x = AI*x x = 0.36 2/.0000 0.

6180 1 1 0.5850 >> e = max(x) e = 0.10516 ⎬ ⎪⎩ ⎪⎭ 1 ⎧⎪− 0.0569 Therefore.50885⎬ ⎪⎩ ⎪⎭ 1 ⎧⎪0. 0.0000 1.380089 ⎫⎪ ⎨0.000.24 − 0.d] = eig(A) v = -0.2913 0.6986. the method converges on the lowest eigenvalue of 1/0.-0.450 -0.693748 ⎫⎪ ⎨− 2.3395 and 0.3395 0 0 0 0.6986 0 0 -0. ⎧⎪ 1.2 X2 =0 1 X 1 + 0.18 − 0.180.746999 ⎬ ⎪⎩ ⎪⎭ 1 A graph can be made showing the three modes 230 .0. 20.6890 0.7307 -0.225 − ω 2 X 3 = 0 ( ) ( ) A MATLAB session can be conducted to evaluate the eigenvalues and eigenvectors as >> A = [0.9450 0. the eigenvalues are 0.225].420 -0.45 − ω )X 2 − 0.225 X 2 + 0. The corresponding eigenvectors are (normalizing so that the amplitude for the third floor is one).240 0.5879 0.0000 0.6190 1. >> [v.225 0.42 − ω 2 X 2 X3 = 0 − 0.3506 0.92075⎫⎪ ⎨− 0.9450 = 1.7664 0 0.0610 with a corresponding eigenvector of [0. After 9 iterations.0569.5 The parameters can be substituted into force balance equations to give (0.200 0.6180].6344 -0.3471 d = 0.0.6190 The process can be continued.5725 0.000 -0.9450 >> x = x/e x = 0.

7370 0. The following MATLAB session can then be used to evaluate the eigenvalues and eigenvectors >> a = [1 -1 0.7370 -0. Therefore.001 0.001 1 1 − L3ω 2 I 3 sin(ωt ) + i3 − ( I 2 sin(ωt ) − I 3 sin(ωt )) = 0 0.5910 0. In addition.001 0.0 -1 2] >> [v.-2 -1 0 1 2 Mode 1 -1 0 Mode 2 1 0 1 Mode 3 20.001 − L1ω 2 I 1 sin(ωt ) + All the sin(ωt) terms can be cancelled.2. assume that the solution is ij = Ij sin(ωt).3280 0. Therefore.6 As was done in Section 20.3280 -0.-1 2 -1.5910 0. the L’s and C’s are constant.7370 -0.d] = eig(a) v = -0.1981 0 0 231 .5910 d = 0. the second derivative is d 2i j dt 2 = −ω 2 I j sin(ωt ) Substituting these relationships into the differential equations gives 1 ( I 1 sin(ωt ) − I 2 sin(ωt )) = 0 C1 1 1 − L2ω 2 I 2 sin(ωt ) + ( I 2 sin(ωt ) − I 3 sin(ωt )) − ( I 1 sin(ωt ) − I 2 sin(ωt )) = 0 0. the system simplifies to ⎡1 − λ ⎢ −1 ⎢⎣ 0 −1 2−λ −1 0 ⎤ ⎧⎪ I 1 ⎫⎪ − 1 ⎥ ⎨I 2 ⎬ = 0 2 − λ ⎥⎦ ⎪⎩ I 3 ⎪⎭ where λ = LCω2.3280 -0.

-k.8019 ⎪ ⎪ LC ⎪ ⎩ ⎭ 20.2*k. and 3.2757 -0.6230 0.2470 The matrix v consists of the system's three eigenvectors (arranged as columns). Setting these eigenvalues equal to mω 2 . the three frequencies can be obtained.4450 ⎫ ⎪ ⎪ ⎪ LC ⎪ ⎪ 1.-k.1981.0000 d = 3.-k.5550.2470. >> kmw2 = [2*k.5278 0.0000 0 0 Therefore.d] = eig(kmw2) v = 0.2*k].2470 ⎪ ω =⎨ ⎬ ⎪ LC ⎪ ⎪ 1.5774 0. and d is a matrix with the corresponding eigenvalues on the diagonal. These values in turn can be used to compute the natural frequencies for the system ⎧ 0. 1.7 The force balances can be written as ⎡m1 ⎢0 ⎢0 ⎣ 0 m2 0 0 ⎤ ⎧ &x&1 ⎫ ⎡ 2k ⎪ ⎪ 0 ⎥ ⎨ &x&2 ⎬ + ⎢− k m3 ⎥⎦ ⎪⎩ &x&3 ⎪⎭ ⎢⎣− k −k 2k −k − k ⎤ ⎧⎪ x1 ⎫⎪ − k ⎥⎨x2 ⎬ = 0 2k ⎥⎦ ⎪⎩ x3 ⎪⎭ Assuming that the solution is xi = Xi sin(ωt).5774 0 3.1456 -0.-k.5774 0. MATLAB computes that the eigenvalues are λ = 0. Thus. we get the following matrix ⎡2k − m1ω 2 ⎢ −k ⎢ −k ⎢⎣ −k 2 k − m 2ω 2 −k ⎤⎧ X ⎫ −k ⎥⎪ 1 ⎪ −k ⎥⎨ X 2 ⎬ = 0 2 ⎪X ⎪ 2k − m3ω ⎥⎦ ⎩ 3 ⎭ Using MATLAB. mω 1 = 0 ⇒ ω 1 = 0 (Hz) 1st mode of oscillation 2 mω 2 = 0 ⇒ ω 2 = 3 (Hz) 2nd mode 2 232 . >> k = 1.0 0 1.0000 0 0 0 0. and 3.7686 0. >> [v. the eigenvalues are 0.8034 -0.5550 0 0 3.-k. 3.-k.

-5*x(1)+5*(x(2)-x(1)).'--') legend('x1'.mω 3 = 0 ⇒ ω 3 = 3 (Hz) 3rd mode 2 20.6. (a) x1 = x2 = 1 >> >> >> >> >> tspan = [0.-0.y0).0. y0 = [1.t. dx1 = x3 dt dx 2 = x4 dt dx 3 = −5 x1 + 5( x 2 − x1 ) dt dx 4 = −5( x 2 − x1 ) − 5 x 2 dt An M-file can be set up to evaluate the right-hand side of these ODEs: function dx = dxdt(t.2).10]. plot(t.10]. 233 .tspan.8 The pair of second-order differential equations can be reexpressed as a system of four firstorder ODE’s. x) dx = [x(3). >> y0=[1.y(:.-5*(x(2)-x(1))-5*x(2)].x(4).1. the two masses oscillate in unison.1).0]. (b) x1 = 1.6 >> tspan=[0.0.'x2') Because we have set the initial conditions consistent with one of the eigenvectors.0].y] = ode45('dxdt'.y(:. [t. x2 = –0.

e = sign(x(i))*e. while (1) eold = e. iter = iter + 1.y]=ode45('dxdt'.'x2') Now. because the initial conditions do not correspond to one of the eigenvectors.tspan.1). e = 1. 20.eold)/e) * 100.9 function [e.>> [t.0001. n = size(A).2).t. break. if ea <= es | iter >= maxit.y(:. for i=1:n v(i)=1. ea = abs((e . >> plot(t.'--') >> legend('x1'. the motion involves the superposition of both modes. end v = v'. v = x/e. end end 234 . v] = powmax(A): % uses the power method to find the highest eigenvalue and % the corresponding eigenvector % input: % A = matrix to be analyzed % output: % e = eigenvalue % v = eigenvector es = 0. x = A*v.y0). iter = 0.i] = max(abs(x)). maxit = 100. [e.y(:. v] = powmax(A) % [e.

8113 0. v] = powmin(A) e = -0.0001.0000 20. >> [e. >> A = [2 2 10. break.0000 -0. v] = powmin(A): % uses the power method to find the lowest eigenvalue and % the corresponding eigenvector % input: % A = matrix to be analyzed % output: % e = eigenvalue % v = eigenvector es = 0.10 function [e.Application to solve Prob.2.8 3 4. e = 1. while (1) eold = e. e = sign(x(i))*e. 20.1815 v = -0. v = x/e. end v = v'. [e. x = Ai*v.7903 1.1271 235 .10 4 5]. iter = 0. maxit = 100. ea = abs((e . Application to solve Prob. Ai = inv(A).3341 1. iter = iter + 1. end end e = 1. >> [e. v] = powmax(A) e = 16. 20.eold)/e) * 100./e.i] = max(abs(x)).2. if ea <= es | iter >= maxit. for i=1:n v(i)=1.2741 v = 0. n = size(A). v] = powmin(A) % [e.

Master your semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master your semester with Scribd & The New York Times

Cancel anytime.