SM CH PDF
SM CH PDF
SM CH PDF
CHAPTER 9
9.1 The flop counts for the tridiagonal algorithm in Fig. 9.6 can be summarized as
Mult/Div
3(n 1)
2n 1
5n 4
Forward elimination
Back substitution
Total
Add/Subtr
Total
2(n 1)
n1
5(n 1)
3n 3
3n 2
8n 7
Thus, as n increases, the effort is much, much less than for a full matrix solved with Gauss elimination
which is proportional to n3.
9.2 The equations can be expressed in a format that is compatible with graphing x2 versus x1:
18 2 x1
3 0.333333 x1
6
40 x1
x2
5 0.125 x1
8
x2
x2
2
0
10
x1
15
20
Thus, the solution is x1 = 9.6, x2 = 6.2. The solution can be checked by substituting it back into the
equations to give
2(9.6) 6(6.2) 19.2 37.2 18
9.6 8(6.2) 9.6 49.6 40
9.3 (a) The equations can be rearranged into a format for plotting x2 versus x1:
x2 14.25 0.77 x1
PROPRIETARY MATERIAL. The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual
may be displayed, reproduced or distributed in any form or by any means, without the prior written permission of the
publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their
individual course preparation. If you are a student using this Manual, you are using it without permission.
x2 11.76471
1.2
x1
1.7
20
0
0
20
40
60
80
-20
-40
-60
If you zoom in, it appears that there is a root at about (38.7, 15.6).
38
38.5
39
39.5
-15
-15.4
-15.8
-16.2
The results can be checked by substituting them back into the original equations:
0.77(38.7) 15.6 14.2 14.25
1.2(38.7) 1.7(15.6) 19.92 20
(b) The plot suggests that the system may be ill-conditioned because the slopes are so similar.
(c) The determinant can be computed as
D 0.77(1.7) 1(1.2) 0.11
which is relatively small. Note that if the system is normalized first by dividing each equation by the largest
coefficient,
0.77 x1 x2 14.25
0.705882 x1 x2 11.76471
PROPRIETARY MATERIAL. The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual
may be displayed, reproduced or distributed in any form or by any means, without the prior written permission of the
publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their
individual course preparation. If you are a student using this Manual, you are using it without permission.
A2 2 1 2(0) 1(3) 3
3 0
A3 2 1 2(1) 1(3) 1
3 1
D 0(1) 2(3) 5(1) 1
x1
x2
x3
1 2 5
1 1 1
2 1 0
D
0 1 5
2 1 1
3 2 0
D
0 2 1
2 1 1
3 1 2
D
2
2
1
8
8
1
3
3
1
2 x1 x2 x3 1
2 x2 5 x3 1
Multiply pivot row 1 by 2/3 and subtract the result from the second row to eliminate the a21 term. Note that
because a31 = 0, it does not have to be eliminated
x2
3x1
0.33333x2 x3 0.33333
2 x2
5 x3 1
x2
2 x2 5 x3 1
0.33333x2 x3 0.33333
Multiply pivot row 2 by 0.33333/2 and subtract the result from the third row to eliminate the a32 term.
3x1
x2
2 x2
5 x3 1
0.16667 x3 0.5
Note that, at this point, the determinant can be computed as the product of the diagonal elements
PROPRIETARY MATERIAL. The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual
may be displayed, reproduced or distributed in any form or by any means, without the prior written permission of the
publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their
individual course preparation. If you are a student using this Manual, you are using it without permission.
D 3 2 0.16667 ( 1) 2 1
The results can be checked by substituting them back into the original equations:
2(8) 5(3) 1
2(2) 8 3 1
3(2) 8 2
9.5 (a) The equations can be expressed in a format that is compatible with graphing x2 versus x1:
x2 0.5 x1 9.5
x2 0.51x1 9.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.5 and
x2 = 10.
PROPRIETARY MATERIAL. The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual
may be displayed, reproduced or distributed in any form or by any means, without the prior written permission of the
publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their
individual course preparation. If you are a student using this Manual, you are using it without permission.
14.7
14.65
14.6
14.55
14.5
14.45
14.4
14.35
14.3
9.75
10
10.25
0.5
1.02 2
x2
0.58
14.5
0.04
This result can be substituted into the first equation which can be solved for
9.5 14.5
10
0.5
x1
(e) Multiply the first equation by 1.02/0.52 and subtract the result from the second equation to eliminate the
x1 term from the second equation,
0.52 x1
x2 9.5
0.03846 x2 0.16538
The second equation can be solved for
x2
0.16538
4.3
0.03846
PROPRIETARY MATERIAL. The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual
may be displayed, reproduced or distributed in any form or by any means, without the prior written permission of the
publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their
individual course preparation. If you are a student using this Manual, you are using it without permission.
This result can be substituted into the first equation which can be solved for
x1
9.5 4.3
10
0.52
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.
9.6 (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. Then, multiply the first equation by 1/10 and subtract the result from the
third equation to eliminate the x1 term from the third equation.
10 x1 2 x2
x3 27
Multiply the second equation by 0.8/(4.4) and subtract the result from the third equation to eliminate the x2
term from the third equation,
10 x1 2 x2
4.4 x2
x3 27
1.7 x3 53.4
6.409091x3 33.9091
(b) Check:
10(0.152482) 2(10.0922) (5.29078) 27
3(0.152482) 5(10.0922) 2(5.29078) 61.5
0.152482 10.0922 5( 5.29078) 21.5
9.7 (a) Pivoting is necessary, so switch the first and third rows,
8 x1 x2 2 x3 20
3x1 x2 7 x3 34
2 x1 6 x2 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. Then, multiply the first equation by 2/(8) and subtract the result from the
third equation to eliminate the a31 term from the third equation.
PROPRIETARY MATERIAL. The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual
may be displayed, reproduced or distributed in any form or by any means, without the prior written permission of the
publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their
individual course preparation. If you are a student using this Manual, you are using it without permission.
7
8 x1
x2
2 x3 20
x2
2 x3 20
5.75 x2 1.5 x3 43
1.375 x2 7.75 x3 26.5
Multiply pivot row 2 by 1.375/(5.75) and subtract the result from the third row to eliminate the a32 term.
8 x1
x2
2 x3 20
5.75 x2
1.5 x3 43
8.108696x3 16.21739
(b) Check:
2(4) 6(8) (2) 38
3(4) (8) 7(2) 34
8(4) (8) 2(2) 20
9.8 Multiply the first equation by 0.4/0.8 and subtract the result from the second equation to eliminate the
x1 term from the second equation.
0.8 0.4
x1 41
x 45.5
0.6
0.4
Multiply pivot row 2 by 0.4/0.6 and subtract the result from the third row to eliminate the x2 term.
0.8 0.4
x1 41
0.4 x2 45.5
0.6
0.533333 x3 135.3333
PROPRIETARY MATERIAL. The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual
may be displayed, reproduced or distributed in any form or by any means, without the prior written permission of the
publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their
individual course preparation. If you are a student using this Manual, you are using it without permission.
(b) Check:
0.8(173.75) 0.4(245) 41
0.4(173.75) 0.8(245) 0.4(253.75) 25
0.4(245) 0.8(253.75) 105
Values for the flows can be substituted and the system of equations can be written in matrix form as
130 30 0 c1 200
90 90
0 c2 0
40 60 120 c3 500
9.10 Let xi = the volume taken from pit i. Therefore, the following system of equations must hold
0.52 x1 0.20 x2 0.25 x3 4800
0.30 x1 0.50 x2 0.20 x3 5800
0.18 x1 0.30 x2 0.55 x3 5700
PROPRIETARY MATERIAL. The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual
may be displayed, reproduced or distributed in any form or by any means, without the prior written permission of the
publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their
individual course preparation. If you are a student using this Manual, you are using it without permission.
x =
1.0e+003 *
4.0058
7.1314
5.1628
Therefore, we take x1 = 4005.8, x2 = 7131.4, and x3 = 5162.8 m3 from pits 1, 2 and 3 respectively.
9.11 Let ci = component i. Therefore, the following system of equations must hold
15c1 17c2 19c3 2120
0.25c1 0.33c2 0.42c3 43.4
1.0c1 1.2c2 1.6c3 164
ci 1 2ci ci 1
c c
U i 1 i 1 kci
2x
x 2
These and the equations for the other interior nodes can be assembled in matrix form as
PROPRIETARY MATERIAL. The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual
may be displayed, reproduced or distributed in any form or by any means, without the prior written permission of the
publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their
individual course preparation. If you are a student using this Manual, you are using it without permission.
10
0
0
0
0
0
0
0 c1 200
4.2 1.5
2.5 4.2 1.5
0
0
0
0
0
0 c2 0
0
0
0
0
0
0 c3 0
2.5 4.2 1.5
0
0
2.5
4.2
1.5
0
0
0
0 c4 0
0
0
0
0
0
0 c5 0
2.5 4.2 1.5
0
0
0
0
0 c6
2.5 4.2 1.5
0
0
0
0
0
0
0
0 c7 0
2.5 4.2 1.5
0
0
0
0
0
2.5 4.2 1.5 c8 0
0
0
0
0
0
0
0
2.5 4.2 c9 15
0
The following script generates the solution with the Tridiag function from p. 247 and develops a plot:
clear,clc,clf
D=2;U=1;k=0.2;c0=80;c10=10;dx=1;
diag=(2*D+k*dx^2);
super=-(D-0.5*U*dx);
sub=-(D+0.5*U*dx);
r1=-sub*c0; rn=-super*c10;
n=9;
e=ones(n,1)*sub;f=ones(n,1)*diag;g=ones(n,1)*super;
r=zeros(n,1);r(1)=r1;r(n)=rn;
c=Tridiag(e,f,g,r)
c=[80 c 10]; x=0:1:10;
plot(x,c) ylim([0 90])
Alternatively, as in the following script, the solution can be generated directly with MATLAB left division:
clear,clc,clf
A=[4.2 -1.5 0 0 0 0 0 0 0
-2.5 4.2 -1.5 0 0 0 0 0 0
0 -2.5 4.2 -1.5 0 0 0 0 0
0 0 -2.5 4.2 -1.5 0 0 0 0
0 0 0 -2.5 4.2 -1.5 0 0 0
0 0 0 0 -2.5 4.2 -1.5 0 0
0 0 0 0 0 -2.5 4.2 -1.5 0
0 0 0 0 0 0 -2.5 4.2 -1.5
0 0 0 0 0 0 0 -2.5 4.2];
b=[200 0 0 0 0 0 0 0 15]';
c=(A\b)'
c=[80 c 10]; x=0:1:10;
plot(x,c), ylim([0 90])
58.9183
50.5357
43.3029
37.0219
31.4898
26.4684
21.6284 16.4454
PROPRIETARY MATERIAL. The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual
may be displayed, reproduced or distributed in any form or by any means, without the prior written permission of the
publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their
individual course preparation. If you are a student using this Manual, you are using it without permission.
11
80
60
40
20
0
0
10
9.13 For the first stage, the mass balance can be written as
F1 yin F2 x2 F2 x1 F1 x1
F
1 2 K y1 2 Ky2 yin
F1
F1
F
y4 1 2 K y5 2 xin
F
F1
1
F
yi-1 1 2 K yi 2 Kyi 1 0
F
F1
1
The solution can be developed in a number of ways. For example, using MATLAB,
>> format short g
>> A=[11 -10 0 0 0;-1 11 -10 0 0;0 -1 11 -10 0;0 0 -1 11 -10;0 0 0 -1 11];
>> B=[0.1;0;0;0;0];
>> Y=A\B
Y =
0.0099999
0.0009999
9.99e-005
PROPRIETARY MATERIAL. The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual
may be displayed, reproduced or distributed in any form or by any means, without the prior written permission of the
publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their
individual course preparation. If you are a student using this Manual, you are using it without permission.
12
9.9e-006
9e-007
1
0
0 Q2 0
0 Q3 0
3 Q4 0
0 Q5 1
1 1 1 0 0 Q6 0
0 0 1 1 1 Q7 0
1 2
0 2
0 0
1 0
0
1
0
0
0
2
2
0
13
x =
37.3333
-46.0000
74.0000
-46.6667
37.3333
46.0000
-76.6667
-74.0000
-37.3333
61.3333
Therefore, in kN
AB = 37.3333
DE = 46
BC = 46
CE = 76.6667
AD = 74
Ax = 74
BD = 46.6667
Ay = 37.33333
CD = 37.3333
Ey = 61.3333
9.16
function x=pentasol(A,b)
% pentasol: pentadiagonal system solver banded system
%
x=pentasol(A,b):
%
Solve a pentadiagonal system Ax=b
% input:
%
A = pentadiagonal matrix
%
b = right hand side vector
% output:
%
x = solution vector
% Error checks
[m,n]=size(A);
if m~=n,error('Matrix must be square');end
if length(b)~=m,error('Matrix and vector must have the same number of
rows');end
x=zeros(n,1);
% Extract bands
d=[0;0;diag(A,-2)];
e=[0;diag(A,-1)];
f=diag(A);
g=diag(A,1);
h=diag(A,2);
delta=zeros(n,1);
epsilon=zeros(n-1,1);
gamma=zeros(n-2,1);
alpha=zeros(n,1);
c=zeros(n,1);
z=zeros(n,1);
% Decomposition
delta(1)=f(1);
epsilon(1)=g(1)/delta(1);
gamma(1)=h(1)/delta(1);
alpha(2)=e(2);
delta(2)=f(2)-alpha(2)*epsilon(1);
epsilon(2)=(g(2)-alpha(2)*gamma(1))/delta(2);
gamma(2)=h(2)/delta(2);
for k=3:n-2
alpha(k)=e(k)-d(k)*epsilon(k-2);
delta(k)=f(k)-d(k)*gamma(k-2)-alpha(k)*epsilon(k-1);
PROPRIETARY MATERIAL. The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual
may be displayed, reproduced or distributed in any form or by any means, without the prior written permission of the
publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their
individual course preparation. If you are a student using this Manual, you are using it without permission.
14
epsilon(k)=(g(k)-alpha(k)*gamma(k-1))/delta(k);
gamma(k)=h(k)/delta(k);
end
alpha(n-1)=e(n-1)-d(n-1)*epsilon(n-3);
delta(n-1)=f(n-1)-d(n-1)*gamma(n-3)-alpha(n-1)*epsilon(n-2);
epsilon(n-1)=(g(n-1)-alpha(n-1)*gamma(n-2))/delta(n-1);
alpha(n)=e(n)-d(n)*epsilon(n-2);
delta(n)=f(n)-d(n)*gamma(n-2)-alpha(n)*epsilon(n-1);
% Forward substitution
c(1)=b(1)/delta(1);
c(2)=(b(2)-alpha(2)*c(1))/delta(2);
for k=3:n
c(k)=(b(k)-d(k)*c(k-2)-alpha(k)*c(k-1))/delta(k);
end
% Back substitution
x(n)=c(n);
x(n-1)=c(n-1)-epsilon(n-1)*x(n);
for k=n-2:-1:1
x(k)=c(k)-epsilon(k)*x(k+1)-gamma(k)*x(k+2);
end
1.1759
1.3082
1.1854
1.1809
9.17 Here is the M-file function based on Fig. 9.5 to implement Gauss elimination with partial pivoting
function [x, D] = GaussPivotNew(A, b, tol)
% GaussPivotNew: Gauss elimination pivoting
%
[x, D] = GaussPivotNew(A,b,tol): Gauss elimination with pivoting.
% input:
%
A = coefficient matrix
%
b = right hand side vector
%
tol = tolerance for detecting "near zero"
% output:
%
x = solution vector
%
D = determinant
[m,n]=size(A);
if m~=n, error('Matrix A must be square'); end
nb=n+1;
Aug=[A b];
npiv=0;
% forward elimination
for k = 1:n-1
% partial pivoting
[big,i]=max(abs(Aug(k:n,k)));
ipr=i+k-1;
if ipr~=k
npiv=npiv+1;
Aug([k,ipr],:)=Aug([ipr,k],:);
end
absakk=abs(Aug(k,k));
if abs(Aug(k,k))<=tol
D=0;
PROPRIETARY MATERIAL. The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual
may be displayed, reproduced or distributed in any form or by any means, without the prior written permission of the
publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their
individual course preparation. If you are a student using this Manual, you are using it without permission.
15
Here is a script to solve Prob. 9.5 for the two cases of tol:
clear; clc; format short g
A=[0.5 -1;1.02 -2];
b=[-9.5;-18.8];
disp('Solution and determinant calculated with GaussPivotNew:')
[x, D] = GaussPivotNew(A,b,1e-5)
disp('Determinant calculated with det:')
D=det(A)
PROPRIETARY MATERIAL. The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual
may be displayed, reproduced or distributed in any form or by any means, without the prior written permission of the
publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their
individual course preparation. If you are a student using this Manual, you are using it without permission.