Solution Manual for Numerical Methods for Engineers,

8th Edition
By Steven Chapra Raymond CanaleTo download the complete and accurate content document, go to: https://testbankbell.com/download/solution-manual-for-numerical-methods-for-engine ers-8th-edition-by-steven-chapra-raymond-canale/
CHAPTER 7
7.1 Divide thepolynomial 432 ()5556 fxxxxx =-++- by the monomial factor 2. x- Is 2 x = a root?
This solution can be obtained in a manual fashion similar to Example 7.1, n = 4, a0 = 6, a1 = 5, a2 = 5,
a3 = 5, a4 = 1 and t = 2. The computations are:
r = a4 = 1
a4 = 0
For i = 3,
s = a3 = 5
a3 = r = 1
r = s + rt = 5 + 1(2) = 3
For i = 2,
s = a2 = 5
a2 = r = 3
r = s + rt = 5 3(2) = 1
For i = 1,
s = a1 = 5
a1 = r = 1
r = s + rt = 5 1(2) = 3
For i = 0,
s = a0 = 6
a0 = r = 3
r = s + rt = 6+3(2) = 0
Therefore, the quotient is x3 – 3x2 – x + 3 with a remainder of zero. Thus, 2 is a root. This result can be easily verified with a simple MATLAB script
% Chapra 8e Chapter 7 problem 1
% RJ Genik II 23 December 2019
a = [ 1 -5 5 5 -6];% 8e
b = [1 -2];
[d, e] = deconv(a,b) >> ch7p1
d = 1 -3 -1 3
e = 0 0 0 0 0
It is also possible to construct a simple Excel calculation to perform synthetic division
n for xn 4 3 2 1 0
Coefficient 1 -5 5 5 -6 xr
Copyright 2021 © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education.
The formulae for each cell are indicated below. Yellow shading indicates an input, while green is a programmed cell. Formulae in unshaded cells are filled from green cells.
7.2 Divide the polynomial 5432 ()67712 fxxxxxx =-+--+ by the monomial factor 2. x-
In a fashion similar to Example 7.1,
These can be used to compute
1
4,
r = 1 r
s + rt = 6 + 1(2) = 4
For i = 3, s = a3 = 1
3 = r = 4 r = s + rt = 1 4(2) = 7
For i = 2, s = a2 = 7 a2 = r = 7
r = s + rt = 7 7(2) = 21
For i = 1, s = a1 = 7
a1 = r = 21
r = s + rt = 7 21(2) = 49
For i = 0,
s = a0 = 12
a0 = r = 49
r = s + rt = 12 49(2) = 86
Therefore, the quotient is x4 – 4x3 – 7x2 – 21x – 49 with a remainder of –86. Thus, 2 is not a root. This result can be easily verified with MATLAB,
% Chapra 8e Chapter 7 problem 2
% RJ Genik II 23 December 2019
a = [ 1 -6 1 -7 -7 12];% 8e
Copyright 2021 © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education.
b = [1 -2];
[d, e] = deconv(a,b)
The Excel tool from problem 1 is also easily extended to 5th degree:
7.3 Use Müller’s method to determine the positive real root of
(a) 32 ()44 fxxxx =+--
(b) 32 ()0.542 fxxxx =-+-
(a) A plot indicates a root at about x = 2. Try
the same approach as in Example 7.2,
Copyright 2021 © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education.
The iterations can be continued as tabulated below:
26.3019%
(b) A plot indicates a root at about x = 0.5
Try initial guesses of x0 = 0.5, x1 = 1, and x2 = 1.5. Using the same approach as in Example 7.2,
The iterations can be continued as tabulated below:
7.4 Use Müller’s method or MATLAB to determine the real and complex roots of
Here is a MATLAB script to determine the roots for all three parts: % Chapra 8e Chapter 7 problem 4 % RJ Genik II 23 December 2019
a = [1 -1 2 -2]; b = [2 0 3 0 5]; %8e c = [1 -2 6 -8 8]; %8e
(a)'); roots(a)
roots(b)
roots(c)
Copyright 2021 © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education.
>> ch7p4
part (a)
ans =
0.0000 + 1.4142i
0.0000 - 1.4142i
1.0000 + 0.0000i
part (b)
ans =
-0.6446 + 1.0796i
-0.6446 - 1.0796i
0.6446 + 1.0796i
0.6446 - 1.0796i
part (c)
ans =
0.0000 + 2.0000i
0.0000 - 2.0000i 1.0000 + 1.0000i
1.0000 - 1.0000i
7.5 Use Bairstow’s method to determine the roots of
(a) f(x) = −2 + 6.2x − 4x2 + 0.7x3
(b) f(x) = 9 − 22x + 16x2 − 3.6x3
(c) f(x) = x4 − 2x3 + 21x2 − 8x + 68
(a) A plot suggests 3 real roots: 0.44, 2 and 3.3.

Try
Copyright 2021 © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education.
Using Equation 7.39,
2.4362.4364(0.8714)
(b) Plot suggests 3 real roots at approximately 0.74, 1.60 and 2.11

i r s r s a,r (%) a,s (%) 1 0.5642857 -0.471429 2.564286 -0.97143 28.21429 94.28571 2 0.1182506 -0.399317 2.682536 -1.37075 4.611443 41.10614 3 0.2270466 -0.223009 2.909583 -1.59375 8.463879 16.26916 4 -0.044583 0.0097385 2.865 -1.58402 1.532269 0.611044 5 -0.011157 0.0123559 2.853843 -1.57166 0.389439 0.780036 2 1 2.8538432.8538431.57166 2.1084 4() root 2 ++ == 2 2 2.8538432.8538431.57166 0.7454 4() root 2 −+ ==
3 2 3 5.726166 1.590602 root 3.6
b s
(c) Plot suggests four complex roots. MATLAB indicates conjugate pairs with real values near 0 and 1:
MATLAB script generating above figure:
% Chapra 8e Chapter 7 problem 5c
% RJ Genik II 26 December 2019
c = [1 -2 21 -8 68]; % 8e
f = @(x) c(1)*x.^4 + c(2) * x.^3 + c(3) * x.^2 + c(4)*x + c(5) ; % 8e
xmin = -1.5;
xmax = 2;
yoff = 2; %offset from x-axis for circles plotting complex roots

xtrue = roots(c)
% xtrue = fzero(f,(xmin+xmax)/2);
x = linspace(xmin,xmax,200);
y = f(x);
set(gcf,'Position',[400 400 800 400]) plot(x,y)
hold on for idx = 1:length(xtrue) if isreal(xtrue(idx))
plot(xtrue(idx),0,'mo','MarkerFaceColor','m') else
plot(real(xtrue(idx)),yoff*sign(imag(xtrue(idx))),'co','MarkerFaceColor','c') end end
set(gca, 'XAxisLocation','origin','YAxisLocation','origin','XMinorTick','on') xlabel('x \rightarrow')
ylabel('f(x)')
title(sprintf('Graphical root finding f(x) = %2.1fx^4 +%2.1fx^3 + %2.1fx^2 + %2.1fx + %2.1f', c))
shg
saveas(gcf,'ch7p5c.jpg')
Copyright 2021 © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education.
Bairstow’s Method: Try r = –1 and s = 1, and follow Example 7.3
After 6 iterations, the result is r = 0 and s = –4, or a factor of 2 (4) x + . Therefore, 2 1 004(4) root02 2 i ++− ==+ 2 2 004(2) root02 2 i −+− ==−
Note in this solution, where the correct value of r is zero, the approximate error, a,r, was affected by smearing.
The quotient, 2 (217) xx−+ , is quadratic, and has roots
224(17) root14
7.6 Develop a program to implement Müller’s method. Test it by duplicating Example 7.2.
Here is a VBA program to implement the Müller algorithm and solve Example 7.2.
Option Explicit
Sub TestMull()
Dim maxit As Integer, iter As Integer
Dim h As Double, xr As Double, eps As Double
h = 0.1
xr = 5
eps = 0.001
maxit = 20
Call Muller(xr, h, eps, maxit, iter)
MsgBox "root = " & xr
MsgBox "Iterations: " & iter
End Sub
Sub Muller(xr, h, eps, maxit, iter)
Dim x0 As Double, x1 As Double, x2 As Double
Dim h0 As Double, h1 As Double, d0 As Double, d1 As Double
Dim a As Double, b As Double, c As Double
Dim den As Double, rad As Double, dxr As Double
Copyright 2021 © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education.
x2 = xr
x1 = xr + h * xr
x0 = xr - h * xr
Do
iter = iter + 1
h0 = x1 - x0
h1 = x2 - x1
d0 = (f(x1) - f(x0)) / h0
d1 = (f(x2) - f(x1)) / h1
a = (d1 - d0) / (h1 + h0)
b = a * h1 + d1
c = f(x2)
rad = Sqr(b * b - 4 * a * c)
If Abs(b + rad) > Abs(b - rad) Then
den = b + rad
Else
den = b - rad
End If
dxr = -2 * c / den
xr = x2 + dxr
If Abs(dxr) < eps * xr Or iter >= maxit Then Exit Do
x0 = x1
x1 = x2
x2 = xr
Loop
End Sub
Function f(x)
f = x ^ 3 - 13 * x - 12
End Function
When this program is run, it yields the correct result of 4 in 3 iterations.
7.7 Use the program developed in Prob. 7.6 to determine the real roots of Prob. 7.4a. Construct a graph (by hand or with a software package) to develop suitable starting guesses.
The plot suggests a real root at 0.7.
Using initial guesses of x0 = 0.63, x1 = 0.77 and x2 = 0.7, the software developed in Prob. 7.6 yields a root of 0.715225 in 2 iterations.
Copyright 2021 © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education.
7.8 Develop a program to implement Bairstow’s method. Test it by duplicating Example 7.3.
Here is a VBA program to implement the Bairstow algorithm to solve Example 7.3.
Option Explicit
Sub PolyRoot()
Dim n As Integer, maxit As Integer, ier As Integer, i As Integer
Dim a(10) As Double, re(10) As Double, im(10) As Double
Dim r As Double, s As Double, es As Double
n = 5
a(0) = 1.25: a(1) = -3.875: a(2) = 2.125: a(3) = 2.75: a(4) = -3.5: a(5) = 1
maxit = 20
es = 0.0001
r = -1
s = -1
Call Bairstow(a(), n, es, r, s, maxit, re(), im(), ier)
For i = 1 To n
If im(i) >= 0 Then
MsgBox re(i) & " + " & im(i) & "i"
Else
MsgBox re(i) & " - " & Abs(im(i)) & "i"
End If
Next i
End Sub
Sub Bairstow(a, nn, es, rr, ss, maxit, re, im, ier)
Dim iter As Integer, n As Integer, i As Integer
Dim r As Double, s As Double, ea1 As Double, ea2 As Double
Dim det As Double, dr As Double, ds As Double
Dim r1 As Double, i1 As Double, r2 As Double, i2 As Double
Dim b(10) As Double, c(10) As Double
r = rr
s = ss
n = nn
ier = 0
ea1 = 1
ea2 = 1
Do
If n < 3 Or iter >= maxit Then Exit Do
iter = 0
Do
iter = iter + 1
b(n) = a(n)
b(n - 1) = a(n - 1) + r * b(n)
c(n) = b(n)
c(n - 1) = b(n - 1) + r * c(n)
For i = n - 2 To 0 Step -1
b(i) = a(i) + r * b(i + 1) + s * b(i + 2)
c(i) = b(i) + r * c(i + 1) + s * c(i + 2)
Next i
det = c(2) * c(2) - c(3) * c(1)
If det <> 0 Then
dr = (-b(1) * c(2) + b(0) * c(3)) / det
ds = (-b(0) * c(2) + b(1) * c(1)) / det
r = r + dr
s = s + ds
If r <> 0 Then ea1 = Abs(dr / r) * 100
If s <> 0 Then ea2 = Abs(ds / s) * 100
Else
r = r + 1
s = s + 1
iter = 0
Copyright 2021 © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education.
End If
If ea1 <= es And ea2 <= es Or iter >= maxit Then Exit Do Loop
Call Quadroot(r, s, r1, i1, r2, i2)
re(n) = r1
im(n) = i1
re(n - 1) = r2
im(n - 1) = i2
n = n - 2
For i = 0 To n
a(i) = b(i + 2)
Next i Loop
If iter < maxit Then
If n = 2 Then
r = -a(1) / a(2)
s = -a(0) / a(2)
Call Quadroot(r, s, r1, i1, r2, i2)
re(n) = r1
im(n) = i1
re(n - 1) = r2
im(n - 1) = i2
Else
re(n) = -a(0) / a(1)
im(n) = 0
End If
Else
ier = 1
End If
End Sub
Sub Quadroot(r, s, r1, i1, r2, i2)
Dim disc
disc = r ^ 2 + 4 * s
If disc > 0 Then
r1 = (r + Sqr(disc)) / 2
r2 = (r - Sqr(disc)) / 2
i1 = 0
i2 = 0
Else
r1 = r / 2
r2 = r1
i1 = Sqr(Abs(disc)) / 2
i2 = -i1
End If
End Sub
When this program is run, it yields the correct result of –
7.9 Use the program developed in Prob. 7.8 to determine the roots of the equations in Prob. 7.5.
Using the software developed in Prob. 7.8 the following results should be generated for the three parts of Prob. 7.5:
(a) 3.2786, 2.0000, 0.4357
(b) 2.2947, 1.1525, 0.9535
(c) 1.0000 + 2.0000i, 1.0000 – 2.0000i, 0.0000 + 1.0000i, 0.0000 – 1.0000i
Copyright 2021 © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education.
7.10 Determine the real root of x3.6 = 75 with Excel, MATLAB, or Mathcad.
The Excel goal seek set up is


The result is
Copyright 2021 © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education.
7.11 The velocity of a falling parachutist is given by (/) (1) cmt gm e c=-
where g = 9.81 m/s2. For a parachutist with a drag coefficient c = 16 kg/s, compute the mass m so that the velocity is 36 m/s u = at t = 7 s. Use Excel, MATLAB, or Mathcad to determine m

Excel:
The goal seek set up is shown below. Cells containing the parameter values in column B have been named from the labels in column A. Note variable name c was modified to cd to avoid the silent, automatic addition of an underscore to the variable name when using a reserved name (R, r, C, and c are reserved names in Excel).

The result is 76.289 kg as shown here:
Copyright 2021 © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education.
MATLAB: clear
format long; format compact hold off g=9.81;c=16;v=36;t=7;%8e f=@(m) g*m/c.*(1-exp(-c./m*t))-v; [mass fmass]=fzero(f,60)
xmin = 60; xmax =90; x = linspace(xmin,xmax,200); y = f(x);
set(gcf,'Position',[400 400 800 400]) plot(x,y)
hold on plot(mass,0,'mo','MarkerFaceColor','m')
set(gca, 'XAxisLocation','origin','YAxisLocation','origin',... 'XMinorTick','on')
xlabel('mass, m (kg) \rightarrow')
ylabel('f(x) \rightarrow')
title('Graphical root finding f(x) = gm/c*(1 - e^{-c/m*t}) - v') shg saveas(gcf,'ch7p11.jpg')

>> ch7p11
mass = 76.290653560358535
fmass = 0 >>
Copyright 2021 © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education.
7.12 Perform the same calculation as in Prob. 7.11 but for the more accurate representation of drag as a function of the square of the velocity. For this case, the closed-form solution is æö ¢÷ ç ÷ ç = ÷ ç ÷ ¢ ç ÷ ç èø
where c′ = a second-order drag coefficient = 0.25 kg/m.
Excel Goal Seek setup:

The result is 36.78 kg:

Check result with MATLAB:
% Chapra 8e Chapter 7 problem 12
% RJ Genik II 28 December 2019
clear
format long; format compact hold off g=9.81;c=0.25;v=36;t=7;%8e f=@(m) sqrt(g*m/c).*tanh(sqrt(g*c./m)*t)-v; [mass fmass]=fzero(f,40)
xmin = 25; xmax =50; x = linspace(xmin,xmax,200); y = f(x);
set(gcf,'Position',[400 400 800 400]) plot(x,y)
hold on plot(mass,0,'mo','MarkerFaceColor','m')
set(gca, 'XAxisLocation','origin','YAxisLocation','origin',... 'XMinorTick','on')
xlabel('mass, m (kg) \rightarrow')
ylabel('f(x) \rightarrow')
title('Graphical root finding $f(x) = \sqrt{gm/c}*\tanh{(\sqrt{gc/m}*t)}v$', 'Interpreter','LaTex')

shg
saveas(gcf,'ch7p12.jpg')
Run the script
>> ch7p12
mass = 36.782934927017131
fmass = 0 >>
Copyright 2021 © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education.
7.13 Determine the roots of the simultaneous nonlinear equations
2 2
=-++ +=
0.75 5 yxx yxyx
Employ initial guesses of x = y = 1.2 and use the Solver tool from Excel or a software package of your choice.


The Solver set up is shown below using initial guesses of x = y = 1.2. Notice that we have rearranged the two functions so that the correct values will drive both to zero. We then drive the sum of their squared values to zero by varying x and y. This is done because a straight sum would be zero if f1(x,y) = f2(x,y).
The result is
7.14 Determine the roots of the simultaneous nonlinear equations
24 22 (4)(4)5 16 xy xy
-+-= +=
Use a graphical approach to obtain your initial guesses. Determine refined estimates with the Solver tool from Excel or a software package of your choice.
Copyright 2021 © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education.
A plot of the functions indicates two real roots at about (1.8, 3.6) and (3.6, 1.8).
The Solver set up is shown below using initial guesses of (2, 4). Notice that we have rearranged the two functions so that the correct values will drive both to zero. We then drive the sum of their squared values to zero by varying x and y. This is done because a straight sum would be zero if f1(x,y) = f2(x,y).

The result is
For guesses of (4, 2) the result is (3.5691, 1.8059).
7.15 Perform the identical MATLAB operations used in Example 7.7 or use a software package of your choice to find all the roots of the polynomial ()(6)(2)(1)(4)(8) fxxxxxx =-+-+-
Note that the poly function can be used to convert the roots to a polynomial.
Copyright 2021 © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education.

MATLAB script:
% Chapra 8e Chapter 7 problem 15
% RJ Genik II 28 December 2019
% adapted from 7e problem 14 solution
format short g; format compact
%r = [-2 -5 6 4 8]; % 7e
r = [6 -2 1 -4 8]; % 7e
a = poly(r); % create polynomial coefficents from root values
pa = polyeq(a);
fprintf([' fa(x) = ' pa '\n'])
% evaluate polynomial at a test value
xtest = 1;
fval = polyval(a,xtest);
fprintf([' fa(%i) = %g \n'],xtest,fval)
% find the derivative
ap = polyder(a);
pap = polyeq(ap);
fprintf([' fa''(x) = ' pap '\n'])
% create a second polynomial
b = poly([r(1) r(2)]);
pb = polyeq(b);
fprintf([' fb(x) = ' pb '\n'])
% divide the two polynomials and print the quotient and remainder
[q rem] = deconv(a,b);
fprintf([ '\n(' pa ')\n divided by (' pb ')\n'])
pq = polyeq(q); pr = polyeq(rem);
fprintf([' quotient: (' pq ')\n'])
fprintf([' remainder: (' pr ')\n\n'])
% the above is an example of the text outputs possible in Matlab
% below is using default outputs
xrootsq = roots(q)
a
areco = conv(q,b) %reconstruct original polynomial
xrootsa = roots(areco); % show roots are same
xrootsa
r % display original roots
MATLAB session:
>> ch7p15
fa(x) = x^5 - 9x^4 - 20x^3 + 204x^2 + 208x - 384
fa(1) = 0
fa'(x) = 5x^4 - 36x^3 - 60x^2 + 408x + 208
fb(x) = x^2 - 4x - 12
(x^5 - 9x^4 - 20x^3 + 204x^2 + 208x - 384)
divided by (x^2 - 4x - 12)
quotient: (x^3 - 5x^2 - 28x + 32)
remainder: (0)
xrootsq = 8 -4 1
Copyright 2021 © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education.
Note that the first few items were scripted with extensive output processing, while the rest of the items were done with minimal output processing. Also, the roots are presented in a different order; however, there is no expectation that the order would be preserved. The polynomial string construciton function is included below.
function pstr = polyeq(a)
% returns a string suitable for screen printing a polynomial
% a = vector of coefficients
% RJ Genik II 28 December 2019
order = length(a)-1; idx = 0; pstr ='';
for jdx = order:-1:2
idx = idx + 1; if jdx == order if (a(idx) == 1)
pstr = sprintf('x^%i',jdx);
elseif (a(idx)~=0)
pstr = [num2str(a(idx)) sprintf('x^%i',a(idx),jdx)];
end
end
elseif a(idx) < 0
pstr = [pstr '' num2str(abs(a(idx))) sprintf('x^%i',jdx)];
elseif a(idx) > 0
pstr = [pstr ' + ' num2str(a(idx)) sprintf('x^%i',jdx)]; else
% insert another concatenation to preserve zero coefficient terms end
if a(end-1)<0
pstr = [pstr '' num2str(abs(a(end-1))) 'x'];
elseif a(end-1) > 0
pstr = [pstr ' + ' num2str(a(end-1)) 'x']; end
if a(end)<0
pstr = [pstr '' num2str(abs(a(end)))];
elseif a(end) > 0
pstr = [pstr ' + ' num2str(a(end))];
elseif a(end) == 0 && isempty(pstr)
end end
pstr = '0';
7.16 Use MATLAB or Mathcad to determine the roots for the equations in Prob. 7.5.
MATLAB script:
% Chapra 8e Chapter 7 problem 16
% RJ Genik II 28 December 2019
clear
format compact; format long g
%ca = [0.7 -4 6.2 -2]; % 7e
ca = [ 0.7 -4 6.2 -2]; % 8e
xra = roots(ca)
%cb = [-3.704 16.3 -21.97 9.34]; % 7e
cb = [-3.6 16 -22 9]; % 8e
xrb = roots(cb)
%cc = [1 -2 6 -2 5]; % 7e
cc = [1 -2 21 -8 68]; % 8e
xrc = roots(cc)
MATLAB session – run script
>> ch7p16
xra = 3.2786 2 0.43573
xrb = 2.1082 1.5908 0.74544
xrc = 1 + 4i 1 - 4i
-9.1593e-16 + 2i
-9.1593e-16 - 2i
>>
Note there is some round off error in the part (c) calculation of 02i roots.
7.17 A two-dimensional circular cylinder is placed in a high-speed uniform flow. Vortices shed from the cylinder at a constant frequency, and pressure sensors on the rear surface of the cylinder detect this frequency by calculating how often the pressure oscillates. Given three data points, use Müller’s method to find the time when the pressure was zero.
Copyright 2021 © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education.
Therefore, the pressure was zero at 0.591 seconds. The result is graphically displayed below:
7.18 When trying to find the acidity of a solution of magnesium hydroxide in hydrochloric acid, we obtain the following equation
32 ()3.540 Axxx=+-
where x is the hydronium ion concentration. Find the hydronium ion concentration for a saturated solution (acidity equals zero) using two different methods in MATLAB (for example, graphically and the roots function).
(a) First we will determine the root graphically
>> x=-1:0.01:5;
>> f=x.^3+3.5.*x.^2-40;
>> plot(x,f);grid
The zoom in tool can be used several times to home in on the root. For example, as shown in the following plot, a real root appears to occur at x = 2.567:

Copyright 2021 © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education.

(b) The roots function yields both real and complex roots:
>> a=[1 3.5 0 -40]; >> roots(a)
ans =
-3.0338 + 2.5249i
-3.0338 - 2.5249i
2.5676
7.19 Consider the following system with three unknowns a, u, and υ:
Solve for the real values of the unknowns using: (a) the Excel Solver and (b) a symbolic manipulator software package.
(a) Excel Solver Solution: The 3 functions can be set up as a roots problems:


If you use initial guesses of a = –1, u = 1, and v = –1, the Solver finds another solution at a = –1.6951, u = 6.2634, and v = –4.2636
Copyright 2021 © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education.
(b) Symbolic Manipulator Solution:
MATLAB:
>> syms a u v
>> S=solve(u^2-2*v^2-a^2,u+v-2,a^2-2*a-u);
>> double(S.a) ans = 3.0916 + 0.3373i
3.0916 - 0.3373i
-0.4879 -1.6952
>> double(S.u) ans = 3.2609 + 1.4108i
3.2609 - 1.4108i
1.2140 6.2641
>> double(S.v) ans =
-1.2609 - 1.4108i
-1.2609 + 1.4108i
0.7860 -4.2641
Mathcad: Problem 7.19 (Mathcad)
Copyright 2021 © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education.
Therefore, we see that the two real-valued solutions for a, u, and v are ( 0.4879, 1.2140, 0.7860) and ( 1.6952, 6.2641, 4.2641). In addition, MATLAB and Mathcad also provide the complex solutions as well.
7.20 In control systems analysis, transfer functions are developed that mathematically relate the dynamics of a system’s input to its output. A transfer function for a robotic-positioning system is given by
32 432 ()12.550.566
() () 19122296192 Cssss Gs Ns ssss +++ == ++++
where G(s) = system gain, C(s) = system output, N(s) = system input, and s = Laplace transform complex frequency. Use a numerical technique to find the roots of the numerator and denominator and factor these into the form
()()() () ()()()() sasasa Gs sbsbsbsb +++ = ++++
123 1234
where ai and bi = the roots of the numerator and denominator, respectively.
MATLAB can be used to determine the roots of the numerator and denominator:
% Chapra 8e Chapter 7 problem 20
% RJ Genik II 29 December 2019
%num = [1 9 26 24];% 7e
%den = [1 15 77 153 90];% 7e
num = [1 12.5 50.5 66];% 8e
den = [1 19 122 296 192];% 8e
nr = roots(num);
dr = roots(den);
nstr = polyfacteq(nr);
dstr = polyfacteq(dr); fprintf([nstr '\n' ' \n' dstr '\n'])
MATLAB Session >> ch7p20
(x + 5.5)(x + 4)(x + 3)
(x + 8)(x + 6)(x + 4)(x + 1)
Therefore, the transfer function is (5.5)(4)(3) () (8)(6)(3)(1) sss Gs ssss +++ = ++++
Copyright 2021 © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education.
The MATLAB script makes use of a factored polynomial string construction function provided below. The calls to roots using appropriate input vectors are minimally required.
function pstr = polyfacteq(a)
% returns string of factored equations based on integer roots
% Chapra 8e Chapter 7 support for problem 20
% RJ Genik II 29 December 2019
% pstr = ''; for idx = 1:length(a) if (a(idx)>0) pstr = [pstr '(x' num2str(a(idx)) ')']; elseif (a(idx)<0)
pstr = [pstr '(x + ' num2str(abs(a(idx))) ')']; else pstr = [pstr '(x)']; end
7.21 Develop an M-file function for bisection similar to the algorithm in Fig. 5.10. Test the function by duplicating the computations from Examples 5.3 and 5.4.
function root = bisection(func,xl,xu,es,maxit)
% root = bisection(func,xl,xu,es,maxit):
% uses bisection method to find the root of a function
% input:
% func = name of function
% xl, xu = lower and upper guesses
% es = (optional) stopping criterion (%)
% maxit = (optional) maximum allowable iterations
% output:
% root = real root
if func(xl)*func(xu)>0 %if guesses do not bracket a sign change disp('no bracket') %display an error message return %and terminate end
% if necessary, assign default values
if nargin<5, maxit=50; end %if maxit blank set to 50 if nargin<4, es=0.001; end %if es blank set to 0.001
% bisection
iter = 0;
xr = xl;
while (1) xrold = xr;
xr = (xl + xu)/2; iter = iter + 1;
if xr ~= 0, ea = abs((xr - xrold)/xr) * 100; end test = func(xl)*func(xr);
if test < 0
xu = xr; elseif test > 0
xl = xr; else
ea = 0; end
if ea <= es | iter >= maxit, break, end end root = xr;
Copyright 2021 © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education.
The following is a MATLAB session that uses the function to solve Example 5.3 with s = 0.0001.
>> fcd=inline('(9.81*68.1/cd)*(1-exp(-0.146843*cd))-40','cd');
>> format long
>> bisection(fcd,5,15,0.0001)
ans = 14.80114936828613
7.22 Develop an M-file function for the false-position method. The structure of your function should be similar to the bisection algorithm outlined in Fig. 5.10. Test the program by duplicating Example 5.5.
function root = falsepos(func,xl,xu,es,maxit)
% falsepos(func,xl,xu,es,maxit):
% uses the false position method to find the root of the function func
% input:
% func = name of function
% xl, xu = lower and upper guesses
% es = (optional) stopping criterion (%) (default = 0.001)
% maxit = (optional) maximum allowable iterations (default = 50)
% output:
% root = real root
if func(xl)*func(xu)>0 %if guesses do not bracket a sign change error('no bracket') %display an error message and terminate end
% default values if nargin<5, maxit=50; end if nargin<4, es=0.001; end
% false position
iter = 0;
xr = xl; while (1)
xrold = xr;
xr = xu - func(xu)*(xl - xu)/(func(xl) - func(xu));
iter = iter + 1;
if xr ~= 0, ea = abs((xr - xrold)/xr) * 100; end
test = func(xl)*func(xr);
if test < 0
xu = xr;
elseif test > 0
xl = xr; else
ea = 0; end
if ea <= es | iter >= maxit, break, end end root = xr;
The following is a MATLAB session that uses the function to solve Example 5.5:
>> fcd=inline('(9.81*68.1/cd)*(1-exp(-0.146843*cd))-40','cd');
>> format long
>> falsepos(fcd,5,15,0.0001)
ans = 14.80114660933235
Copyright 2021 © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education.
7.23 Develop an M-file function for the Newton-Raphson method based on Fig. 6.4 and Sec. 6.2.3. Along with the initial guess, pass the function and its derivative as arguments. Test it by duplicating the computation from Example 6.3.
function root = newtraph(func,dfunc,xr,es,maxit)
% root = newtraph(func,dfunc,xguess,es,maxit):
% uses Newton-Raphson method to find the root of a function
% input:
% func = name of function
% dfunc = name of derivative of function
% xguess = initial guess
% es = (optional) stopping criterion (%)
% maxit = (optional) maximum allowable iterations
% output:
% root = real root
% if necessary, assign default values
if nargin<5, maxit=50; end %if maxit blank set to 50 if nargin<4, es=0.001; end %if es blank set to 0.001
% Newton-Raphson iter = 0; while (1) xrold = xr; xr = xr - func(xr)/dfunc(xr); iter = iter + 1;
if xr ~= 0, ea = abs((xr - xrold)/xr) * 100; end if ea <= es | iter >= maxit, break, end end root = xr;
The following is a MATLAB session that uses the function to solve Example 6.3 with s = 0.0001.
>> format long
>> f=inline('exp(-x)-x','x');
>> df=inline('-exp(-x)-1','x');
>> newtraph(f,df,0)
ans = 0.56714329040978
7.24 Develop an M-file function for the secant method based on Fig. 6.4 and Sec. 6.3.2. Along with the two initial guesses, pass the function as an argument. Test it by duplicating the computation from Example 6.6.
function root = secant(func,xrold,xr,es,maxit)
% secant(func,xrold,xr,es,maxit):
% uses secant method to find the root of a function
% input:
% func = name of function
% xrold, xr = initial guesses
% es = (optional) stopping criterion (%)
% maxit = (optional) maximum allowable iterations
% output:
% root = real root
% if necessary, assign default values
if nargin<5, maxit=50; end %if maxit blank set to 50 if nargin<4, es=0.001; end %if es blank set to 0.001
% Secant method iter = 0;
Copyright 2021 © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education.
while (1)
xrn = xr - func(xr)*(xrold - xr)/(func(xrold) - func(xr)); iter = iter + 1; if xrn ~= 0, ea = abs((xrn - xr)/xrn) * 100; end if ea <= es | iter >= maxit, break, end
xrold = xr;
xr = xrn;
end root = xrn;
Test by solving Example 6.6:
>> format long
>> f=inline('exp(-x)-x','x');
>> secant(f,0,1)
ans = 0.56714329040970
7.25 Develop an M-file function for the modified secant method based on Fig. 6.4 and Sec. 6.3.3. Along with the initial guess and the perturbation fraction, pass the function as an argument. Test it by duplicating the computation from Example 6.8.
function root = modsec(func,xr,delta,es,maxit)
% modsec(func,xr,delta,es,maxit):
% uses modified secant method to find the root of a function
% input:
% func = name of function
% xr = initial guess
% delta = perturbation fraction
% es = (optional) stopping criterion (%)
% maxit = (optional) maximum allowable iterations
% output:
% root = real root
% if necessary, assign default values
if nargin<5, maxit=50; end %if maxit blank set to 50 if nargin<4, es=0.001; end %if es blank set to 0.001 if nargin<3, delta=1E-5; end %if delta blank set to 0.00001
% Secant method
iter = 0; while (1)
xrold = xr;
xr = xr - delta*xr*func(xr)/(func(xr+delta*xr)-func(xr)); iter = iter + 1;
if xr ~= 0, ea = abs((xr - xrold)/xr) * 100; end if ea <= es | iter >= maxit, break, end end root = xr;
Test by solving Example 6.8:
>> format long
>> f=inline('exp(-x)-x','x');
>> modsec(f,1,0.01)
ans = 0.56714329027265
Copyright 2021 © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education.