3
0 0 0 -1 0 0 0.707 1 0 0 0 0 0 0 0 0 0
0 0 0 0 0.707 0 0 0 0.707 0 -0.5 -1 0 0 0 0 0
0 0 0 0 0 -1 -0.707 0 0.7071 0 0.8666 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.866 0 -0.866];
b=[0; 54000; 0; 0; 0; 0; 0; 0; -2000; 0; 0; 5000; 0; 6000; 0; 0; 0];
format short e
disp(‘Part (a)’)
x = GaussJordan(a,b)
disp(‘Part (b)’)
x=a\b
When the program is executed, the following result is displayed in the Command Window.
Part (a)
x =
-2.8289e+03
4
4.5396e+04
-3.0493e+04
-3.0150e+04
2.4719e+04
-7.2656e+04
4.0006e+03
4.3396e+04
-6.1381e+04
4.5396e+04
>>
1
4.37 A bridge is modeled by a rigid horizontal bar supported
by three elastic vertical columns as shown. A force
kN applied to the rigid bar at a distance d from the
end of the bar represents a car on the bridge. The forces in
columns , , and can be determined from the
solution of the following system of three equations:
,
Once the force in each of the column is known, its elongation can be determined with the formula
, where E and A are the elastic modulus and the cross-sectional area of each of the columns.
Write a MATLAB program in a script file that determines the forces in the three columns and their elonga-
tion for m. The program displays the three forces as a function of d in one plot, and the elonga-
tion of the three columns as a function of d in a second plot (two plots on the same page). Also given:
m, m, m, GPa, and m2.
Solution
The following program in a script file solves the problem.
A
B
C
D
P
L
AB
L
GF
L
CD
G
F
d
10m 10m
18m 12m
P40=
FAB
FCD
FGF
FAB FCD FGF
++ P=
10FAB 28FCD 40FGF
++ dP=
12FABLAB 30FCDLCD
–18FGFLGF
+0=
δFL
EA
——
=
0d50≤≤
LAB 12=
LCD 8=
LGF 10=
E70=
A25 10 4
=
2
end
subplot(2,1,1)
plot(a,FAB,a,FCD,a,FEF)
When the program is executed, the following plots are displayed in the Command Window.
0 5 10 15 20 25 30 35 40 45 50
-5
-4
-3
-2
-1
0
1
2
3x 104
d (m)
force (N)
FAB
FCD
FEF
1
4.38 A food company manufactures the five types of 1.0 lb trail mix packages that have the following
composition and cost:
Using the information in the table, determine the cost per pound of each of the ingredients. Write a system
of linear equations and solve by using the following methods.
(a) Use the user-defined function GaussJordan that was developed in Problem 4.22.
(b) Use MATLAB’s built-in functions.
Solution
The problem is solved by solving the following system of five equations:
Mix Peanuts (lb) Raisins (lb) Almonds (lb) Chocolate
Chips (lb)
Dried Plums
(lb)
Total Cost of
Ingredients ($)
A0.2 0.2 0.2 0.2 0.2 1.44
B0.35 0.15 0.35 00.15 1.16
C0.1 0.3 0.1 0.1 0.4 1.38
D00.3 0.1 0.4 0.2 1.78
E0.15 0.3 0.2 0.35 01.61
0.2 0.2 0.2 0.2 0.2
x1
1.44
2
disp(‘Part (b)’)
xb=a\b
When the file is executed the following results are displayed in the Command Window:
1
4.39 The currents, , in the circuit that is
shown can be determined from the solution of the follow-
ing system of equations. (Obtained by applying Kirch
hoffs law.)
,
,
Solve the system using the following methods.
(a) Use the user-defined function GaussJordan that
was developed in Problem 4.22.
(b) Use MATLAB’s built-in functions.
Solution
The system is solved in the following script file:
clear, clc
a=[9.5 -2.5 0 -2 0; -2.5 11 -3.5 0 -5; 0 -3.5 15.5 0 -4
When the script file is executed the following results are displayed in the Command Window:
Part (a)
xa =
0.1162
-3.9276
i1
5
12 V
_
+
_
+
+
+
i2
i3
i4i5
16 V
30 V
10 V
14 V
4
3.5
2
8
5
2
3
_
_
+
_
2.5
i1i2i3i4i5
,,,,
9.5i12.5i2
–2i4
–12=
2.5i1
–11i23.5i3
–5i5
+16=
3.5i2
– 15.5i34i5
+14=
2i1
–7i43i5
+10=
5i2
–4i3
–3i4
–12i5
+30=
1
4.40 When balancing the following chemical reaction by conserving the number of atoms of each element
between reactants and products:
the unknown stoichiometric coefficients a, b, c, and d are given by the solution of the following system of
equations:
Solve for the unknown stoichiometric coefficients using
(a) The user-defined function GaussJordan that was developed in Problem 4.22.
(b) MATLAB’s left division operation.
Solution
(a) The user-defined function GaussJordan that was developed in Problem 4.24 is used in the follow-
ing script file to solve the problem.
P2I4aP4bH2O++
cPH4IdH
3PO4
+
4–011
0010
02–43
01–04
a
b
c
d
2
4
0
0
=
1
4.41 A certain chemical engineering process application
(see figure) involves three chemical reactors A, B, and C.
At steady state, the concentrations of a particular species n
in each reactor has the values , , and in units of
mg/m3. If the flow rates from reactor i (A, B, or C) to reac-
tor j (A, B, or C) is denoted as (units of m3/s), then the
mass flow rate of species n from reactor i to reactor j is
(units of mg/s). Since this chemical species is con-
served (i.e., neither produced nor destroyed) conservation of mass (of the species) for each reactor must
hold. For the process shown in the figure, m3/s, m3/s, m3/s,
m3/s, m3/s, mg/s, and mg/s. Write down the mass con-
tinuity equations for each reactor and solve them to find the concentrations , , and in each reactor.
Solution
Conservation of mass yields:
QAin+xBQBA-xAQAC-xAQAB = 0
A
A
B
C
xAQAC
xBQBC
xAQAB
xBQBA
mAin
mCin
xCQCout
xA
xB
xC
Qij
xiQij
QAB 40=
QAC 80=
QBA 60=
QBC 20=
QCout 150=
mCin 195=
mAin 1320=
xA
xB
xC
1
4.42 When balancing the following chemical reaction by conserving the number of atoms of each element
between reactants and products:
the unknown stoichiometric coefficients a through h are given by the solution of the following system of
equations:
Solve for the unknown stoichiometric coefficients using
(a) The user-defined function GaussJordan that was developed in Problem 4.22.
(b) MATLAB’s left division operation.
Solution
(a) The listing of the user-defined function GaussJordan is:
function x = GaussJordan(a,b)
% The function solve a system of linear equations ax=b using the Gauss
Cr N2H4CO()
6
()
4Cr CN()
6
()
3aKMnO4bH2SO4
++
cK2Cr2O7dMnSO4eCO2fKNO3gK2SO4hHO2
+++++
0 0 200000
0 0 000100
02– 000002
0 0 001000
4–4– 742341
1 0 200120
1 0 010000
01– 010010
a
b
c
d
e
f
g
h
7
66
96
42
24
0
0
0
=
2
% Pivoting section starts
pvtemp=ab(j,j);
kpvt=j;
% If a row with a larger pivot element exists, switch the rows.
if kpvt~=j
abTemp=ab(j,:);
ab(j,:)=ab(kpvt,:);
ab(kpvt,:)=abTemp;
end
3
-1 0 0 1 0 0 0 0; 0 -1 0 1 0 0 1 0];
b=[7; 66; 96; 42; 24; 0; 0; 0];
c = GaussJordan(A,b)
When the program is executed the following results are displayed in the Command Window:
c =
117.6000
139.9000
(b) The following program written in a script file solves the problem with MATLAB’s left division opera-
tion.
% Solution of HW4_39b, script file
clear all
A=[0 0 2 0 0 0 0 0; 0 0 0 0 0 1 0 0; 0 -2 0 0 0 0 0 2
0 0 0 0 1 0 0 0; -4 -4 7 4 2 3 4 1; -1 0 2 0 0 1 2 0
-1 0 0 1 0 0 0 0; 0 -1 0 1 0 0 1 0];
b=[7; 66; 96; 42; 24; 0; 0; 0];
c=A\b
When the program is executed the following results are displayed in the Command Window:
c =
1
4.43 Traffic congestion is encountered at the intersections
shown in the figure. All the streets are one-way and in the
directions shown. In order for effective movement of traffic, it
is necessary that for every car that arrives at a given corner,
another car must leave so that the number of cars arriving per
unit time must equal the number of cars leaving per unit time.
Traffic engineers gather the following information:
600 cars per hour come down Amsterdam Ave. to intersec
tion #1 and 300 cars per hour enter intersection #1 on 108th
St.
650 cars per hour leave intersection #2 along Amsterdam Ave. and 50 cars per hour leave intersection
#2 along 107th St.
350 cars per hour come up Columbus Ave. to intersection #3 and 50 cars per hour enter intersection #3
along 107th St.
400 cars per hour leave intersection #4 along Columbus Ave. and 300 cars per hour enter intersection #4
from 108th St.
Find , , , and , where denotes the number of cars traveling per hour along Amsterdam Ave.
from intersection #1 to intersection #2, denotes the number of cars traveling per hour along 107th St.
from intersection #3 to intersection #2, denotes the number of cars traveling per hour along Columbus
Ave. from intersection #3 to intersection #4, and denotes the number of cars traveling per hour along
108th St. from intersection #1 to intersection #4.
Solution
The conservation equations are:
x1+x4 = 600+300 (intersection #1)
Amsterdam Ave.
Columbus Ave.
1
2
34
108th St.
107th St.
n1
n2
n3
n4
n1
n2
n3
n4
2
=
700
900
x
x
0011
1001
2
1