1
4.28 Write a user-defined MATLAB function that calculates the condition number of an matrix by
using the infinity norm. For the function name and arguments use c = CondNumb_Inf(A), where A is
the matrix and c is the value of the condition number. Within the function, use the user-defined functions
Inverse from Problem 4.24 and InfinityNorm from Problem 4.26. Use the function
CondNumb_Inf for calculating the condition number of the matrices in Problem 4.25.
Solution
The listing of the user-defined function CondNumb is:
function c=CondNumb_Inf(A)
nn×()
1
4.29 In a Cartesian coordinate system the equation of a circle with its
center at point and radius r is:
Given three points, , , and , determine the
equation of the circle that passes through the points.
Solve the problem by deriving a system of three linear equations (substi-
tute the points in the equation) and solve the system.
(a) Use the user-defined function GaussPivotLarge developed in Problem 4.21.
(b) Solve the system of equations using MATLAB’s left division operation.
Solution
The equation of the circle can be written in the form:
where
(-6.5, -9.3)
(-1, 3.2)
(-8, 4)
x
y
ab,()
xa()
2yb()
2
+r2
=
1–3.2,()
8–4,()
6.5–9.3,()
ca
2b2r2
+=
2
a=Cb(1)
b=Cb(2)
r=sqrt(Cb(1)^2+Cb(2)^2-Cb(3))
When the script is executed the following answers are displyed in the Comand Window:
1
4.30 In a 3D Cartesian coordinate system the equation of a plane is:
Given three points, , , and , determine the equation of the plane that passes
through the points.
Solution
Substituting the three points in the equation gives a system of three linear equations for the unknowns: ,
, and . Solving the system gives the constants (d can have any value. It is taken to be 1).
The problem is solved in the following script file:
ax by cz++ d=
23–2,,()
521,,()
1–54,,()
a
b
c
1
4.31 Three masses, kg, kg, and kg, are attached to
springs, N/m, N/m, N/m, and N/m, as
shown. Initially the masses are positioned such that the springs are in their nat-
ural length (not stretched or compressed); then the masses are slowly released
and move downward to an equilibrium position as shown. The equilibrium
equations of the three masses are:
where , , and are the relative displacement of each mass as shown. Determine the displacement of
the three masses. ( )
Solution
The problem is solved in the following script file:
m1=2; m2=3; m3=1.5;
m
1
m
2
m
3
m
1
u
1
u
2
u
3
m
2
m
3
k
3
k
1
k
2
k
4
m12=
m23=
m31.5=
k130=
k225=
k320=
k415=
k1k2k3
++()u1k3u2
m1g=
k3u1
k3k4
+()u2k4u3
+ m2g=
k4u2
k4u3
+m3g=
u1
u2
u3
g9.81=
ms
2
1
4.32 The axial force in each of the 13-member pin-
connected truss, shown in the figure, can be calculated
by solving the following system of 13 equations:
,
,
,
,
,
,
(a) Solve the system of equations using the user-defined function GaussPivotLarge developed in
Problem 4.21.
(b) Solve the system of equations using Gauss–Seidel iteration. Does the solution converge for a starting
(guess) vector whose elements are all zero?
(c) Solve the system of equations using MATLAB’s left division operation.
Solution
The listing of the user-defined function GaussPivotLarge is:
600 N 600 N
2000 N
2
3
4
5
6
7
89
1800 N 800 N
1
10
13
11
12
8 m
8 m 8 m7 m 7 m
Fi
F20.707F1
+0=
F30.707F1
–2000–0=
0.7071F1F46229++ 0=
F20.659F5F6
++0=
F40.753F5
– 600–0=
F3
– 0.659F5
F7
+0=
0.753F5F8
+0=
F6
– 0.659F9F10
++0=
F80.753F9
– 800–0=
F70.659F9
F11
+0=
0.753F9F12 2429+0=
F10
–0.707F13
+0=
F12 0.7071F13
–600–0=
2
pvtemp=ab(j,j);
kpvt=j;
end
% Pivoting section ends
for i = j+1:R
ab(i,j:C) = ab(i,j:C)-ab(i,j)/ab(j,j)*ab(j,j:C);
end
end
x = zeros(R,1);
x(R) = ab(R,C)/ab(R,R);
for i = R-1:-1:1
x(i)=(ab(i,C)-ab(i,i+1:R)*x(i+1:R))/ab(i,i);
end
3
0 0 0 -1 -0.753 0 0 0 0 0 0 0 0
0 0 -1 0 -0.659 0 1 0 0 0 0 0 0
0 0 0 0 0.753 0 0 1 0 0 0 0 0
b=[0; 2000; -6229; 0; 600; 0; 0; 0; 800; 0; 2429; 0; 600];
format short e
disp(‘Part (a)’)
c = GaussPivotLarge(A,b)
disp(‘Part (c)’)
c=A\b
When the program is executed, the following result is displayed in the Command Window.
Part (a)
c =
-4.4699e+03
4
Part (c)
c =
-4.4699e+03
3.1602e+03
-1.1602e+03
1
4.33 A particular dessert consists of 2 lb of bananas, 3 lb of strawberries, 3 lb of cherries, and 4 lb of fro-
zen yogurt. If the cost of the entire batch of this dessert is to be no more than $20 (in order to yield an
acceptable profit), what must the cost of each ingredient be (per pound) if the strawberries cost twice as
much as the cherries, and the cherries cost $1 per pound less than the frozen yogurt, and the frozen yogurt
costs as much as half a pound of cherries and 4 pounds of bananas? (Hint: Set up a system of four equa-
tions where the unknowns are the cost (per pound) of the bananas ( ), the cost (per pound) of the straw-
berries ( ), the cost (per pound) of the cherries ( ), the cost (per pound) of the frozen yogurt ( ), and
use the fact that all the ingredient costs have to add up to $20.)
Solution
The four equations are:
x1
x2
x3
x4
1
4.34 A particular chemical substance is produced from three different ingredients A, B, and C, each of
which have be dissolved in water first before they react to form the desired substance. Suppose that a solu-
tion containing ingredient A at a concentration of 2 g/cm3 is combined with a solution containing ingredi-
ent B at a concentration of 3.6 g/cm3 and with a solution containing ingredient C at a concentration of 6.3
g/cm3 to form 25.4 g of the substance. If the concentrations of A, B, and C in these solutions are changed to
4 g/cm3, 4.3 g/cm3, and 5.4 g/cm3, respectively (while the volumes remain the same), then 27.7 g of the
substance is produced. Finally, if the concentrations are changed to 7.2, 5.5, and 2.3 g/cm3, respectively,
then 28.3 g of the chemical is produced. Find the volumes (in cubic centimeters) of the solutions contain-
ing A, B, and C.
Solution
The three equations are:
1
4.35 Mass spectrometry of a sample gives a series of peaks that represent various masses of ions of con-
stituents within the sample. For each peak, the height of the peak is influenced by the amounts of the
various constituents:
where is the contribution of ions of species i to the height of peak j, and is the amount of ions or con-
centration of species j. The coefficients for each peak are given by:
If a sample produces a mass spectrum with peak heights, , , , ,
, and , determine the concentrations of the different species in the sample.
Solution
This is one of those instances where it is possible to obtain a unique solution despite having more equa-
tions than unknowns. The problem is solved by setting up the following matrix equation:
Peak
identity
Species
CH4C2H4C2H6C3H6C3H8
120.5 02.4 0.2
218 40.3 0.2 0.1
318 10 0 15
412 0 1
510 2
610
Ii
IjCijnj
i1=
N
=
Cij
nj
Cij
I130.5=
I271.5=
I3354.8=
I4180=
I5100=
I636.9=
2
1
4.36 The axial force in each of the 17 member pin connected truss,
shown in the figure, can be calculated by solving the following system
of 17 equations:
,
,
,
,
,
,
,,
(a) Solve the system of equations using the user-defined function GaussJordan developed in Problem
4.22.
(b) Solve the system of equations using MATLAB’s left division operation.
Solution
The listing of the user-defined function GaussJordan is:
function x = GaussJordan(a,b)
2
7
4
5
6
8
9
10
11
12
13
14
15
16
17
1
8000 N 6000 N
2000 N
3
5000 N
Fi
F10.342F3
–0=
0.94F3F454000+0=
F50.342F3
+0=
F6F2
–0.94F3
–0=
F50.7071F7
–0=
F80.707F7F4
+0=
0.707F90.707F+50.5F11
F12
–0=
F60.707F7
– 0.7071F90.866F11
++ 0=
F10 0.707F9
– 2000+0=
F80.707F9
–0=
F10 0.5F11 0.5F13
F14
+0=
0.866F11 0.866F13
– 5000–0=
F12 0.5F13 0.5F15
F16
+0=
0.866F13 0.866F15 6000+0=
F16 0.5F17
+0=
F14 0.5F15 0.5F17
+0=
0.866F15 0.866F17
–0=
2
pvtemp=ab(j,j);
kpvt=j;
% Looking for the row with the largest pivot element.
for k=j+1:R
if ab(k,j)~=0 & abs(ab(k,j)) > abs(pvtemp)
pvtemp=ab(k,j);
kpvt=k;
The following program (script file) uses the user-defined GaussJordan function (Part (a)) and MATLAB
left division (Part (b)) to solve the system of linear equations that is given in the problem statement.
clear, clc
a=[-1 0 -0.342 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0.94 1 0 0 0 0 0 0 0 0 0 0 0 0 0