184 Roots: Open Methods
6.6.1 MATLAB Function: roots
If you are dealing with a problem where you must determine a single real root of a polyno-
mial, the techniques such as bisection and the Newton-Raphson method can have utility.
However, in many cases, engineers desire to determine all the roots, both real and complex.
Unfortunately, simple techniques like bisection and Newton-Raphson are not available for
determining all the roots of higher-order polynomials. However, MATLAB has an excel-
lent built-in capability, the roots function, for this task.
The roots function has the syntax,
x = roots(c)
where x is a column vector containing the roots and c is a row vector containing the poly-
nomial’s coefficients.
So how does the roots function work? MATLAB is very good at finding the eigen-
values of a matrix. Consequently, the approach is to recast the root evaluation task as an
eigenvalue problem. Because we will be describing eigenvalue problems later in the book,
we will merely provide an overview here.
Suppose we have a polynomial
a1 x5 + a2 x4 + a3 x3 + a4 x2 + a5 x + a6 = 0 (6.13)
Dividing by a1 and rearranging yields
x5 = − _aa_21 x4 − _ aa_13 x3 − _ aa_14 x2 − _aa_51 x − _ aa_61
A special matrix can be constructed by using the coefficients from the right-hand side as
the first row and with 1’s and 0’s written for the other rows as shown:
−a2∕a1 −a3∕a1 −a4∕a1 −a5∕a1 −a6∕a1
1 0 0 0 0
0 1 0 0 0 (6.14)
0 0 1 0 0
0 0 0 1 0
Equation (6.14) is called the polynomial’s companion matrix. It has the useful prop-
erty that its eigenvalues are the roots of the polynomial. Thus, the algorithm underlying
the roots function consists of merely setting up the companion matrix and then using
MATLAB’s powerful eigenvalue evaluation function to determine the roots. Its applica-
tion, along with some other related polynomial manipulation functions, are described in
the following example.
We should note that roots has an inverse function called poly, which when passed the
values of the roots, will return the polynomial’s coefficients. Its syntax is
c = poly(r)
where r is a column vector containing the roots and c is a row vector containing the poly-
nomial’s coefficients.
6.6 polynomials 185
EXAMPLE 6.8 Using MATLAB to Manipulate Polynomials and Determine Their Roots
Problem Statement. Use the following equation to explore how MATLAB can be em-
ployed to manipulate polynomials:
f 5(x) = x5 − 3.5x4 + 2.75x3 + 2.125x2 − 3.875x + 1.25 (E6.8.1)
Note that this polynomial has three real roots: 0.5, −1.0, and 2; and one pair of complex
roots: 1 ± 0.5i.
Solution. Polynomials are entered into MATLAB by storing the coefficients as a row vec-
tor. For example, entering the following line stores the coefficients in the vector a:
>> a = [1 −3.5 2.75 2.125 −3.875 1.25];
We can then proceed to manipulate the polynomial. For example we can evaluate it at
x = 1, by typing
>> polyval(a,1)
with the result, 1(1)5 − 3.5(1)4 + 2.75(1)3 + 2.125(1)2 − 3.875(1) + 1.25 = −0.25:
ans =
−0.2500
We can create a quadratic polynomial that has roots corresponding to two of the origi-
nal roots of Eq. (E6.8.1): 0.5 and −1. This quadratic is (x − 0.5)(x + 1) = x2 + 0.5x − 0.5.
It can be entered into MATLAB as the vector b:
>> b = [1 .5 −.5]
b= 0.5000 −0.5000
1.0000
Note that the poly function can be used to perform the same task as in
>> b = poly([0.5 −1])
b= 0.5000 −0.5000
1.0000
We can divide this polynomial into the original polynomial by
>> [q,r] = deconv(a,b)
with the result being a quotient (a third-order polynomial, q) and a remainder (r)
q= −4.0000 5.2500 −2.5000
1.0000 00 00 0
r=
0
Because the polynomial is a perfect divisor, the remainder polynomial has zero coeffi-
cients. Now, the roots of the quotient polynomial can be determined as
>> x = roots(q)
186 Roots: Open Methods
with the expected result that the remaining roots of the original polynomial Eq. (E6.8.1)
are found:
x=
2.0000
1.0000 + 0.5000i
1.0000 − 0.5000i
We can now multiply q by b to come up with the original polynomial:
>> a = conv(q,b)
a= −3.5000 2.7500 2.1250 −3.8750 1.2500
1.0000
We can then determine all the roots of the original polynomial by
>> x = roots(a)
x=
2.0000
−1.0000
1.0000 + 0.5000i
1.0000 − 0.5000i
0.5000
Finally, we can return to the original polynomial again by using the poly function:
>> a = poly(x)
a=
1.0000 −3.5000 2.7500 2.1250 −3.8750 1.2500
6.7 CASE STUDY PIPE FRICTION
Background. Determining fluid flow through pipes and tubes has great relevance in
many areas of engineering and science. In engineering, typical applications include the
flow of liquids and gases through pipelines and cooling systems. Scientists are interested
in topics ranging from flow in blood vessels to nutrient transmission through a plant’s
vascular system.
The resistance to flow in such conduits is parameterized by a dimensionless number
called the friction factor. For turbulent flow, the Colebrook equation provides a means to
calculate the friction factor:
( )0 = _√_1__f __ + 2.0 log _3_.7ε__ D_ + _ R_2e_.5√_1_ _f__ (6.15)
6.7 CASE STUDY 187
6.7 CASE STUDY continued
where ε = the roughness (m), D = diameter (m), and Re = the Reynolds number:
Re = _ρ_Vμ_D _
where ρ = the fluid’s density (kg/m3), V = its velocity (m/s), and μ = dynamic viscosity
(N · s/m2). In addition to appearing in Eq. (6.15), the Reynolds number also serves as the
criterion for whether flow is turbulent (Re > 4000).
In this case study, we will illustrate how the numerical methods covered in this part of
the book can be employed to determine f for air flow through a smooth, thin tube. For this
case, the parameters are ρ = 1.23 kg/m3, μ = 1.79 × 10–5 N · s/m2, D = 0.005 m, V = 40 m/s,
and ε = 0.0015 mm. Note that friction factors range from about 0.008 to 0.08. In addition,
an explicit formulation called the Swamee-Jain equation provides an approximate estimate:
[ ( )]f = _ l_n_ _ _3__.7_ _ε1_ _D.__3 _ 2+_5__ R5__.e7__04_._9 _ _2 (6.16)
Solution. The Reynolds number can be computed as
Re = _ρ_Vμ_D _ = _ 1_.12_.37_(9_4_×0 _)_10_0.0_−0_5 5_ = 13,743
This value along with the other parameters can be substituted into Eq. (6.15) to give
( )g ( f ) = _√_1__f __ + 2.0 log _03_..07_0(_00_.0_00_01_55_) + _1_3_,27_.4_53_1√_ __f__
Before determining the root, it is advisable to plot the function to estimate initial
guesses and to anticipate possible difficulties. This can be done easily with MATLAB:
>> rho = 1.23;mu = 1.79e − 5;D = 0.005;V = 40;e = 0.0015/1000;
>> Re = rho*V*D/mu;
>> g = @(f) 1/sqrt(f)+2*log10(e/(3.7*D)+2.51/(Re*sqrt(f)));
>> fplot(g,[0.008 0.08]),grid,xlabel('f'),ylabel('g(f)')
As in Fig. 6.11, the root is located at about 0.03.
Because we are supplied initial guesses (xl = 0.008 and xu = 0.08), either of the brack-
eting methods from Chap. 5 could be used. For example, the bisect function developed in
Fig. 5.7 gives a value of f = 0.0289678 with a percent relative error of error of 5.926 × 10–5
in 22 iterations. False position yields a result of similar precision in 26 iterations. Thus,
although they produce the correct result, they are somewhat inefficient. This would not be
important for a single application, but could become prohibitive if many evaluations were
made.
188 Roots: Open Methods
6.7 CASE STUDY continued
6
5
4
3
g( f ) 2
1
0
−1
−2
−30.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08
f
FIGURE 6.11
We could try to attain improved performance by turning to an open method. Because
Eq. (6.15) is relatively straightforward to differentiate, the Newton-Raphson method is a
good candidate. For example, using an initial guess at the lower end of the range (x0 =
0.008), the newtraph function developed in Fig. 6.7 converges quickly:
>> dg = @(f) −2/log(10)*1.255/Re*f^(−3/2)/(e/D/3.7 ...
+2.51/Re/sqrt(f))−0.5/f^(3/2);
>> [f ea iter] = newtraph(g,dg,0.008)
f=
0.02896781017144
ea =
6.870124190058040e−006
iter =
6
However, when the initial guess is set at the upper end of the range (x0 = 0.08), the routine
diverges,
>> [f ea iter] = newtraph(g,dg,0.08)
f= NaNi
NaN +
As can be seen by inspecting Fig. 6.11, this occurs because the function’s slope at the
initial guess causes the first iteration to jump to a negative value. Further runs demonstrate
that for this case, convergence only occurs when the initial guess is below about 0.066.
6.7 CASE STUDY 189
6.7 CASE STUDY continued
So we can see that although the Newton-Raphson is very efficient, it requires good ini-
tial guesses. For the Colebrook equation, a good strategy might be to employ the Swamee-
Jain equation (Eq. 6.16) to provide the initial guess as in
>> fSJ=1.325/log(e/(3.7*D)+5.74/Re^0.9)^2
fSJ =
0.02903099711265
>> [f ea iter] = newtraph(g,dg,fSJ)
f=
0.02896781017144
ea =
8.510189472800060e−010
iter =
3
Aside from our homemade functions, we can also use MATLAB’s built-in fzero func-
tion. However, just as with the Newton-Raphson method, divergence also occurs when
fzero function is used with a single guess. However, in this case, guesses at the lower end
of the range cause problems. For example,
>> fzero(g,0.008)
Exiting fzero: aborting search for an interval containing a sign
change because complex function value encountered ...
during search.
(Function value at −0.0028 is −4.92028−20.2423i.)
Check function or try again with a different starting value.
ans =
NaN
If the iterations are displayed using optimset (recall Example 6.7), it is revealed that a nega-
tive value occurs during the search phase before a sign change is detected and the routine
aborts. However, for single initial guesses above about 0.016, the routine works nicely.
For example, for the guess of 0.08 that caused problems for Newton-Raphson, fzero does
just fine:
>> fzero(g,0.08)
ans =
0.02896781017144
As a final note, let’s see whether convergence is possible for simple fixed-point it-
eration. The easiest and most straightforward version involves solving for the first f in
Eq. (6.15):
( ( ))fi+1 = _ _lo_g__ _ _3_ _.7__ε_ _D0__._ 2 +_5__ R__2_e_._√_5__1___f i__ _ _ 2_ (6.17)
190 Roots: Open Methods
6.7 CASE STUDY continued
y y1 = x
0.05
0.04
0.03 y2 = g(x)
0.02
0.01
00 0.02 0.04 0.06 0.08 x
FIGURE 6.12
The two-curve display of this function depicted indicates a surprising result (Fig. 6.12).
Recall <=tha10t).0.fi0Ax8esdtio-npd0oi.ic0na8ttiemtdeerbaaytnisoFntihgca.ot6nn.vo1et2rg,oenthslyewdfhaoecentsttfhhiaexteydt2h-cepuoyriv2netchuitarevsreaatiirsoenlqauctiiovtneevlfyelrafgtleai,tnbstluohtpeietra(cino.egn.e-,
|g′(ξ)|
from f
verges fairly rapidly! In fact, for initial guesses anywhere between 0.008 and 0.08, fixed-
point iteration yields predictions with percent relative errors less than 0.008% in six or
fewer iterations! Thus, this simple approach that requires only one guess and no derivative
estimates performs really well for this particular case.
The take-home message from this case study is that even great, professionally devel-
oped software like MATLAB is not always foolproof. Further, there is usually no single
method that works best for all problems. Sophisticated users understand the strengths and
weaknesses of the available numerical techniques. In addition, they understand enough
of the underlying theory so that they can effectively deal with situations where a method
breaks down.
Problems 191
PROBLEMS
6.1 Employ fixed-point iteration to locate the root of 6.10 The “divide and average” method, an old-time method
for approximating the square root of any positive number a,
f (x) = sin (√_x_ ) − x can be formulated as
xi+1 = _x_i _+_2_a _∕_x_i
Use an initial guess of x0 = 0.5 and iterate until εa ≤ 0.01%. Prove that this formula is based on the Newton-Raphson
Verify that the process is linearly convergent as described at algorithm.
the end of Sec. 6.1. 6.11 (a) Apply the Newton-Raphson method to the function
6.2 Use (a) fixed-point iteration and (b) the Newton- f (x) = tanh(x2 − 9) to evaluate its known real root at x = 3.
Raphson method to determine a root of f (x) = −0.9x2 + 1.7x + Use an initial guess of x0 = 3.2 and take a minimum of three
t2h.5anuεssin=g0x.00 1=%.5A. Plseorfcohremckthyeoucrofminpaultaatnisowneur.ntil εa is less iterations. (b) Did the method exhibit convergence onto its real
6.3 Determine the highest real root of f (x) = x3 − 6x2 + root? Sketch the plot with the results for each iteration labeled.
11x − 6.1: 6.12 The polynomial f (x) = 0.0074x4 − 0.284x3 + 3.355x2−
(a) Graphically. 12.183x + 5 has a real root between 15 and 20. Apply the
(b) Using the Newton-Raphson method (three iterations, Newton-Raphson method to this function using an initial
x0 = 3.5 guess of x0 =16.15. Explain your results.
(c) Using the secant method (three iterations, x−1 = 2.5 and 6.13 Mechanical engineers, as well as most other engineers,
x0 = 3.5). use thermodynamics extensively in their work. The follow-
(d) Using the modified secant method (three iterations, ing polynomial can be used to relate the zero-pressure spe-
x0 = 3.5, δ = 0.01). cific heat of dry air cp in kJ/(kg K) to temperature in K:
(e) Determine all the roots with MATLAB.
6.4 Determine the lowest positive root of f (x) = cp = 0.99403 + 1.671 × 10−4T + 9.7215 × 10−8T 2
7 sin(x)e−x − 1: −9.5838 × 10−11T 3 + 1.9520 × 10−14T 4
(a) Graphically.
(b) Using the Newton-Raphson method (three iterations,
x0 = 0.3). Write a MATLAB script (a) to plot cp versus a range of T = 0
(c) Using the secant method (three iterations, x−1 = 0.5 and to 1200 K and (b) to determine the temperature that corre-
x0 = 0.4. sponds to a specific heat of 1.1 kJ/(kg K) with MATLAB
(d) Using the modified secant method (five iterations, polynomial functions.
x0 = 0.3, δ = 0.01). 6.14 In a chemical engineering process, water vapor (H2O)
6.5 Use (a) the Newton-Raphson method and (b) the modi- is heated to sufficiently high temperatures that a significant
fied secant method (δ = 0.05) to determine a root of f (x) = portion of the water dissociates, or splits apart, to form oxy-
x5 − 16.05x4 + 88.75x3 − 192.0375x2 + 116.35x + 31.6875 gen (O2) and hydrogen (H2):
using an initial guess of x = 0.5825 and εs = 0.01%. Explain
your results. H2O⇄H2 + _12 O2
6.6 Develop an M-file for the secant method. Along with If it is assumed that this is the only reaction involved, the
the two initial guesses, pass the function as an argument. mole fraction x of H2O that dissociates can be represented by
Test it by solving Prob. 6.3. _____
6.7 Develop an M-file for the modified secant method. √K = _1_−_x _x_ _ 2_2+_p_t x_
Along with the initial guess and the perturbation frac- (P6.14.1)
tion, pass the function as an argument. Test it by solving
Prob. 6.3.
6.8 Differentiate Eq. (E6.4.1) to get Eq. (E6.4.2). where K is the reaction’s equilibrium constant and p=t is the
6.9 Employ the Newton-Raphson method to determine a total pressure of the mixture. If pt = 3 atm and K 0.05,
real root for f (x) = −2 + 6x − 4x2 + 0.5x3, using an ini- determine the value of x that satisfies Eq. (P6.14.1).
6.15 The Redlich-Kwong equation of state is given by
tial guess of (a) 4.5 and (b) 4.43. Discuss and use graphical
and analytical methods to explain any peculiarities in your p = _υ_R−_T_b _ − _ υ_(υ__+_a_b_ )_√___T__
results.
192 Roots: Open Methods TB
y θ
B
A y0 TA W= s
FIGURE P6.17 (a) x (b)
where R = the universal gas constant [= 0.518 kJ/(kg K)], Calculus can be employed to solve this equation for the
T = absolute temperature (K), p = absolute pressure (kPa), height of the cable y as a function of distance x:
and υ = the volume of a kg of gas (m3/kg). The parameters a
and b are calculated by ( )y = _T _ A_ cosh _T _ A_ x + y0 − _T _ A_
a = 0.427 _ R_2_p T_c _2c ._5 b = 0.0866R _ Tp_cc (a) Use a numerical method to calculate a value for the
parameter TA given values for the parameters = 10 and
y0 = 5, such that the cable has a height of y = 15 at x = 50.
Develop a plot of y versus x for x = −50 to 100.
where pc = 4600 kPa and Tc = 191 K. As a chemical engi- (b)
neer, you are asked to determine the amount of methane fuel
that can be held in a 3-m3 tank at a temperature of−40 °C 6.18 An oscillating current in an electric circuit is described
with a pressure of 65,000 kPa. Use a root-locating method by I = 9e−t sin(2πt), where t is in seconds. Determine all
of your choice to calculate υ and then determine the mass of values of t such that I = 3.5
methane contained in the tank. 6.19 Figure P6.19 shows a circuit with a resistor, an induc-
6.16 The volume of liquid V in a hollow horizontal cylinder tor, and a capacitor in parallel. Kirchhoff’s rules can be used
of radius r and length L is related to the depth of the liquid h by to express the impedance of the system as
_______ _______________
√ 2rh − h2 L √ ( )_ Z1_ = _R1_2_ + ωC − _ω1_L_ 2
[ ( ) ]V
= r 2cos−1 _r_−_r _h_ − (r − h) where Z = impedance (Ω), and ω is the angular frequency. Find
the ω that results in an impedance of 100 Ω using the fzero
Determine h given r = 2 m, L = 5 m, and V = 8 m3. function with initial guesses of 1 and 1000 for the following
6.17 A catenary cable is one which is hung between parameters: R = 225 Ω, C = 0.6 × 10−6 F, and L = 0.5 H.
two points not in the same vertical line. As depicted in
Fig. P6.17a, it is subject to no loads other than its own
weight. Thus, its weight acts as a uniform load per unit
length along the cable (N/m). A free-body diagram of a
section AB is depicted in Fig. P6.17b, where TA and TB are
R LC
the tension forces at the end. Based on horizontal and verti-
cal force balances, the following differential equation model
of the cable can_b_e_d_e_r_i_v_ed:
√ ( ) _dd_ x2_ y2_ = _T _ A_ _dd_xy_ 2
1 + FIGURE P6.19
Problems 193
h h+d Find the appropriate initial angle θ0, if υ0 = 30 m/s, and the
d (b) distance to the catcher is 90 m. Note that the throw leaves the
right fielder’s hand at an elevation of 1.8 m and the catcher
(a) receives it at 1 m.
FIGURE P6.20 6.22 You are designing a spherical tank (Fig. P6.22) to hold
water for a small village in a developing country. The vol-
ume of liquid it can hold can be computed as
V = πh2 _[3_R__3−_ __h_]
where V = volume [m3], h = depth of water in tank [m], and
R = the tank radius [m].
6.20 Real mechanical systems may involve the deflection R
of nonlinear springs. In Fig. P6.20, a block of mass m is
released a distance h above a nonlinear spring. The resis-
tance force F of the spring is given by
F = −(k1d + k2d 3∕2)
Conservation of energy can be used to show that Vh
0 = 2_k_2_5d_ 5_∕_2 + _12_ k1d2 − mgd − mgh FIGURE P6.22
If R = 3 m, what depth must the tank be filled to so
Solve for d, given the following p9a5ragm, get=er9v.8a1lumes/:s2,k1an=d
40,000 g/s2, k2 = 40 g/(s2 m0.5), m = that it holds 30 m3? Use three iterations of the most efficient
h = 0.43 m. numerical method possible to determine your answer. De-
6.21 Aerospace engineers sometimes compute the trajec termine the approximate relative error after each iteration.
tories of projectiles such as rockets. A related problem deals Also, provide justification for your choice of method. Extra
with the trajectory of a thrown ball. The trajectory of a ball information: (a) For bracketing methods, initial guesses of
thrown by a right fielder is defined by the (x, y) coordinates 0 and R will bracket a single root for this example. (b) For
as displayed in Fig. P6.21. The trajectory can be modeled as open methods, an initial guess of R will always converge.
6.23 Perform the identical MATLAB operations as those
y = (tan θ0)x − _ 2_υ_02_ _cgo_ _s2_ θ_0_ x2 + y0 in Example 6.8 to manipulate and find all the roots of the
p olynomial
y
f 5(x) = (x + 2)(x + 5)(x − 6)(x − 4)(x − 8)
υ0 x 6.24 In control systems analysis, transfer functions are
θ0 d eveloped that mathematically relate the dynamics of a sys-
tem’s input to its output. A transfer function for a robotic
FIGURE P6.21 p ositioning system is given by
G(s) = _CN_((_ss_)) = _ s4__+_1_s5_3 s_+3_+_ 9_s72_ 7_+s_22_+6__s1_ +5_3_2s_4+__9_0_
194 Roots: Open Methods
where G(s) = system gain, C(s) = system output, N(s) = tsIahfenecydaosxneuutcua=msneet2t.mahIobefdrtyha,ocoukudse,eutuisansenegtihminneieittNtiihaaelolwgdgu,tuoeuensss-sesReisaonpofithfixasxioli=−ng1uo=0er.s70sth.eaesInfomdyfoxoxdiul i==fuie2s0de..
system input, and s = Laplace transform complex frequency. 6.30 (a) Develop an M-file function to implement Brent’s
Use MATLAB to find the roots of the numerator and de- root-location method. Base your function on Fig. 6.10, but
nominator and factor these into the form with the beginning of the function changed to
G(s) = _ ( s__+_(sb_1_+)_(s_a _1+ )_(_sb_2+)_(_sa_2+ )_(_sb _3+_)(_sa_3+_)_b_4_) function [b,fb] = fzeronew(f, xl, xu,varargin)
where ai and bi = the roots of the numerator and denomina- % fzeronew: Brent root location zeroes
tor, respectively. % [b,fb] = fzeronew(f,xl,xu,p1,p2,...):
6.25 The Manning equation can be written for a rectangular % uses Brent’s method to find the root of f
open channel as % input:
% f = name of function
Q = _n√_(B__S__+ _ (B_2_HH_)_)52∕_∕3_3 % xl, xu = lower and upper guesses
where Q = flow (m3/s), S = slope (m/m), H = depth (m), % p1,p2,... = additional parameters used by f
and n = the Manning roughness coefficient. Develop a fixed- % output:
point iteration scheme to solve this equation for H given % b = real root
Q = 5, S = 0.0002, B = 20, and n = 0.03. Perform the compu- % fb = function value at root
tation until εa is less than εs = 0.05%. Prove that your scheme
converges for all initial guesses greater than or equal to zero. Make the appropriate modifications so that the function per-
6.26 See if you can develop a foolproof function to com- forms as outlined in the documentation statements. In addi-
pute the friction factor based on the Colebrook equation as tion, include error traps to ensure that the function’s three
described in Sec. 6.7. Your function should return a precise required arguments (f,xl,xu) are prescribed, and that the
result for Reynolds number ranging from 4000 to 107 and for initial guesses bracket a root.
ε/D ranging from 0.00001 to 0.05. (b) Test your function by using it to solve for the root of the
6.27 Use the Newton-Raphson method to find the root of
function from Example 5.6 using
f (x) = e−0.5x (4 − x) − 2 >> [x,fx] = fzeronew(@(x,n) x^n − 1,0,1.3,10)
Employ initial guesses of (a) 2, (b) 6, and (c) 8. Explain 6.31 Figure P6.31 shows a side view of a broad crested
your results. weir. The symbols shown in Fig. P6.31 are defined as: Hw =
6.28 Given the height of the weir (m), Hh = the head above the weir
(m), and H = Hw + Hh = the depth of the river upstream
f (x) = −2x6 − 1.5x4 + 10x + 2
of the weir (m).
Use a root-location technique to determine the maximum of
this function. Perform iterations until the approximate relative
error falls below 5%. If you use a bracketing method, use initial Hh Qw
guesses of xl =se0caanntdmxeut=ho1d.,Iufsyeoaunuisneittihael gNueewsstoonf -xRi =ap1h.sIof nyoour H Weir
the modified
use the secant method, use initial guesses of xi − 1 = 0 and xi = 1. Hw
Assuming that convergence is not an issue, choose the tech- Lw
nique that is best suited to this problem. Justify your choice.
6.29 You must determine the root of the following easily FIGURE P6.31
differentiable function: A broad-crested weir used to control depth and
velocity of rivers and streams.
e0.5x = 5 − 5x
Pick the best numerical technique, justify your choice, and The flow across the weir, Qw (m3/s), can be computed as
then use that technique to determine the root. Note that it (Munson et al., 2009)
is known that for positive initial guesses, all techniques ex-
cept fixed-point iteration will eventually converge. Perform ( )Q w = Cw Bw √ _g_ _23_ 3∕2H 3h ∕2 (P6.31.1)
iterations until the approximate relative error falls below 2%.
Problems 195
where Cw =a weir coefficient (dimensionless), Bw = the Determine the solution approach that converges for initial
weir width (m), and g = the gravitational constant (m/s2). Cw guesses in the range of 0 < x < 7. Use either a graphical or
analytical approach to prove that your formulation always
can be determined using the weir height (Hw) as in converges in the given range.
6.35 A circular pipe made out of new cast iron is used to
√C w = 1.125 __ 12__++____HH____hh __∕∕__HH__ww__ (P6.31.2) convey water at a volume flow rate of Q = 0.3 m3/s. Assume
that the flow is steady and fully developed and the water
Given g = 9.81 m/s2, Hw = 0.8 m, Bw = 8 m, and Qw = 1.3 is incompressible. The head loss, friction, and diameter are
m3/s, determine the upstream depth, H, using (a) the modi- related by the Darcy-Weisbach equation,
fied secant method with δ = 10–5, (b) fixed-point iteration,
and (c) the MATLAB function fzero. For all cases employ hL = f _DL_V 2_ 2g_ (P6.35.1)
an initial guess of 0.5Hw, which for this case is 0.4. For (b) where f = the friction factor (dimensionless), L = length (m),
also prove that your result will be convergent for positive D = pipe inner diameter (m), V = velocity (m/s), and g =
initial guesses. the gravitational constant (= 9.81 m/s2). The velocity can be
6.32 The following reversible chemical reaction describes related to flow by
how gaseous phases of methane and water react to form car-
bon dioxide and hydrogen in a closed reactor,
C H4 + 2H2 O ⇔ CO2 + 4H2 Q = A cV (P6.35.2)
with the equilibrium relationship where Ac = the pipe’s cross-sectional area (m2) = πD2/4 and
the friction factor can be determined by the Colebrook equa-
K = _[ C[_C_HO_4_ 2]_ ] [_ [H_ H_2 2O_ ]_4 ]_2 tion. If you want the head loss to be less than 0.006 m per
where K = the equilibrium coefficient and the brackets meter of pipe, develop a MATLAB function to determine
[] designate molar concentrations (mole/L). Conserva- the smallest diameter pipe to achieve this objective. Use the
tion of mass can be used to reformulate the equilibrium following parameter values: υ = 1.16 × 10–6 m2/s and ε =
relationship as 0.4 mm.
6.36 Figure P6.36 shows an asymmetric diamond-shaped
( ( ))(( ) )K = _ _M___ _C__H_V_ 4__ _−___ x_ _ _V x __ _ __4 _MV__x__ _ _H 4__ 2 __O V__ −____2 __x_ _ _2 supersonic airfoil. The orientation of the airfoil relative to
the airflow is represented by a number of angles: α = the
where x = the number of moles created in the forward direc- angle of attack, β = the shock angle, θ = the deflection
tion (mole), V = the volume of the reactor (L), and Mi = the angle, with the subscripts “l” and “u” designating the lower
initial number of moles of constituent i (mole). Given that and upper surfaces of the airfoil. The following formula
mK i=ne7x×u1si0n−g3,(Va)=fi2x0edL-,paonindtMite C rHa 4ti=onMa nHd 2O(b=) 1 moles, deter- relates the deflection angle to the oblique shock angle and
fzero. speed,
tan θ = 2_ M c_o_ 2t_(_βk_(+M__ c2_os _ si_n2_2β_β_+_−_2_1)_)
6.33 The concentration of pollutant bacteria c in a lake de-
creases according to
c = 77e−1.5t + 20e−0.08t α θu
βu
Determine the time required for the bacteria concentration to
be reduced to 15 using the Newton-Raphson method with an βl θl
initial guess of t = 6 and a stopping criterion of 1%. Check
your result with fzero. FIGURE P6.36
6.34 You are asked to solve for the root of the following A diamond-shaped airfoil.
equation with fixed-point iteration:
x4 = 5x + 10
196 Roots: Open Methods
where M = the Mach number which is the ratio of the jet’s [Hint: The problem can be solved by integrating Eq. (P6.37)
speed, υ (m/s), to the speed of sound, c (m/s), where two times to yield an equation for x as a function of t.]
c = _____ x=0
v
√ kRTa
where k = the ratio of specific heats which for Kai)r),isancpd/cTυa(==
1.4), R = the air gas constant (= 287 N m/(kg
the air’s absolute temperature (K). Given estimates of M, k,
and θ, the shock angle can be determined as the root of
f ( β) = _ 2M _c_o2_t(_kβ_(+M__c2_os _s i_2n_2β_β_+_−_2_1)_ ) − tan θ x=L
x
The pressure on the airfoil surface, pa (kPa), can then be FIGURE P6.37
computed as A sphere settling in a cylinder filled with viscous honey.
( )pa = p _k_2+_k_ 1_ (M sin β)2 − _kk_+−__11_
Suppose that the airfoil is attached to a jet traveling at a
speed υ = 625 m/s through air with a temperature T = 4 °C,
pressure (pa)=ge1n1e0ratkePaa,plaontdofθfu (β=u)4v°e.rDsuesvβeulo=p2a° MATLAB 6.38 As depicted in Fig. P6.38a, a scoreboard is suspended
script to to 88°, and above a sports arena by two cables, pinned at A, B, and C.
The cables are initially horizontal and of length L. After the
(b) compute the pressure on the upper surface of the airfoil. scoreboard is hung, a free-body diagram at node B can be de-
6.37 As described in Sec. 1.4, for objects falling through
fluids at very low speeds, the flow regime around the object veloped as shown in Fig. P6.38b. Assuming that the weight of
each cable is negligible, determine the deflection, d (m), that
will be laminar and the relationship between the drag force results if the scoreboard weighs W = 9000 N. Also, compute
and velocity is linear. In addition, in such cases, the buoy-
ancy force must also be included. For such cases, a force how much each cable is elongated. Note that each cable obeys
Hooke’s law such that the axial elongation is represented by
balance can be written as L′ – L = FL /(AcE) where F = the axial force (N), Ac = the ca-
ble’s cross-sectional area (m2), and E = the modulus of elastic-
_dd_vt_ = g − _ ρm_f V_ g − _cm_d υ (P6.37) ity (N/m2). Use the following parameters for your calculations:
L = 45 m, Ac = 6.362 × 10–4 m2, and E = 1.5 × 1011 N/m2.
(gravity) (buoyancy) (drag)
where υ = velocity (m/s), t = time (s), m = the mass of the AL L C
particle (kg), g = the gravitational constant (= 9.81 m/s2),
tρchdfe==ptafhrleutiicldilnedecaearnnsdirbtayegc(ckoogme/fmpfui3c)tie,edVntas=(kVgpρ/amsr,t)wi.cNhleeorvteeoρtlhus am=tetthh(eemmd3)ea,nsssainotdyf d
of the particle (kg/m3). For a small sphere, Stokes developed L′ B
the following formula for the drag coefficient, cd = 6πμr,
where μ = the fluid’s dynamic viscosity (N s/m2), and r = The Rabid Hippos
the sphere’s radius (m).
Home Period Visitor
You release an iron sphere at the surface of a container (a)
(x = 0) filled with honey (Fig. P6.37) and then measure how FF
long it takes to settle to the bottom (x = L). Use this infor-
θ
mation to estimate the honey’s viscosity based on the fol- W
lowing parameter =va0l.u5ems: ,ρafn=d t1(x42=00k.5g)/m=3,3.ρ6s = 7850 kg/ FIGURE P6.38 (b)
m3, r = 0.02 m, L s. Check the
(a) Two thin cables pinned at A, B, and C with a score-
board suspended from B. (b) Free-body diagram of the
Reynolds number (Re = ρf υd/μ, where d = diameter) to con- pin at B after the scoreboard is hung.
firm that laminar conditions occurred during the experiment.
Problems 197
6.39 A water tower is connected to a pipe with a valve at its d = pipe =diaemqueitvearl(emnt),leLne,ge t=h equivalent length for the elbow
end as depicted in Fig. P6.39. Under a number of simplify- (m), Le,v for the valve (m), and K = loss
ing assumptions (e.g., minor friction losses neglected), the coefficient for the contraction at the bottom of the tank.
following energy balance can be written Write a MATLAB script to determine the flow exiting the
valve, Q (m3/s), using the following parameter values: h =
( )gh − _υ2_2 = f _L_+d__ h_ + _L d_e,_ e + _L d_e,_ υ _υ2_2 + K _υ2_2 24 m, L = 65 m, d = 100 mm, Le,e∕d = 30, Le,υ∕d = 8, and
K = 0.5. In addition, the kinematic viscosity of water is υ=
where g = gravitational acceleration (= 9.81 m/s2), h = μ/ρ = 1.2 × 10–6 m2/s.
tower height (m), υ = mean water velocity in pipe (m/s), 6.40 Modify the fzerosimp function (Fig. 6.10) so that it
f = the pipe’s friction factor, L = horizontal pipe length (m), can be passed any function with a single unknown and uses
varargin to pass the function’s parameters. Then test it with
hd the following script to obtain a solution for pipe friction
d based on Case Study 6.3,
Q
L clc
format long, format compact
FIGURE P6.39 rho = 1.23;mu = 1.79e − 5;D=0.005;V = 40;e = 0.0015/1000;
A water tower connected to a pipe with a valve at Re = rho*V*D/mu;
its end. g = @(f,e,D) 1/sqrt(f)+2*log10(e/(3.7*D)+2.51/
(Re*sqrt(f)));
f = fzerosimp(@(x) g(x,e,D),0.008,0.08)
7
Optimization
CHAPTER OBJECTIVES
The primary objective of this chapter is to introduce you to how optimization can be
used to determine minima and maxima of both one-dimensional and multidimensional
functions. Specific objectives and topics covered are
• Understanding why and where optimization occurs in engineering and scientific
problem solving.
• Recognizing the difference between one-dimensional and multidimensional
optimization.
• Distinguishing between global and local optima.
• Knowing how to recast a maximization problem so that it can be solved with a
minimizing algorithm.
• Being able to define the golden ratio and understand why it makes one-
dimensional optimization efficient.
• Locating the optimum of a single-variable function with the golden-section search.
• Locating the optimum of a single-variable function with parabolic interpolation.
• Knowing how to apply the fminbnd function to determine the minimum of a
one-dimensional function.
• Being able to develop MATLAB contour and surface plots to visualize two-
dimensional functions.
• Knowing how to apply the fminsearch function to determine the minimum of a
multidimensional function.
YOU’VE GOT A PROBLEM
An object like a bungee jumper can be projected upward at a specified velocity. If it
is subject to linear drag, its altitude as a function of time can be computed as
( )z = z 0 + _ mc_ υ0 + _mc_g_ (1 − )e−(c∕m)t − _ mc_g_ t (7.1)
198
7.1 INTRODUCTION AND BACKGROUND 199
z, m 200
100 Maximum
0 elevation
−100 t, s
2 4 6 8 10 12
FIGURE 7.1
Elevation as a function of time for an object initially projected upward with an initial velocity.
where z = altitude (m) above the earth’s surface (defined as z = 0), z0 = the initial altitude
(m), m = mass (kg), c = a linear drag coefficient (kg/s), υ0 = initial velocity (m/s), and t =
time (s). Note that for this formulation, positive velocity is considered to be in the upward
direction. Given the following parameter values: g = 9.81 m/s2, z0 = 100 m, υ0 = 55 m/s,
m = 80 kg, and c= 15 kg/s, Eq. (7.1) can be used to calculate the jumper’s altitude. As
displayed in Fig. 7.1, the jumper rises to a peak elevation of about 190 m at about t = 4 s.
Suppose that you are given the job of determining the exact time of the peak elevation.
The determination of such extreme values is referred to as optimization. This chapter will
introduce you to how the computer is used to make such determinations.
7.1 INTRODUCTION AND BACKGROUND
In the most general sense, optimization is the process of creating something that is as
effective as possible. As engineers, we must continuously design devices and products
that perform tasks in an efficient fashion for the least cost. Thus, engineers are always
confronting optimization problems that attempt to balance performance and limitations. In
addition, scientists have interest in optimal phenomena ranging from the peak elevation of
projectiles to the minimum free energy.
From a mathematical perspective, optimization deals with finding the maxima and
minima of a function that depends on one or more variables. The goal is to determine the
values of the variables that yield maxima or minima for the function. These can then be
substituted back into the function to compute its optimal values.
Although these solutions can sometimes be obtained analytically, most practical
o ptimization problems require numerical, computer solutions. From a numerical stand-
point, optimization is similar in spirit to the root-location methods we just covered in
Chaps. 5 and 6. That is, both involve guessing and searching for a point on a function. The
fundamental difference between the two types of problems is illustrated in Fig. 7.2. Root
location involves searching for the location where the function equals zero. In contrast,
o ptimization involves searching for the function’s extreme points.
200 Optimization
f (x) f ʹ(x) = 0 Maximum
f ʺ(x) < 0
f (x) = 0
Root Root Root x
0
Minimum f ʹ(x) = 0
f ʺ(x) > 0
FIGURE 7.2
A function of a single variable illustrating the difference between roots and optima.
As can be seen in Fig. 7.2, the optimums are the points where the curve is flat. In math-
ematical terms, this corresponds to the x value where the derivative f ′(x) is equal to zero.
Additionally, the second derivative, f ″(x), indicates whether the optimum is a minimum or a
maximum: if f ″(x) < 0, the point is a maximum; if f ″(x) > 0, the point is a minimum.
Now, understanding the relationship between roots and optima would suggest a pos-
sible strategy for finding the latter. That is, you can differentiate the function and locate the
root (i.e., the zero) of the new function. In fact, some optimization methods do just this by
solving the root problem: f ′(x) = 0.
EXAMPLE 7.1 Determining the Optimum Analytically by Root Location
Problem Statement. Determine the time and magnitude of the peak elevation based on
Eq. (7.1). Use the following parameter values for your calculation: g = 9.81 m/s2, z0 = 100 m,
υ0 = 55 m/s, m = 80 kg, and c = 15 kg/s.
Solution. Equation (7.1) can be differentiated to give
_ dd_zt = υ0 e−(c∕m)t − _ mc_g_ (1 − e−(c∕m)t ) (E7.1.1)
Note that because υ = dz/dt, this is actually the equation for the velocity. The maximum el-
evation occurs at the value of t that drives this equation to zero. Thus, the problem amounts
to determining the root. For this case, this can be accomplished by setting the derivative to
zero and solving Eq. (E7.1.1) analytically for
( )t = _ mc_ ln 1 + _cm_ υg_0
Substituting the parameters gives
( )t = _18_05_ ln 1 + _ 81_0_5(_9(_5.8_51_)_ ) = 3.83166 s
7.1 INTRODUCTION AND BACKGROUND 201
This value along with the parameters can then be substituted into Eq. (7.1) to compute the
maximum elevation as
( )z = 100 + _ 18_50_ 50 + _ 8_0_(1_95_.8_ 1__ ) (1 − )e−(15/80)3.83166 − _ 8_0_(1_95_.8_ 1__) (3.83166) = 192.8609 m
We can verify that the result is a maximum by differentiating Eq. (E7.1.1) to obtain
the second derivative
_dd_2t_z2 = −_ mc_ υ0e−(c∕m)t − ge−(c∕m)t = −9.81 _ ms_2
The fact that the second derivative is negative tells us that we have a maximum. Further,
the result makes physical sense since the acceleration should be solely equal to the force of
gravity at the maximum when the vertical velocity (and hence drag) is zero.
Although an analytical solution was possible for this case, we could have obtained the
same result using the root-location methods described in Chaps. 5 and 6. This will be left
as a homework exercise.
Although it is certainly possible to approach optimization as a roots problem, a variety
of direct numerical optimization methods are available. These methods are available for both
one-dimensional and multidimensional problems. As the name implies, one-dimensional
problems involve functions that depend on a single dependent variable. As in Fig. 7.3a, the
search then consists of climbing or descending one-dimensional peaks and valleys. Multi
dimensional problems involve functions that depend on two or more dependent variables.
FIGURE 7.3
(a) One-dimensional optimization. −Tfh (ixs).fi(gbu)rTewaols-doimilluesntsraiotensalhoopwtimmiiznaimtioizna. tNioonteofthf a(xt)thisis
equivalent to the maximization of
figure can be taken to represent either a maximization (contours increase in elevation up to
the maximum like a mountain) or a minimization (contours decrease in elevation down to the
minimum like a valley).
f (x) f (x) y Optimum f (x*, y*)
x* f (x, y)
Minimum f (x) y*
Maximum −f (x)
x
−f (x) x* x
(a) (b)
202 Optimization
In the same spirit, a two-dimensional optimization can again be visualized as searching out
peaks and valleys (Fig. 7.3b). However, just as in real hiking, we are not constrained to walk
a single direction; instead the topography is examined to efficiently reach the goal.
Finally, the process of finding a maximum versus finding a minimum is essentially
identical because the same value x* both minimizes f (x) and maximizes −f (x). This equiva-
lence is illustrated graphically for a one-dimensional function in Fig. 7.3a.
In the next section, we will describe some of the more common approaches for one-
dimensional optimization. Then we will provide a brief description of how MATLAB can
be employed to determine optima for multidimensional functions.
7.2 ONE-DIMENSIONAL OPTIMIZATION
This section will describe techniques to find the minimum or maximum of a function of a
single variable f (x). A useful image in this regard is the one-dimensional “roller coaster”–
like function depicted in Fig. 7.4. Recall from Chaps. 5 and 6 that root location was com-
plicated by the fact that several roots can occur for a single function. Similarly, both local
and global optima can occur in optimization.
A global optimum represents the very best solution. A local optimum, though not the
very best, is better than its immediate neighbors. Cases that include local optima are called
multimodal. In such cases, we will almost always be interested in finding the global optimum.
In addition, we must be concerned about mistaking a local result for the global optimum.
Just as in root location, optimization in one dimension can be divided into bracketing
and open methods. As described in the next section, the golden-section search is an example
of a bracketing method that is very similar in spirit to the bisection method for root location.
This is followed by a somewhat more sophisticated bracketing approach—parabolic inter-
polation. We will then show how these two methods are combined and implemented with
MATLAB’s fminbnd function.
FIGURE 7.4
A function that asymptotically approaches zero at plus and minus ∞ and has two maximum
and two minimum points in the vicinity of the origin. The two points to the right are local op-
tima, whereas the two to the left are global.
f (x) Local
maximum
Global
maximum
x
Global Local
minimum minimum
7.2 ONE-DIMENSIONAL OPTIMIZATION 203
7.2.1 Golden-Section Search
In many cultures, certain numbers are ascribed magical qualities. For example, we in the
West are all familiar with “lucky 7” and “Friday the 13th.” Beyond such superstitious quan-
tities, there are several well-known numbers that have such interesting and powerful math-
ematical properties that they could truly be called “magical.” The most common of these are
the ratio of a circle’s circumference to its diameter π and the base of the natural logarithm e.
Although not as widely known, the golden ratio should surely be included in the pan-
theon of remarkable numbers. This quantity, which is typically represented by the Greek
letter ϕ (pronounced: fee), was originally defined by Euclid (ca. 300 BCE) because of
its role in the construction of the pentagram or five-pointed star. As depicted in Fig. 7.5,
Euclid’s definition reads: “A straight line is said to have been cut in extreme and mean ratio
when, as the whole line is to the greater segment, so is the greater to the lesser.”
The actual value of the golden ratio can be derived by expressing Euclid’s definition as
_ ℓ_1 ℓ+_1_ ℓ_2 = _ℓℓ_21 (7.2)
Multiplying by ℓ 1∕ℓ 2 and collecting terms yields (7.3)
ϕ2 − ϕ − 1 = 0
where ϕ = ℓ 1∕ℓ 2. The positive root of this equation is the golden ratio: (7.4)
ϕ = _1_+_2_√_ __5__ = 1.61803398874989 . . .
The golden ratio has long been considered aesthetically pleasing in Western cultures.
In addition, it arises in a variety of other contexts including biology. For our purposes, it
provides the basis for the golden-section search, a simple, general-purpose method for de-
termining the optimum of a single-variable function.
The golden-section search is similar in spirit to the bisection approach for locating
roots in Chap. 5. Recall that bisection hinged on defining an interval, specified by a lower
guess (xl) and an upper guess (xu) that bracketed a single root. The presence of a root be-
tween these bounds was verified by determining that f (xl) and f (xu) had different signs. The
root was then estimated as the midpoint of this interval:
xr = _ x_l _+2_ _x_u (7.5)
FIGURE 7.5
Euclid’s definition of the golden ratio is based on dividing a line into two segments so that
the ratio of the whole line to the larger segment is equal to the ratio of the larger segment to
the smaller segment. This ratio is called the golden ratio.
12
1+ 2
204 Optimization
The final step in a bisection iteration involved determining a new smaller bracket. This
was done by replacing whichever of the bounds xl or xu had a function value with the same
sign as f (xr). A key advantage of this approach was that the new value xr replaced one of
the old bounds.
Now suppose that instead of a root, we were interested in determining the minimum
of a one-dimensional function. As with bisection, we can start by defining an interval that
contains a single answer. That is, the interval should contain a single minimum, and hence
is called unimodal. We can adopt the same nomenclature as for bisection, where xl and xu
defined the lower and upper bounds, respectively, of such an interval. However, in contrast
to bisection, we need a new strategy for finding a minimum within the interval. Rather than
using a single intermediate value (which is sufficient to detect a sign change, and hence
a zero), we would need two intermediate function values to detect whether a minimum
occurred.
The key to making this approach efficient is the wise choice of the intermediate points.
As in bisection, the goal is to minimize function evaluations by replacing old values with
new values. For bisection, this was accomplished by choosing the midpoint. For the golden-
section search, the two intermediate points are chosen according to the golden ratio:
x1 = xl + d (7.6)
x2 = xu − d (7.7)
where
d = (ϕ − 1)(xu − xl) (7.8)
The function is evaluated at these two interior points. Two results can occur:
1. If, as in Fig. 7.6a, f (x1) < f (x2), then f (x1) is the minimum, and the domain of x to the
left of x2, from xl to x2, can be eliminated because it does not contain the minimum. For
this case, x2 becomes the new xl for the next round.
2. If f (x2) < f (x1), then f (x2) is the minimum and the domain of x to the right of x1, from
x1 to xu would be eliminated. For this case, x1 becomes the new xu for the next round.
Now, here is the real benefit from the use of the golden ratio. Because the original x1
and x2 were chosen using the golden ratio, we do not have to recalculate all the function
values for the next iteration. For example, for the case illustrated in Fig. 7.6, the old x1 be-
comes the new x2. This means that we already have the value for the new f (x2), since it is
the same as the function value at the old x1.
To complete the algorithm, we need only determine the new x1. This is done with
Eq. (7.6) with d computed with Eq. (7.8) based on the new values of xl and xu. A similar
a pproach would be used for the alternate case where the optimum fell in the left subinterval.
For this case, the new x2 would be computed with Eq. (7.7).
As the iterations are repeated, the interval containing the extremum is reduced
rapidly. In fact, each round the interval is reduced by a factor of ϕ − 1 (about 61.8%).
That means that after 10 rounds, the interval is shrunk to about 0.61810 or 0.008 or 0.8%
of its initial length. After 20 rounds, it is about 0.0066%. This is not quite as good as
the reduction achieved with bisection (50%), but optimization is a harder problem than
root location.
7.2 ONE-DIMENSIONAL OPTIMIZATION 205
f (x)
Eliminate
Minimum
xl d x1 x
xu
x2 d
(a)
f (x) Old Old
x2 x1
xl x2 x1 x
xu
New
(b)
FIGURE 7.6
(a) The initial step of the golden-section search algorithm involves choosing two interior
points according to the golden ratio. (b) The second step involves defining a new interval
that encompasses the optimum.
EXAMPLE 7.2 Golden-Section Search
Problem Statement. Use the golden-section search to find the minimum of
f (x) = _1x_0 2_ − 2 sin x
within the interval from xl = 0 to xu = 4.
Solution. First, the golden ratio is used to create the two interior points:
d = 0.61803(4 − 0) = 2.4721
x1 = 0 + 2.4721 = 2.4721
x2 = 4 − 2.4721 = 1.5279
206 Optimization
The function can be evaluated at the interior points:
f (x2) = _ 1_.5_12_07_ _9_2 − 2 sin(1.5279) = −1.7647
f (x1) = _ 2_.4_17_02_ _1_2 − 2 sin(2.4721) = −0.6300
Because f (x2) < f (x1), our best estimate of the minimum at this point is that it is
l ocated at x = 1.5279 with a value of f (x) = –1.7647. In addition, we also know that the
brmtheocieunafnilomcdruumrlmeaemtreiaxsfi2ni(nvxs1at)xlh,uleie=tibwn0eta,ecsroavdnmaedletesdxr1etmhfbieinencneeodedmwboeyxns1x,tthlht,heexa2ptu,rpiaespnv, edixor1xub=1s.oi1uTte.nh5rdua2,st7i,to9hfn.aoItranistsha,fdex(d1nui.et=5ixo2tn27i,.9t4ew)7r=ea2t1di–o.o1nIn.n,7ot6aht4deh7dal.iovtiweotenor,
All that remains is to use Eqs. (7.8) and (7.7) to compute the new value of d and x2:
d = 0.61803(2.4721 − 0) = 1.5279
x2 = 2.4721 − 1.5279 = 0.9443
The function evaluation at x2 is f (0.9943) = −1.5310. Since this value is less than the
function value at x1, the minimum is f (1.5279) = −1.7647, and it is in the interval pre-
scribed by x2, x1, and xu. The process can be repeated, with the results tabulated here:
i xl f (xl) x2 f (x2) x1 f (x1) xu f (xu) d
1 0 0 1.5279 −1.7647 2.4721 −0.6300 4.0000 3.1136 2.4721
2 0 0 0.9443 −1.5310 1.5279 −1.7647 2.4721 −0.6300 1.5279
3 0.9443 −1.5310 1.5279 −1.7647 1.8885 −1.5432 2.4721 −0.6300 0.9443
4 0.9443 −1.5310 1.3050 −1.7595 1.5279 −1.7647 1.8885 −1.5432 0.5836
5 1.3050 −1.7595 1.5279 −1.7647 1.6656 −1.7136 1.8885 −1.5432 0.3607
6 1.3050 −1.7595 1.4427 −1.7755 1.5279 −1.7647 1.6656 −1.7136 0.2229
7 1.3050 −1.7595 1.3901 −1.7742 1.4427 −1.7755 1.5279 −1.7647 0.1378
8 1.3901 −1.7742 1.4427 −1.7755 1.4752 −1.7732 1.5279 −1.7647 0.0851
Note that the current minimum is highlighted for every iteration. After the eighth
iteration, the minimum occurs at x = 1.4427 with a function value of −1.7755. Thus, the
result is converging on the true value of −1.7757 at x = 1.4276.
Recall that for bisection (Sec. 5.4), an exact upper bound for the error can be calculated
at each iteration. Using similar reasoning, an upper bound for golden-section search can be
derived as follows: Once an iteration is complete, the optimum will either fall in one of two
intervals. If the optimum function value is at x2, it will be in the lower interval (xl, x2, x1). If
the optimum function value is at x1, it will be in the upper interval (x2, x1, xu). B ecause the
interior points are symmetrical, either case can be used to define the error.
7.2 ONE-DIMENSIONAL OPTIMIZATION 207
Looking at the upper interval (x2, x1, xu), if the true value were at the far left, the maxi-
mum distance from the estimate would be
Δxa = x1 − x2
= xl + (ϕ − 1)(xu − xl) − xu + (ϕ − 1)(xu − xl)
= (xl − xu) + 2(ϕ − 1)(xu − xl)
= (2ϕ − 3)(xu − xl)
or 0.2361 (xu − xl). If the true value were at the far right, the maximum distance from the
estimate would be
Δxb = xu − x1
= xu − xl − (ϕ − 1)(xu − xl)
= (xu − xl) − (ϕ − 1)(xu − xl)
= (2 − ϕ)(xu − xl)
or 0.3820 (xu − xl). Therefore, this case would represent the maximum error. This result can
then be normalized to the optimal value for that iteration xopt to yield
| |εa = (2 − ϕ) _x_ux_−o_p_t x_l × 100% (7.9)
This estimate provides a basis for terminating the iterations.
An M-file function for the golden-section search for minimization is presented in
Fig. 7.7. The function returns the location of the minimum, the value of the function, the
approximate error, and the number of iterations.
The M-file can be used to solve the problem from Example 7.1.
>> g = 9.81;v0 = 55;m = 80;c = 15;z0 = 100;
>> z = @(t) −(z0 + m/c*(v0 + m*g/c)*(1 − exp(−c/m*t)) −m*g/c*t);
>> [xmin,fmin,ea] = goldmin(z,0,8)
xmin =
3.8317
fmin =
−192.8609
ea =
6.9356e−005
Notice how because this is a maximization, we have entered the negative of Eq. (7.1).
Consequently, fmin corresponds to a maximum height of 192.8609.
You may be wondering why we have stressed the reduced function evaluations of
the golden-section search. Of course, for solving a single optimization, the speed savings
would be negligible. However, there are two important contexts where minimizing the
number of function evaluations can be important. These are
1. Many evaluations. There are cases where the golden-section search algorithm may
be a part of a much larger calculation. In such cases, it may be called many times.
Therefore, keeping function evaluations to a minimum could pay great dividends for
such cases.
208 Optimization
function [x,fx,ea,iter] = goldmin(f,xl,xu,es,maxit,varargin)
% goldmin: minimization golden section search
% [x,fx,ea,iter] = goldmin(f,xl,xu,es,maxit,p1,p2,...):
% uses golden section search to find the minimum of f
% input:
% f = name of function
% xl, xu = lower and upper guesses
% es = desired relative error (default = 0.0001%)
% maxit = maximum allowable iterations (default = 50)
% p1,p2,... = additional parameters used by f
% output:
% x = location of minimum
% fx = minimum function value
% ea = approximate relative error (%)
% iter = number of iterations
if nargin < 3,error('at least 3 input arguments required'),end
if nargin < 4|isempty(es), es = 0.0001;end
if nargin < 5|isempty(maxit), maxit = 50;end
phi = (1+sqrt(5))/2; iter = 0;
d = (phi−1)*(xu − xl);
x1 = xl + d; x2 = xu − d;
f1 = f(x1,varargin{:}); f2 = f(x2,varargin{:});
while(1)
xint = xu − xl;
if f1 < f2
xopt = x1; xl = x2; x2 = x1; f2 = f1;
x1 = xl + (phi − 1)*(xu − xl); f1 = f(x1,varargin{:});
else
xopt = x2; xu = x1; x1 = x2; f1 = f2;
x2 = xu − (phi−1)*(xu−xl); f2 = f(x2,varargin{:});
end
iter = iter + 1;
if xopt~ = 0, ea = (2 − phi) * abs(xint / xopt) * 100;end
if ea < = es | iter > = maxit,break,end
end
x = xopt; fx = f(xopt,varargin{:});
FIGURE 7.7
An M-file to determine the minimum of a function with the golden-section search.
2. Time-consuming evaluation. For pedagogical reasons, we use simple functions in
most of our examples. You should understand that a function can be very complex
and time-consuming to evaluate. For example, optimization can be used to estimate
the parameters of a model consisting of a system of differential equations. For such
cases, the “function” involves time-consuming model integration. Any method that
minimizes such evaluations would be advantageous.
7.2 ONE-DIMENSIONAL OPTIMIZATION 209
True maximum Parabolic
f (x) True function approximation
of maximum
Parabolic
function
x1 x2 x4 x3 x
FIGURE 7.8
Graphical depiction of parabolic interpolation.
7.2.2 Parabolic Interpolation
Parabolic interpolation takes advantage of the fact that a second-order polynomial often
provides a good approximation to the shape of f (x) near an optimum (Fig. 7.8).
Just as there is only one straight line connecting two points, there is only one parabola
connecting three points. Thus, if we have three points that jointly bracket an optimum, we
can fit a parabola to the points. Then we can differentiate it, set the result equal to zero, and
solve for an estimate of the optimal x. It can be shown through some algebraic manipula-
tions that the result is
x4 = x2 − _ 21_ _( x_(2x_2−_−_x_1x_)12_)_[[ _ff_((_xx2_2))_−_−_ff_((_ x x_33)_)]]_−_−_((_xx_22_−− __xx_33)_)2_[[_ff_((_xx_2 2)_)−_−_f_f(_(x_x11_))]_] (7.10)
where x1, x2, and x3 are the initial guesses, and x4 is the value of x that corresponds to the
optimum value of the parabolic fit to the guesses.
EXAMPLE 7.3 Parabolic Interpolation
Problem Statement. Use parabolic interpolation to approximate the minimum of
f (x) = _ 1x_02_ − 2 sin x
with initial guesses of x1 = 0, x2 = 1, and x3 = 4.
Solution. The function values at the three guesses can be evaluated:
x1 = 0 f (x1) = 0
x2 = 1 f (x2) = −1.5829
x3 = 4 f (x3) = 3.1136
210 Optimization
and substituted into Eq. (7.10) to give
x4 = 1 − _21_ _ (( 1_1_−−__00_))2_[[_−−_ 11_ _..55_88_22_99__−−_33_ .._ 11_11_33_66_]]_−−__((_11 _−−__44_))_2[_[−−_1_1._ 5 .5_88_22_99_−_−_0_0]_] = 1.5055
which has a function value of f (1.5055) = −1.7691.
Next, a strategy similar to the golden-section search can be employed to determine
which point should be discarded. Because the function value for the new point is lower
than for the intermediate point (x2) and the new x value is to the right of the intermediate
point, the lower guess (x1) is discarded. Therefore, for the next iteration:
x1 = 1 f (x1) = −1.5829
x2 = 1.5055 f (x2) = −1.7691
x3 = 4 f (x3) = 3.1136
which can be substituted into Eq. (7.10) to give
x4 = 1.5055 − _21_ _(1( _1._5.5_00_55_55_−_−_1_1) _2) _[[_−−_11_..77_66_99_11__−− _ _33_..11_11_33_66_]]_−−__(( _ 11_..55_00_55_55__−−__44_)) 2_ [_−[−_1_1._7.7_66_99_11_−_− _(_−(−_1_1.5_.58_82_29_9)_])_]
= 1.4903
which has a function value of f (1.4903) = −1.7714. The process can be repeated, with the
results tabulated here:
i x1 f (x1) x2 f (x2) x3 f (x3) x4 f (x4)
1 0.0000 0.0000 1.0000 −1.5829 4.0000 3.1136 1.5055 −1.7691
2 1.0000 −1.5829 1.5055 −1.7691 4.0000 3.1136 1.4903 −1.7714
3 1.0000 −1.5829 1.4903 −1.7714 1.5055 −1.7691 1.4256 −1.7757
4 1.0000 −1.5829 1.4256 −1.7757 1.4903 −1.7714 1.4266 −1.7757
5 1.4256 −1.7757 1.4266 −1.7757 1.4903 −1.7714 1.4275 −1.7757
Thus, within five iterations, the result is converging rapidly on the true value of −1.7757
at x = 1.4276.
7.2.3 MATLAB Function: fminbnd
Recall that in Sec. 6.4 we described Brent’s method for root location, which combined sev-
eral root-finding methods into a single algorithm that balanced reliability with efficiency.
Because of these qualities, it forms the basis for the built-in MATLAB function fzero.
Brent also developed a similar approach for one-dimensional minimization which
forms the basis for the MATLAB fminbnd function. It combines the slow, dependable
golden-section search with the faster, but possibly unreliable, parabolic interpolation. It
first attempts parabolic interpolation and keeps applying it as long as acceptable results are
obtained. If not, it uses the golden-section search to get matters in hand.
7.3 MULTIDIMENSIONAL OPTIMIZATION 211
A simple expression of its syntax is
[xmin, fval] = fminbnd(function,x1,x2)
where x and fval are the location and value of the minimum, function is the name
of the function being evaluated, and x1 and x2 are the bounds of the interval being
searched.
Here is a simple MATLAB session that uses fminbnd to solve the problem from
E xample 7.1.
>> g = 9.81;v0 = 55;m = 80;c = 15;z0 = 100;
>> z = @(t) −(z0 + m/c*(v0 + m*g/c)*(1 − exp(−c/m*t)) − m*g/c*t);
>> [x,f] = fminbnd(z,0,8)
x=
3.8317
f=
−192.8609
As with fzero, optional parameters can be specified using optimset. For example, we
can display calculation details:
>> options = optimset('display','iter');
>> fminbnd (z,0,8,options)
Func-count x f(x) Procedure
1 3.05573 −189.759 initial
2 4.94427 −187.19 golden
3 1.88854 −171.871 golden
4 3.87544 −192.851 parabolic
5 3.85836 −192.857 parabolic
6 3.83332 −192.861 parabolic
7 3.83162 −192.861 parabolic
8 3.83166 −192.861 parabolic
9 3.83169 −192.861 parabolic
Optimization terminated:
the current x satisfies the termination criteria using
OPTIONS.TolX of 1.000000e − 004
ans =
3.8317
Thus, after three iterations, the method switches from golden to parabolic, and after eight
iterations, the minimum is determined to a tolerance of 0.0001.
7.3 MULTIDIMENSIONAL OPTIMIZATION
Aside from one-dimensional functions, optimization also deals with multidimensional
functions. Recall from Fig. 7.3a that our visual image of a one-dimensional search was
like a roller coaster. For two-dimensional cases, the image becomes that of mountains and
v alleys (Fig. 7.3b). As in the following example, MATLAB’s graphic capabilities provide
a handy means to visualize such functions.
212 Optimization
EXAMPLE 7.4 Visualizing a Two-Dimensional Function
Problem Statement. Use MATLAB’s graphical capabilities to display the following
function and visually estimate its minimum in the range –2 ≤ x1 ≤ 0 and 0 ≤ x2 ≤ 3:
f (x1, x2) = 2 + x1 − x2 + 2x1 2 + 2x1x2 + x 2 2
Solution. The following script generates contour and mesh plots of the function:
x = linspace(−2,0,40);y = linspace(0,3,40);
[X,Y] = meshgrid(x,y);
Z = 2 + X − Y + 2 * X.^2 + 2 * X.* Y + Y.^2;
subplot(1,2,1);
cs = contour(X,Y,Z);clabel(cs);
xlabel('x_1');ylabel('x_2');
title('(a) Contour plot');grid;
subplot(1,2,2);
cs = surfc(X,Y,Z);
zmin = floor(min(Z));
zmax = ceil(max(Z));
xlabel('x_1');ylabel('x_2');zlabel('f(x_1,x_2)');
title ('(b) Mesh plot');
As displayed in Fig. 7.9, both plots indicate that function has a minimum value of about
f (x1, x2) = 0 to 1 located at about x1 = −1 and x2 = 1.5.
FIGURE 7.9
(a) Contour and (b) mesh plots of a two-dimensional function.
(a) Contour plot (b) Mesh plot
3 +3 +7+6
2.5 8
+4 + 6
1
2+
+2
1.5
x2 4
f (x1, x2)
1 +3 2
0.5 +2 03 0
+4 −1 −0.5 2
x1 1 −1
0−82+7 +6−1+5.5 x2 0 −2 x1
0
7.4 CASE STUDY 213
Techniques for multidimensional unconstrained optimization can be classified in a
number of ways. For purposes of the present discussion, we will divide them depending
on whether they require derivative evaluation. Those that require derivatives are called gra-
dient, or descent (or ascent), methods. The approaches that do not require derivative evalu-
ation are called nongradient, or direct, methods. As described next, the built-in MATLAB
function fminsearch is a direct method.
7.3.1 MATLAB Function: fminsearch
Standard MATLAB has a function fminsearch that can be used to determine the mini-
mum of a multidimensional function. It is based on the Nelder-Mead method, which is
a d irect-search method that uses only function values (does not require derivatives) and
h andles non-smooth objective functions. A simple expression of its syntax is
[xmin, fval] = fminsearch (function,x0)
where xmin and fval are the location and value of the minimum, function is the name of the func-
tion being evaluated, and x0 is the initial guess. Note that x0 can be a scalar, vector, or a matrix.
Here is a simple MATLAB session that uses fminsearch to determine minimum for the
function we just graphed in Example 7.4:
>> f = @ (x) 2 + x (1) − x (2) + 2*x (1)^2 + 2*x (1)*x (2) + x (2)^2;
>> [x,fval] = fminsearch (f,[−0.5,0.5])
x= 1.5000
−1.0000
fval =
0.7500
7.4 CASE STUDY EQUILIBRIUM AND MINIMUM POTENTIAL ENERGY
Background. As in Fig. 7.10a, an unloaded spring can be attached to a wall mount. When
a horizontal force is applied, the spring stretches. The displacement is related to the force
by Hookes law, F = kx. The potential energy of the deformed state consists of the differ-
ence between the strain energy of the spring and the work done by the force:
PE(x) = 0.5kx 2 − Fx (7.11)
FIGURE 7.10
(a) An unloaded spring attached to a wall mount. (b) Application of a horizontal force stretches
the spring where the relationship between force and displacement is described by Hooke’s law.
k
(a)
x
F
(b)
214 Optimization
7.4 CASE STUDY continued
Equation (7.11) defines a parabola. Since the potential energy will be at a minimum
at equilibrium, the solution for displacement can be viewed as a one-dimensional optimi-
zation problem. Because this equation is so easy to differentiate, we can solve for the dis-
placement as x = F∕k. For example, if k = 2 N∕cm and F = 5 N, x = 5N∕(2 N/cm) =
2.5 cm.
A more interesting two-dimensional case is shown in Fig. 7.11. In this system, there
are two degrees of freedom in that the system can move both horizontally and vertically.
In the same way that we approached the one-dimensional system, the equilibrium deforma-
tions are the values of x1 and x2 that minimize the potential energy:
____________
√x 12 + (La − x2)2
( )PE(x1,= − La 2
x2) 0.5ka
( )+ 0.5kb √_ x12_ _+__(L_b_ _+_x_2_)_2 − Lb 2 − F1x1 − F2 x2 (7.12)
IFf2t=he4pNar,aumseetMersAaTrLe AkaB=to9sNol/vcemf,okrbth=e 2 N/cm, La = 10 cm, Lb = 10 cm, F1 = 2 N, and
displacements and the potential energy.
FIGURE 7.11
A two-spring system: (a) unloaded and (b) loaded.
La ka F2
Lb kb
F1
(a)
x2
x1
(b)
PROBLEMS 215
7.4 CASE STUDY continued
Solution. An M-file can be developed to hold the potential energy function:
function p = PE(x, ka, kb, La, Lb, F1, F2)
PEa = 0.5*ka*(sqrt(x(1)^2 + (La − x(2))^2) − La)^2;
PEb = 0.5*kb*(sqrt(x(1)^2 + (Lb + x(2))^2) − Lb)^2;
W = F1*x(1) + F2*x(2);
p = PEa + PEb − W;
The solution can be obtained with the fminsearch function:
>> ka = 9;kb = 2;La = 10;Lb = 10;F1 = 2;F2 = 4;
>> [x,f] = fminsearch(@(x) PE(x,ka,kb,La,Lb,F1,F2),[−0.5,0.5])
x= 1.2769
4.9523
f=
−9.6422
Thus, at equilibrium, the potential energy is −9.6422 N · cm. The connecting point is
located 4.9523 cm to the right and 1.2759 cm above its original position.
PROBLEMS
7.1 Perform three iterations of the Newton-Raphson method (c) Differentiate the function and then use a root-location
to determine the root of Eq. (E7.1.1). Use the parameter val- method to solve for the maximum f (x) and the corre-
ues from Example 7.1 along with an initial guess of t = 3 s. sponding value of x.
7.2 Given the formula
7.5 Solve for the value of x that maximizes f (x) in Prob. 7.4
f (x) = −x2 + 8x − 12 using the golden-section search. Employ initial guesses of
xl = 0 and xu = 2, and perform three iterations.
(a) Determine the maximum and the corresponding value of 7.6 Repeat Prob. 7.5, except use parabolic interpolation.
x for this function analytically (i.e., using differentiation). Employ initial guesses of x1 = 0, x2 = 1, and x3 = 2, and
perform three iterations.
(b) Verify that Eq. (7.10) yields the same results based on 7.7 Employ the following methods to find the maximum of
initial guesses of x1 = 0, x2 = 2, and x3 = 6.
f (x) = 4x − 1.8x2 + 1.2x3 − 0.3x4
7.3 Consider the following function:
f (x) = 3 + 6x + 5x2 + 3x3 + 4x4 (a) Golden-section search (xl = – 2, xu = 4, εs = 1%).
Locate the minimum by finding the root of the derivative of (b) Parabolic interpolation (x1 = 1.75, x2 = 2, x3 = 2.5,
this function. Use bisection with initial guesses of xl = −2 iterations = 5).
and xu = 1.
7.4 Given 7.8 Consider the following function:
f (x) = −1.5x6 − 2x4 + 12x f (x) = x4 + 2x3 + 8x2 + 5x
(a) Plot the function. Use analytical and graphical methods to show the func-
(b) Use analytical methods to prove that the function is con- tion has a minimum for some value of x in the range
−2 ≤ x ≤ 1.
cave for all values of x.
216 Optimization
7.9 Employ the following methods to find the minimum of w
the function from Prob. 7.8: −2, −xu2,= = 1%).
(a) Golden-section search (xl = = 1, =εs −1, x3
(b) Parabolic interpolation (x1 x2 = 1,
i terations = 5). hℓ
7.10 Consider the following function: x
f (x) = 2x + _ 3x_ yF
(a) (b)
Perform 10 iterations of parabolic interpolation to locate
the minimum. Comment on the convergence of your results FIGURE P7.15
(x1 = 0.1, x2 = 0.5, x3 = 5) (a) A mountain bike along with (b) a free-body diagram
7.11 The following function defines a curve with several for a part of the frame.
unequal minima over the interval: 2 ≤ x ≤ 20,
( )f (x) = sin(x) + sin _23_ x and vertical displacement of a bike bracketing system in
response to a force. Assume the forces you must analyze
Develop a MATLAB script to (a) plot the function over can be simplified as depicted in Fig. P7.15b. You are inter-
the interval. Determine the minimum (b) with fminbnd and ested in testing the response of the truss to a force exerted
(c) by hand with golden-section search with a stopping cri- in any number of directions designated by the angle θ. The
terion corresponding to three significant figures. For (b) and parameters for the problem are E = Young’s modulus =
(c), use initial guesses of [4, 8]. 2 × 1011 Pa, A = cross-sectional area = 0.0001 m2, = width =
7.12 Use the golden-section search to determine the loca- 0.44 m, ℓ = length = 0.56 m, and h = height = 0.5 m. The
tion, xmax, and maximum, f(xmax), of the following function displacements x and y can be solved by determining the val-
by hand, ues that yield a minimum potential energy. Determine the
displacements for a force of 10,000 N and a range of θ’s
f (x) = −0.8x4 + 2.2x2 + 0.6 from 0° (horizontal) to 90° (vertical).
7.16 As electric current moves through a wire (Fig. P7.16),
Use initial guesses of xl = 0.7 and xu = 1.4 and perform suffi- heat generated by resistance is conducted through a layer of
cient iterations so that εs = 10%. Determine the approximate insulation and then convected to the surrounding air. The
relative error of your final result.
7.13 Develop a single script to (a) generate contour and [ ( ) ]steady-state temperature of the wire can be computed as
mesh subplots of the following temperature field in a similar T = Tair + _2q_π_ _k1_ ln _r _ _r+ _ _r_i + _h1_ _ r_ _1+_ _r_i
fashion to Example 7.4:
ri Tair
T (x, y) = 2x2 + 3y2 − 4xy − y − 3x
rw
and (b) determine the minimum with fminsearch. Tw
7.14 The head of a groundwater aquifer is described in Car-
tesian coordinates by FIGURE P7.16
Cross-section of an insulated wire.
h(x, y) = _1 _+__x_2_+__y1_ 2_ +__x__+__xy_
Develop a single script to (a) generate contour and mesh
subplots of the function in a similar fashion to Example 7.4,
and (b) determine the maximum with fminsearch.
7.15 Recent interest in competitive and recreational cycling
has meant that engineers have directed their skills toward
the design and testing of mountain bikes (Fig. P7.15a). Sup-
pose that you are given the task of predicting the horizontal
PROBLEMS 217
Determine ttehmeptehriactkunreesgsiovfenintshuelaftoilolnowrii (nmg)ptahraatmmetienrism: iqze=s given y0 = 2 m, υ0 = 20 m/s, and θ0 = 45°. Iterate until the
the wire’s approximate error falls below εs = 10% using initial guesses
generation rate = 75 Wof/min, sru la=tiownir=e radius = 6 mm, of xl = 10 and xu = 30 m.
heat thermal conductivity 0.17 W/(m K), 7.22 The deflection of a uniform beam subject to a linearly
k=
h = convective heat transfer coefficient = 12 W/(m2 K), and
Tair = air temperature = 293 K. increasing distributed load can be computed as
7.17 Develop an M-file that is expressly designed to locate y = _ 1_2_0 _E _0_ I_L_ (−x5 + 2L2x3 − L4x)
a maximum with the golden-section search. In other words, Given that L = 600 cm, E = 50,000 kN/cm2, I = 30,000 cm4,
set it up so that it directly finds the maximum rather than and 0 = 2.5 kN/cm, determine the point of maximum de-
finding the minimum of −f(x). The function should have the flection (a) graphically, (b) using the golden-section search
following features: until the approximate error falls below εs = 1% with initial
guesses of xl = 0 and xu = L.
• Iterate until the relative error falls below a stopping cri- 7.23 A object with a mass of 90 kg is projected upward
terion or exceeds a maximum number of iterations. from the surface of the earth at a velocity of 60 m/s. If the
object is subject to linear drag (c = 15 kg/s), use the golden-
• Return both the optimal x and f(x). section search to determine the maximum height the object
attains.
Test your program with the same problem as Example 7.1. 7.24 The normal distribution is a bell-shaped curve defined by
7.18 Develop an M-file to locate a minimum with the
golden-section search. Rather than using the maximum it- y = e−x2
erations and Eq. (7.9) as the stopping criteria, determine the
number of iterations needed to attain a desired tolerance. Use the golden-section search to determine the location of
Test your function by solving Example 7.2 using Ea,d = the inflection point of this curve for positive x.
0.0001. 7.25 Use the fminsearch function to determine the
7.19 Develop an M-file to implement parabolic interpo- minimum of
lation to locate a minimum. The function should have the
f ollowing features: f (x, y) = 2y2 − 2.25xy − 1.75y + 1.5x2
7.26 Use the fminsearch function to determine the
• Base it on two initial guesses, and have the program m aximum of
generate the third initial value at the midpoint of the
interval. f (x, y) = 4x + 2y + x2 − 2x4 + 2xy − 3y2
7.27 Given the following function:
• Check whether the guesses bracket a maximum. If not,
the function should not implement the algorithm, but f (x, y) = −8x + x2 + 12y + 4y2 − 2xy
should return an error message. Determine the minimum (a) graphically, (b) numerically
with the fminsearch function, and (c) substitute the result
• Iterate until the relative error falls below a stopping cri- of (b) back into the function to determine the minimum
terion or exceeds a maximum number of iterations. f (x, y).
7.28 The specific growth rate of a yeast that produces an
• Return both the optimal x and f(x). antibiotic is a function of the food concentration c:
Test your program with the same problem as Example 7.3.
7.20 Pressure measurements are taken at certain points
behind an airfoil over time. These data best fit the curve
y = 6 cos x − 1.5 sin x from x = 0 to 6 s. Use four iterations
of the golden-search method to find the minimum pressure.
Set xl = 2 and xu = 4.
7.21 The trajectory of a ball can be computed with
y = (tan θ0)x − _2_υ_20 _cg_o_ s_2 _θ_0 x2 + y0 g = _4 _+__0_._8_c_+_2_ cc _2_+__0_._2_c_3
As depicted in Fig. P7.28, growth goes to zero at very low
where y = the height (m), θ(0m=/s)t,hegin=itialthaengglerav(riatadtiiaonnsa)l, concentrations due to food limitation. It also goes to zero at
υco0 ns=tantthe= initial velocity y0 = the initial height (m). Use high concentrations due to toxicity effects. Find the value of
9.81 m/s2, and c at which growth is a maximum.
the golden-section search to determine the maximum height
218 Optimization
0.4 12 os
g o
(d−1) 0.2 8
o 5 10 15 20
0 (mg/L) 4 t (d)
0 5 10 oc 0
c (mg/L)
0
FIGURE P7.28
The specific growth rate of a yeast that produces an tc
antibiotic versus the food concentration.
FIGURE P7.31
A dissolved oxygen “sag” below a point discharge of
sewage into a river.
7.29 A compound A will be converted into B in a stirred tank where o = dissolved oxygen concentration (mg/L), os =
reactor. The product B and unreacted A are purified in a sepa- oxygen saturation concentration (mg/L), t = travel time (d),
ration unit. Unreacted A is recycled to the reactor. A process atLBitooOnthD=re a(tbmdei−oi(1xdc)i−,hn1ekg)ms, p=aiocnaidrnalStteob(xm=oyfggss/eeLednt)it,mlidkneedgnm=toaofnrxadBytOge(eBDonfOd(dDdee−m)c1)oac,nmokdnpa(co=mesnigrttie/roLaante/irdooa)nf-.
engineer has found that the initial cost of the system is a func-
tion of the conversion xA. Find the conversion that will result As indicated in Fig. P7.31, Eq. (P7.31) produces an
in the lowest cost system. C is a proportionality constant. oxygen “sag” that reaches a critical minimum level oc, some
travel time tc below the point discharge. This point is called
[ ( ) ( ) ]Cost = C _(1__−_1_ x_A_)_2 0.6 + 6 _x1_A 0.6 “critical” because it represents the location where biota that
depend on oxygen (like fish) would be the most stressed.
7.30 A finite-element model of a cantilever beam subject Develop a MATLAB script that (a) generates a plots of the
to loading and moments (Fig. P7.30) is given by optimizing function versus travel time and (b) uses fminbnd to deter-
mine the critical travel time and concentration, given the fol-
f (x, y) = 5x2 − 5xy + 2.5y2 − x − 1.5y lowing values:
where x = end displacement and y = end moment. Find the
values of x and y that minimize f(x, y). os = 10 mg/L kd = 0.1 d−1 ka = 0.6 d−1
7.31 The Streeter-Phelps model can be used to compute the ks = 0.05 d−1 Lo = 50 mg/L Sb = 1 mg/L/d
dissolved oxygen concentration in a river below a point dis-
charge of sewage (Fig. P7.31), 7.32 The two-dimensional distribution of pollutant concen-
tration in a channel can be described by
( )o = os − _k_d _+k_d_k_Ls _−o_ _k_a e−ka t − e−(kd + ks)t (P7.31)
c(x, y) = 7.9 + 0.13x + 0.21y − 0.05x2
− _ Sk_ab (1 − e−ka t ) −0.016y2 − 0.007xy
x Determine the exact location of the peak concentration given
the function and the knowledge that the peak lies within the
y bounds −10 ≤ x ≤ 10 and 0 ≤ y ≤ 20.
7.33 A total charge Q is uniformly distributed around a ring-
shaped conductor with radius a. A charge q is located at a
distance x from the center of the ring (Fig. P7.33). The force
exerted on the charge by the ring is given by
FIGURE P7.30 F = _4_π1 _e _0 _ (x_2_q+_ Q_a_x2_ )_3/_2
A cantilever beam.
PROBLEMS 219
a D
x 20,000
q
Minimum
10,000 Total
Q Fric 800 Lift
FIGURE P7.33 0 1,200 V
0 400
where =e00=.9 8.85 × 10−12 C2/(N m2), q =Q=2× 10−5 C, FIGURE P7.35
and a m. Determine the distance x where the force is Plot of drag versus velocity for an airfoil.
a maximum.
7.34 The torque transmitted to an induction motor is a func-
tion of the slip between the rotation of the stator field and the
rotor speed s, where slip is defined as differently as velocity increases. Whereas friction drag in-
creases with velocity, the drag due to lift decreases. The com-
s = _n_−_n_ n__R bination of the two factors leads to a minimum drag.
(a) If σ = 0.6 and W = 16,000, determine the minimum drag
where n = revolutions per second of rotating stator speed
and nR = rotor speed. Kirchhoff’s laws can be used to show and the velocity at which it occurs.
that the torque (expressed in dimensionless form) and slip (b) In addition, develop a sensitivity analysis to determine
are related by
how this optimum varies in response to a range of
T = _ ( 1__−__1s)_5(_s4 _(s1_2 _−−__3s)_s_+__4_) W = 12,000 to 20,000 with σ = 0.6.
7.36 Roller bearings are subject to fatigue failure caused by
Figure P7.34 shows this function. Use a numerical method large contact loads F (Fig. P7.36). The problem of finding
to determine the slip at which the maximum torque occurs. the location of the maximum stress along the x axis can be
7.35 The total drag on an airfoil can be estimated by shown to be equivalent to maximizing the function:
( )f
(x) = _ ___0__.__4__ ____ − √_1_+___x_2 1 − _1_0+_._4_x _2 + x
√ 1 + x2
( )D = 0.01σ V 2 + _ 0_.σ9_ 5_ _WV_ 2
Find the x that maximizes f (x).
Friction Lift
where D = drag, σ = ratio of air density between the flight F
altitude and sea level, W = weight, and V = velocity. As seen
in Fig. P7.35, the two factors contributing to drag are affected
T x
4 F
3
2
1
0 0 2 4 6 8 10 s
FIGURE P7.34 FIGURE P7.36
Torque transmitted to an inductor as a function of slip. Roller bearings.
220 Optimization
ka
x1 x2
2F
kb
1
FIGURE P7.37 h
Two frictionless masses connected to a wall by a pair of d
linear elastic springs.
7.37 In a similar fashion to the case study described in FIGURE P7.39
Sec. 7.4, develop the potential energy function for the sys- A ladder leaning against a fence and just touching
tem depicted in Fig. P7.37. Develop contour and surface a wall.
plots in MATLAB. Minimize the potential energy function F or the case where 1 = 2 = 2 m, use a numerical method
to determine the equilibrium displacements x1 and x2 given described in this chapter (including MATLAB’s built-in
the forcing function F = 100 N and the parameters ka = 20 capabilities) to develop a plot of L versus a range of α’s from
and kb = 15 N/m. 45 to 135°.
7.38 As an agricultural engineer, you must design a trap- 7.41 Figure P7.41 shows a pinned-fixed beam subject to a
ezoidal open channel to carry irrigation water (Fig. P7.38). uniform load. The equation for the resulting deflections is
Determine the optimal dimensions to minimize the wetted
perimeter for a cross-sectional area of 50 m2. Are the relative y = – _ 4_8 _ E_ _I (2x4 – 3Lx3 + L3x)
dimensions universal?
7.39 Use the function fminsearch to determine the length L
of the shortest ladder that reaches from the ground over the
fence to the building’s wall (Fig. P7.39). Test it for the case 1
where h = d = 4 m.
7.40 The length of the longest ladder that can negoti-
ate the corner depicted in Fig. P7.40 can be determined
by computing the value of θ that minimizes the following
function:
L(θ) = _si _n _1θ_ + _ s i_n_(_π_− _ _ 2α_ _−__θ_)
α
d2
FIGURE P7.38 FIGURE P7.40
A ladder negotiating a corner formed by two hallways.
PROBLEMS 221
y w x Use these formulas to determine the optimal steady cruise
0 L velocity for a 670 kN jet flying at 10 km above sea level.
Employ the following parameters in your computation: A =
FIGURE P7.41 150 m2, AR = 6.5, CD0 = 0.018, and ρ = 0.413 kg/m3.
7.43 Develop a MATLAB script to generate a plot of the
Develop a MATLAB script that uses fminbnd to (a) generate optimal velocity of the jet from Prob. 7.42 versus elevation
a labeled plot of deflection versus distance and (b) deter- above sea level. Employ a mass of 68,300 kg for the jet.
mine the location and magnitude of the maximum deflec- Note that the gravitational acceleration at 45° latitude can be
tion. Employ an initial guesses of 0 and L and use optimset computed as a function of elevation with
to display the iterations. Use the following parameter values
in your computation (making sure that you use consistent ( )g(h) = 9.8066 _re_r+_e_ h_ 2
units): L = 400 cm, E = 52,000 kN/cm2, I = 32,000 cm4, and
= 4 kN/cm. where g(h) = gravitational acceleration (m∕s2) at elevation
7.42 For a jet in steady, level flight, thrust balances drag h (m) above sea level, and re = Earth’s mean radius (= 6.371 ×
and lift balances weight (Fig. P7.42). Under these condi- 106 m). In addition, air density as a function of elevation can
tions, the optimal cruise speed occurs when the ratio of drag be calculated with
force to velocity is minimized. The drag, CD, can be com-
puted as ρ(h) = − 9.57926 × 10−14 h3 + 4.71260 × 10−9 h2
− 1.18951 × 10−4 h + 1.22534
Employ the other parameters from Prob. 7.42 and design the
plot for elevations ranging from h = 0 to 12 km above sea
CD = CD0 + _π_C ·_ AL 2_ _R level.
7.44 As depicted in Fig. P7.44, a mobile fire hose projects a
fwichieernet,CaDn0d=ARdr=agthceoeafsfpiceicetnrtataitoz. eFroor = the lift coef- stream of water onto the roof of a building. At what angle, θ,
lift, CL level flight, the and how far from the building, x1, should the hose be placed
steady in order to maximize the coverage of the roof; that is, to
lift coefficient can be computed as
maximize: x2 – x1? Note that the water velocity leaving the
CL = _ρ2_υ_W2_ A_ nozzle has a constant value of 3 m/s regardless of the angle,
where W = the jet’s weight (N), ρ = air density (kg/m3), υ = and the other parameter values are h1 = 0.06 m, h2 = 0.2 m,
velocity (m/s), and A = wing planform area (m2). The drag and L = 0.12 m. [Hint: The coverage is maximized for the
force can then be computed as trajectory that just clears the top front corner. That is, we
want to choose –anx1x.1] and θ that just clear the top corner while
FD = W _ CC_DL_ maximizing x2
Lift
Drag Thrust h2
Weight (gravity) L x1
FIGURE P7.42 θ
The four major forces on a jet in steady, level flight.
h1
x2
FIGURE P7.44
222 Optimization
7.45 Since many pollutants enter lakes (and other water- ( )0 = −Ux _ ∂∂_xc_ + E _∂∂_2xc_2 + _ ∂∂_y2c_2 − kc
bodies for that matter) at their peripheries, an important where the x and y axes are defined to be parallel and per-
water-quality problem involves modeling the distribution pendicular to the shoreline, respectively (Fig. P7.45). The
of contaminants in the vicinity of a waste discharge or a parameters and variables acroen: cUexn=tratthioenw, aEte=r vtehloectiutyrbaulolenngt
river. For a vertically well-mixed, constant-depth layer, the the shoreline (m/d), c =
steady-state distribution of a pollutant reacting with first- diffusion coefficient, and k = the first-order decay rate. For
order decay is represented by
the case where a constant loading, W, enters at (0, 0), the
solution for the concentration at any coordinate is given by
Open boundary Solid boundary
∞
c = 2 c(x, y) + ∑ [c (x, y + 2nY ) – c(x, y + 2nY )]
{ }n=1
where
( √ [ ( ) ] )c(x, y) = _ π_HW__E _ e U_2_xE_ x_ K0
Ux Y E Ux __________________
y ( x2 + y2) _Ek _ + _2U_E_x 2
−x x where Y = the width, H = depth, and K0 = the modified Bes-
W Open boundary sel function of the second kind. Develop a MATLAB script
Solid boundary to generate a contour plot of concentration for a section of a
lake with Y = 4.8 km and a length from X = –2.4 to 2.4 km
FIGURE P7.45 using Δx = Δy = 0.32 km. Employ the following parameters
Plan view of a section of a lake with a point source of for your calculation: W = 1.2 × 1012, H = 20, E = 5 × 106,
pollutant entering at the middle of the lower boundary. Ux = 5 × 103, k = 1, and n = 3.
Part Three
Linear Systems
3.1 OVERVIEW
What Are Linear Algebraic Equations?
In Part Two, we determined the value x that satisfied a single equation, f(x) = 0. Now, we
deal with the case of determining the values x1, x2, . . . , xn that simultaneously satisfy a set
of equations:
f1(x1, x2, . . . , xn) = 0
f 2 (x 1 , x... 2, . . . , x n ) =... 0
fn(x1, x2, . . . , xn) = 0
Such systems are either linear or nonlinear. In Part Three, we deal with linear algebraic
equations that are of the general form
a a 1211 xx 11 ++ aa 12...22 xx 22 ++ ·· ·· ·· ++ aa 12 nn ...xx nn = b1 (PT3.1)
= b2
an1 x1 + an2 x2 + · · · + ann xn) = bn
where the a’s are constant coefficients, the b’s
are constants, the x’s are unknowns, and n is the
number of equations. All other algebraic equa-
tions are nonlinear.
Linear Algebraic Equations in
Engineering and Science
Many of the fundamental equations of engineering
and science are based on conservation laws. Some
familiar quantities that conform to such laws are
mass, energy, and momentum. In mathematical
terms, these principles lead to balance or continuity
equations that relate system behavior as represented
223
224 PART 3 Linear Systems
x3
Feed x1 x5
x2 x4
(a)
Feed x1 ... xi−1 xi xi+1 ... xn
(b)
FIGURE PT3.1
Two types of systems that can be modeled using linear algebraic equations: (a) lumped
variable system that involves coupled finite components and (b) distributed variable system
that involves a continuum.
by the levels or response of the quantity being modeled to the properties or characteristics of the
system and the external stimuli or forcing functions acting on the system.
As an example, the principle of mass conservation can be used to formulate a model
for a series of chemical reactors (Fig. PT3.1a). For this case, the quantity being modeled is
the mass of the chemical in each reactor. The system properties are the reaction character-
istics of the chemical and the reactors’ sizes and flow rates. The forcing functions are the
feed rates of the chemical into the system.
When we studied roots of equations, you saw how single-component systems result in a
single equation that can be solved using root-location techniques. Multicomponent systems
result in a coupled set of mathematical equations that must be solved simultaneously. The
equations are coupled because the individual parts of the system are influenced by other
parts. For example, in Fig. PT3.1a, reactor 4 receives chemical inputs from reactors 2 and 3.
Consequently, its response is dependent on the quantity of chemical in these other reactors.
When these dependencies are expressed mathematically, the resulting equations are
often of the linear algebraic form of Eq. (PT3.1). The x’s are usually measures of the mag-
nitudes of the responses of the individual components. Using Fig. PT3.1a as an example,
x1 might quantify the amount of chemical mass in the first reactor, x2 might quantify the
amount in the second, and so forth. The a’s typically represent the properties and character-
istics that bear on the interactions between components. For instance, the a’s for Fig. PT3.1a
might be reflective of the flow rates of mass between the reactors. Finally, the b’s usually
represent the forcing functions acting on the system, such as the feed rate.
Multicomponent problems of these types arise from both lumped (macro-) or distrib-
uted (micro-) variable mathematical models. Lumped variable problems involve coupled
3.2 PART ORGANIZATION 225
finite components. The three interconnected bungee jumpers described at the beginning
of Chap. 8 are a lumped system. Other examples include trusses, reactors, and electric
circuits.
Conversely, distributed variable problems attempt to describe the spatial detail on a
continuous or semicontinuous basis. The distribution of chemicals along the length of an
elongated, rectangular reactor (Fig. PT3.1b) is an example of a continuous variable model.
Differential equations derived from conservation laws specify the distribution of the depen-
dent variable for such systems. These differential equations can be solved numerically by
converting them to an equivalent system of simultaneous algebraic equations.
The solution of such sets of equations represents a major application area for the meth-
ods in the following chapters. These equations are coupled because the variables at one lo-
cation are dependent on the variables in adjoining regions. For example, the concentration
at the middle of the reactor in Fig. PT3.1b is a function of the concentration in adjoining
regions. Similar examples could be developed for the spatial distribution of temperature,
momentum, or electricity.
Aside from physical systems, simultaneous linear algebraic equations also arise in a
variety of mathematical problem contexts. These result when mathematical functions are
required to satisfy several conditions simultaneously. Each condition results in an equation
that contains known coefficients and unknown variables. The techniques discussed in this
part can be used to solve for the unknowns when the equations are linear and algebraic.
Some widely used numerical techniques that employ simultaneous equations are regres-
sion analysis and spline interpolation.
3.2 PART ORGANIZATION
Due to its importance in formulating and solving linear algebraic equations, Chap. 8
provides a brief overview of matrix algebra. Aside from covering the rudiments of matrix
representation and manipulation, the chapter also describes how matrices are handled in
MATLAB.
Chapter 9 is devoted to the most fundamental technique for solving linear algebraic
systems: Gauss elimination. Before launching into a detailed discussion of this technique, a
preliminary section deals with simple methods for solving small systems. These approaches
are presented to provide you with visual insight and because one of the methods—the elim-
ination of unknowns—represents the basis for Gauss elimination.
After this preliminary material, “naive” Gauss elimination is discussed. We start with
this “stripped-down” version because it allows the fundamental technique to be elabo-
rated on without complicating details. Then, in subsequent sections, we discuss potential
problems of the naive approach and present a number of modifications to minimize and
circumvent these problems. The focus of this discussion will be the process of switching
rows, or partial pivoting. The chapter ends with a brief description of efficient methods for
solving tridiagonal matrices.
Chapter 10 illustrates how Gauss elimination can be formulated as an LU factoriza-
tion. Such solution techniques are valuable for cases where many right-hand-side vectors
need to be evaluated. The chapter ends with a brief outline of how MATLAB solves linear
s ystems.
226 PART 3 Linear Systems
Chapter 11 starts with a description of how LU factorization can be employed to ef-
ficiently calculate the matrix inverse, which has tremendous utility in analyzing stimulus-
response relationships of physical systems. The remainder of the chapter is devoted to the
important concept of matrix condition. The condition number is introduced as a measure of
the roundoff errors that can result when solving ill-conditioned matrices.
Chapter 12 deals with iterative solution techniques, which are similar in spirit to the
a pproximate methods for roots of equations discussed in Chap. 6. That is, they involve guess-
ing a solution and then iterating to obtain a refined estimate. The emphasis is on the Gauss-
Seidel method, although a description is provided of an alternative approach, the Jacobi
method. The chapter ends with a brief description of how nonlinear simultaneous equations
can be solved.
Finally, Chap. 13 is devoted to eigenvalue problems. These have general mathematical
relevance as well as many applications in engineering and science. We describe two simple
methods as well as MATLAB’s capabilities for determining eigenvalues and eigenvectors.
In terms of applications, we focus on their use to study the vibrations and oscillations of
m echanical systems and structures.
8
Linear Algebraic Equations
and Matrices
CHAPTER OBJECTIVES
The primary objective of this chapter is to acquaint you with linear algebraic equations
and their relationship to matrices and matrix algebra. Specific objectives and topics
covered are
• Understanding matrix notation.
• Being able to identify the following types of matrices: identity, diagonal,
symmetric, triangular, and tridiagonal.
• Knowing how to perform matrix multiplication and being able to assess when it is
feasible.
• Knowing how to represent a system of linear algebraic equations in matrix
form.
• Knowing how to solve linear algebraic equations with left division and matrix
inversion in MATLAB.
YOU’VE GOT A PROBLEM
Suppose that three jumpers are connected by bungee cords. Figure 8.1a shows them
being held in place vertically so that each cord is fully extended but unstretched.
We can define three distances, x1, x2, and x3, as measured downward from each of
their unstretched positions. After they are released, gravity takes hold and the jumpers will
eventually come to the equilibrium positions shown in Fig. 8.1b.
Suppose that you are asked to compute the displacement of each of the jumpers. If
we assume that each cord behaves as a linear spring and follows Hooke’s law, free-body
diagrams can be developed for each jumper as depicted in Fig. 8.2.
227
228 Linear Algebraic Equations and Matrices
x1 = 0 k1x1 k2(x2 − x1) k3(x3 − x2)
x2 = 0
x3 = 0
(a ) Unstretched (b ) Stretched m1g k2(x2 − x1) m2g k3(x3 − x2) m3g
FIGURE 8.1 FIGURE 8.2
Three individuals connected by bungee cords. Free-body diagrams.
Using Newton’s second law, force balances can be written for each jumper:
m1 _ dd_2t_x2_1 = m1 g + k2(x2 − x1) − k1x1
m2 _ dd_2t_x2_2 = m2 g + k3(x3 − x2) + k2(x1 − x2) (8.1)
m3 _dd_2t_x2_3 = m3 g + k3(x2 − x3)
xawnih=dergteh=emgdi =risapvthliateactmeimoanseasnltoafocfjcuejmulempraeptreioirn(ik(mg9).e,8at1s=umrte/isdm2)de.oB(wse)n,cwakuja=sredtwhfereosamprreitnhingeteceroqenussitletiadbnritinufomthrecposotrsediatijdo (ynN-s(/tmmat))e,,
solution, the second derivatives can be set to zero. Collecting terms gives
(k1 + k2) x1 − k2x2 = m1g (8.2)
−k2 x1 + (k2 + k3) x2 − k3 x3 = m2g
−k3 x2 + k3 x3 = m3 g
Thus, the problem reduces to solving a system of three simultaneous equations for
the three unknown displacements. Because we have used a linear law for the cords, these
equations are linear algebraic equations. Chapters 8 through 12 will introduce you to how
MATLAB is used to solve such systems of equations.
8.1 MATRIX ALGEBRA OVERVIEW 229
8.1 MATRIX ALGEBRA OVERVIEW
Knowledge of matrices is essential for understanding the solution of linear algebraic equa-
tions. The following sections outline how matrices provide a concise way to represent and
manipulate linear algebraic equations.
8.1.1 Matrix Notation
A matrix consists of a rectangular array of elements represented by a single symbol. As
d epicted in Fig. 8.3, [A] is the shorthand notation for the matrix and ai j designates an indi-
vidual element of the matrix.
A horizontal set of elements is called a row and a vertical set is called a column. The
first subscript i always designates the number of the row in which the element lies. The sec-
ond subscript j designates the column. For example, element a23 is in row 2 and column 3.
The matrix in Fig. 8.3 has m rows and n columns and is said to have a dimension of
m by n (or m × n). It is referred to as an m by n matrix.
Matrices with row dimension m = 1, such as
[b] = [b1 b2 · · · bn]
are called row vectors. Note that for simplicity, the first subscript of each element is
dropped. Also, it should be mentioned that there are times when it is desirable to employ
a special shorthand notation to distinguish a row matrix from other types of matrices. One
way to accomplish this is to employ special open-topped brackets, as in ⌊b⌋.1
Matrices with column dimension n = 1, such as
c1 (8.3)
[c] = c⋮2
cm
FIGURE 8.3
A matrix.
Column 3
a11 a12 a13 . . . a1n Row 2
a21 a22 a23 . . . a2n
[A] = . . . .
. . . .
.. . .
am1 am2 am3 . . . amn
1 In addition to special brackets, we will use case to distinguish between vectors (lowercase) and matrices
(uppercase).
230 Linear Algebraic Equations and Matrices
are referred to as column vectors. For simplicity, the second subscript is dropped. As with
the row vector, there are occasions when it is desirable to employ a special shorthand
notation to distinguish a column matrix from other types of matrices. One way to accom-
plish this is to employ special brackets, as in {c}.
Matrices where m = n are called square matrices. For example, a 3 × 3 matrix is
a11 a12 a13
[A] = a21 a22 a23
a31 a32 a33
The diagonal consisting of the elements a11, a22, and a33 is termed the principal or main
diagonal of the matrix.
Square matrices are particularly important when solving sets of simultaneous linear equa-
tions. For such systems, the number of equations (corresponding to rows) and the number of
unknowns (corresponding to columns) must be equal for a unique solution to be possible. Con-
sequently, square matrices of coefficients are encountered when dealing with such systems.
There are a number of special forms of square matrices that are important and should
be noted:
A symmetric matrix is one where the rows equal the columns—that is, ai j = aj i for all
i’s and j’s. For example,
5 1 2
[A] = 1 3 7
2 7 8
is a 3 × 3 symmetric matrix.
A diagonal matrix is a square matrix where all elements off the main diagonal are
equal to zero, as in
a11
[A] = a22
a33
Note that where large blocks of elements are zero, they are left blank.
An identity matrix is a diagonal matrix where all elements on the main diagonal are
equal to 1, as in
1
[I ] = 1
1
The identity matrix has properties similar to unity. That is,
[A][I ] = [I ][A] = [A]
An upper triangular matrix is one where all the elements below the main diagonal are
zero, as in
[A] = a11 a12 a13
a22 a23
a33
8.1 MATRIX ALGEBRA OVERVIEW 231
A lower triangular matrix is one where all elements above the main diagonal are zero,
as in
a11
[A] = a21 a22
a31 a32 a33
A banded matrix has all elements equal to zero, with the exception of a band centered
on the main diagonal:
a11 a12
[A] = a21 a22 a23
a32 a33 a34
a43 a44
The preceding matrix has a bandwidth of 3 and is given a special name—the tridiagonal
matrix.
8.1.2 Matrix Operating Rules
Now that we have specified what we mean by a matrix, we can define some operating rules
that govern its use. Two m by n matrices are equal if, and only if, every element in the first
is equal to every element in the second—that is, [A] = [B] if ai j = bi j for all i and j.
Addition of two matrices, say, [A] and [B], is accomplished by adding corresponding
terms in each matrix. The elements of the resulting matrix [C ] are computed as
ci j = ai j + bi j
for i = 1, 2, . . . , m and j = 1, 2, . . . , n. Similarly, the subtraction of two matrices, say,
[E] minus [F], is obtained by subtracting corresponding terms, as in
di j = ei j − fi j
for i = 1, 2, . . . , m and j = 1, 2, . . . , n. It follows directly from the preceding definitions
that addition and subtraction can be performed only between matrices having the same
d imensions.
Both addition and subtraction are commutative:
[A] + [B] = [B] + [A]
and associative:
([A] + [B ]) + [C ] = [A] + ([B ] + [C ])
The multiplication of a matrix [A] by a scalar g is obtained by multiplying every
element of [A] by g. For example, for a 3 × 3 matrix:
ga11 ga12 ga13
[D] = g [A] = ga21 ga22 ga23
ga31 ga32 ga33
232 Linear Algebraic Equations and Matrices
59 [A]m×n [B]n×l = [C]m×l
72
31 Interior dimensions
86 3 × 5 + 1 × 7 = 22 are equal,
04
multiplication
is possible
Exterior dimensions define
the dimensions of the result
FIGURE 8.4 FIGURE 8.5
Visual depiction of how the rows and columns line up in Matrix multiplication can be performed only if
matrix multiplication. the inner dimensions are equal.
The product of two matrices is represented as [C] = [A][B], where the elements of [C]
are defined as
n (8.4)
ci j = ∑k= 1 aik bk j
where n = the column dimension of [A] and the row dimension of [B]. That is, the ci j ele-
ment is obtained by adding the product of individual elements from the ith row of the first
matrix, in this case [A], by the jth column of the second matrix [B]. Figure 8.4 depicts how
the rows and columns line up in matrix multiplication.
According to this definition, matrix multiplication can be performed only if the first
matrix has as many columns as the number of rows in the second matrix. Thus, if [A] is an
m by n matrix, [B] could be an n by l matrix. For this case, the resulting [C] matrix would
have the dimension of m by l. However, if [B] were an m by l matrix, the multiplication
could not be performed. Figure 8.5 provides an easy way to check whether two matrices
can be multiplied.
If the dimensions of the matrices are suitable, matrix multiplication is associative:
([A][B]) [C] = [A]([B][C])
and distributive:
[A]([B] + [C ]) = [A][B] + [A][C ]
or
([A] + [B])[C ] = [A][C ] + [B][C ]
However, multiplication is not generally commutative:
[A][B] ≠ [B][A]
That is, the order of matrix multiplication is important.
8.1 MATRIX ALGEBRA OVERVIEW 233
Although multiplication is possible, matrix division is not a defined operation. How-
ever, if a matrix [A] is square and nonsingular, there is another matrix [A]−1, called the
inverse of [A], for which
[A][A]−1 = [A]−1[A] = [I ]
Thus, the multiplication of a matrix by the inverse is analogous to division, in the sense that
a number divided by itself is equal to 1. That is, multiplication of a matrix by its inverse
leads to the identity matrix.
The inverse of a 2 × 2 matrix can be represented simply by
[A]−1 = _a _11_a_2_2 _−1_ _a_12_a_2_1 a22 −a12
−a21 a11
Similar formulas for higher-dimensional matrices are much more involved. Chapter 11
will deal with techniques for using numerical methods and the computer to calculate the
inverse for such systems.
The transpose of a matrix involves transforming its rows into columns and its columns
into rows. For example, for the 3 × 3 matrix:
a11 a12 a13
[A] = a21 a22 a23
a31 a32 a33
the transpose, designated [A]T, is defined as
a11 a21 a31
[A]T = a12 a22 a32
a13 a23 a33
In other words, the element ai j of the transpose is equal to the aj i element of the original
matrix.
The transpose has a variety of functions in matrix algebra. One simple advantage is
that it allows a column vector to be written as a row, and vice versa. For example, if
{ } {c} = cc11
c1
then
{c}T = ⌊c1 c2 c3⌋
In addition, the transpose has numerous mathematical applications.
A permutation matrix (also called a transposition matrix) is an identity matrix with
rows and columns interchanged. For example, here is a permutation matrix that is con-
structed by switching the first and third rows and columns of a 3 × 3 identity matrix:
[P] = [010 0 1
1 00 ]
0