Docsity

Numerical Computing - Solution Manual for Homework 2 | CSCI 4800, Assignments of Computer Science

Toggle sidebar
bg1
Numerical Computing S’09 MATH/CSCI 4800-01
Homework-2 Solutions
1. (a) Text: Section 1.1, Page 30, Problem 2(c).
(b) Text: Section 1.1, Page 30, Problem 4(c).
(a) Let f(x) = ln x+x2−3.Since f(1) = −2 and f(2) = ln2 + 1 >0,a root lies in the bracket
[1,2].
(b) The first approximation to the root is
r1=1+2
2=3
2with error estimate e1=2−1
2=1
2.
Now, f(3/2) = ln(3/2) −3/4 = −0.3445 <0.Therefore, the root lies in the bracket [3/2,2].The
second approximation to the root is
r2=3/2+2
2=7
4with error estimate e2=2−3/2
2=1
4.
Finally, f(7/4) = ln(7/4)+49/8−3=3.685 >0.Therefore, the root lies in the bracket [3/2,7/4].
The third approximation to the root is
r2=3/2+7/4
2=13
8with error estimate e3=7/4−3/2
2=1
8.
Thus the answer is 13/8=1.625.
2. (a) Define the term “conditioning” in the context of a mathematical problem.
(b) Text: Section 1.3, Page 53, Problem 2. Of the four cases considered, indicate which one is the
most ill-conditioned and why.
(c) Text: Section 1.3, Page 53, Problem 4. Comment on the conditioning of this problem.
(a) Conditioning refers to the sensitivity of a mathematical problem to small disturbances in input.
A mathematical problem is ill-conditioned if small disturbances in input (or backward error)
correspond to large disturbances in output (or forward error). Conditioning is an attribute of the
mathematical problem itself, and is independent of the numerical algorithm chosen to solve the
problem.
(b) The exact root of f(x) is x∗= 1/3 and the approximate root xc= 0.3333.Therefore the
forward error is ef=|x∗−xc|=|1/3−0.3333|= 0.00003333 . . . .
The perturbed function whose root is xcis given by f(x)−f(xc),yielding a backward error of
eb=|f(xc)|=|f(0.3333)|.
(i) For f(x)=3x−1, eb=|3(0.3333) −1|= 0.0001 = 10−4.
(ii) For f(x) = (3x−1)2, eb=|[3(0.3333) −1]2|= 10−8.
(iii) For f(x) = (3x−1)3, eb=|[3(0.3333) −1]3|= 10−12.
(iv) For f(x) = (3x−1)(1/3), eb=|[3(0.3333) −1](1/3)|= 10−4/3= 0.0464 . . . .
Case (iii) is the most ill-conditioned as it has the largest ratio of forward error to backward error.
(c) Since
x2sin x2=x4sin x2
x2
and limx→0sin(x2)/x2= 1,the multiplicity of the root r= 0 is 4. For the approximate root
xc= 0.01,the forward error is ef=|r−xc|= 0.01.The backward error is eb=|f(xc)|=
0.0001 sin(0.0001) ≈10−8.The large forward error to backward error ratio makes the probelem
ill-conditioned.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Numerical Computing - Solution Manual for Homework 2 | CSCI 4800 and more Assignments Computer Science in PDF only on Docsity!

Numerical Computing S’09 MATH/CSCI 4800- Homework-2 Solutions

  1. (a) Text: Section 1.1, Page 30, Problem 2(c). (b) Text: Section 1.1, Page 30, Problem 4(c).

(a) Let f (x) = ln x + x^2 − 3. Since f (1) = −2 and f (2) = ln 2 + 1 > 0 , a root lies in the bracket [1, 2]. (b) The first approximation to the root is

r 1 =

with error estimate e 1 =

Now, f (3/2) = ln(3/2) − 3 /4 = − 0. 3445 < 0. Therefore, the root lies in the bracket [3/ 2 , 2]. The second approximation to the root is

r 2 =

with error estimate e 2 =

Finally, f (7/4) = ln(7/4)+49/ 8 −3 = 3. 685 > 0. Therefore, the root lies in the bracket [3/ 2 , 7 /4]. The third approximation to the root is

r 2 =

with error estimate e 3 =

Thus the answer is 13/8 = 1. 625.

  1. (a) Define the term “conditioning” in the context of a mathematical problem. (b) Text: Section 1.3, Page 53, Problem 2. Of the four cases considered, indicate which one is the most ill-conditioned and why. (c) Text: Section 1.3, Page 53, Problem 4. Comment on the conditioning of this problem.

(a) Conditioning refers to the sensitivity of a mathematical problem to small disturbances in input. A mathematical problem is ill-conditioned if small disturbances in input (or backward error) correspond to large disturbances in output (or forward error). Conditioning is an attribute of the mathematical problem itself, and is independent of the numerical algorithm chosen to solve the problem. (b) The exact root of f (x) is x∗ = 1/ 3 and the approximate root xc = 0. 3333. Therefore the forward error is ef = |x∗ − xc| = | 1 / 3 − 0. 3333 | = 0. 00003333.... The perturbed function whose root is xc is given by f (x) − f (xc), yielding a backward error of eb = |f (xc)| = |f (0.3333)|. (i) For f (x) = 3x − 1 , eb = |3(0.3333) − 1 | = 0.0001 = 10−^4. (ii) For f (x) = (3x − 1)^2 , eb = |[3(0.3333) − 1]^2 | = 10−^8. (iii) For f (x) = (3x − 1)^3 , eb = |[3(0.3333) − 1]^3 | = 10−^12. (iv) For f (x) = (3x − 1)( 1 /3), eb = |[3(0.3333) − 1]( 1 /3)| = 10−^4 /^3 = 0. 0464.... Case (iii) is the most ill-conditioned as it has the largest ratio of forward error to backward error. (c) Since x^2 sin x^2 = x^4 sin x^2 x^2 and limx→ 0 sin(x^2 )/x^2 = 1, the multiplicity of the root r = 0 is 4. For the approximate root xc = 0. 01 , the forward error is ef = |r − xc| = 0. 01. The backward error is eb = |f (xc)| = 0 .0001 sin(0.0001) ≈ 10 −^8. The large forward error to backward error ratio makes the probelem ill-conditioned.

  1. (a) Text: Section 1.4, Page 62, Problem 2(b).

(b) Text: Section 1.4, Page 63, Problem 4(b).

(a) We have f (x) = x^2 +

x + 1 − 3 x, f ′(x) = 2x −

(x + 1)^2

so that Newton’s method becomes

xn+1 = xn −

f (xn) f ′(xn)

= xn −

x^2 n + (^) xn^1 +1 − 3 xn 2 xn − (^) (xn+1)^12 − 3

With x 0 = 1 the next two iterates turn out to be x 1 = − 0. 2 , x 2 = 0. 180856. (b) We have f (x) = x^3 − x^2 − 5 x − 3 = 0. The two roots are (i) r = −1 and (ii) r = 3. Note that

f ′(x) = 3x^2 − 2 x − 5 ,

and that f ′(−1) = 3 + 2 − 5 = 0 while f ′(3) = 27 − 6 − 5 = 16 6 = 0. Thus 3 is a root with multiplicity 1 while -1 is a root with multiplicity greater than 1. Since f is a cubic and has only 3 roots, -1 must be a root with multiplicity 2. According to Theorem 1.11, when f ′(r) 6 = 0 the convergence is quadratic and the errors en satisfy lim n→∞

en+ e^2 n

= M =

f ′′(r) 2 f ′(r) This theorem will apply to the single root r = 3. We already have f ′(3) = 16. Also, f ′′^ = 6 x − 2 = 16 for r = 3. Therefore M = 16/(2 × 16) = 12. To the multiple root r = −1 we apply Theorem (1.12), which says that for a root with multiplicity m, lim n→∞

en+ en

= S =

m − 1 m

Here, m = 2 so that S = 1/ 2.

  1. (a) List one advantage and one disadvantage of the secant method over (i) the bisection method and (ii) Newton’s method for finding the root of a nonlinear equation. (b) Consider the problem of finding a root α satisfying 1 < α < 2. If you are using a binary computer with precision p, what is the smallest error tolerance that makes sense in finding an approximation to α? If the starting bracket is of length unity, how many interval halvings are needed to find an approximation αn to α with the maximum accuracy possible for this machine? (c) What is the definition of the convergence rate r of an iterative method? If an iterative method squares the error every 2 iterations, what is its convergence rate? (d) Suppose you are using an iterative method to solve a nonlinear equation f (x) = 0 for a root that is ill-conditioned, and you need a stopping criterion. Would it be better to terminate the iteration when |xn − xn− 1 | is small, or when |f (xn)| is small? Why?

(a) When compared to bisection, the secant method converges more rapidly (advantage) but like Newton’s method, may not converge at all if initial guesses are not sufficiently close to the root (disadvantage). When compared to Newton’s method, the secant method does not require evaluation of the derivative (advantage) but has a slower rate of convergence (disadvantage). (b) In the block of numbers [1, 2], the separation between adjacent machine numbers is mach = 1 / 2 p−^1 for a machine with precision p. Therefore, this is also the smallest sensible tolerance to apply. Starting with a bracket of length unity, the first approximation to the root has an error bound of 1/ 2. After one interval halving the error bound becomes 1/ 22 , and so on. Therefore, after p − 2 interval halvings the error bound will be 1/ 2 p−^1.

(b) Plot a semilog graph to show the variation of β 1 with α.

You may use a rootfinder of your choice (bisection, Newton or secant). Supply the Matlab scripts, a well-labelled graph, well-formatted numerical output, and a brief explanation. It will be useful to plot the graph of f (βn) for each α to get a rough sense of where the root lies. Accuracy to 3 digits will suffice.

MATLAB LOG, Problem 5(a)

function xb=bisect(a,b,tol)

% Matlab function bisect.m

% Solves f(x) = 0 using the bisection method

% Inputs:

% a = left endpoint of interval

% b = right endpoint of interval

% tol = tolerance for stopping bisection method

% Required m-file:

% f.m is m-file for function f(x)

% Outputs:

% Root by bisection

it=0; % set iteration count to zero

fa=f(a);

fb=f(b);

% check bracketing

if sign(fa)==sign(fb), error('Root not in bracket'); end

% begin while loop

while (b-a)/2>tol

it=it+1;

c=a+0.5*(b-a);

fc=f(c);

if sign(fa)~=sign(fc); % root lies in [a,c]

b=c;

fb=fc;

else % root lies in [c,b]

a=c;

fa=fc;

end

% print progress

xb=0.5*(a+b);

err=0.5*abs(b-a);

n = 12 Solution = 1.5921630859e+00 error =

1.2207031250e-

n = 13 Solution = 1.5921020508e+00 error =

6.1035156250e-

n = 14 Solution = 1.5921325684e+00 error =

3.0517578125e-

n = 15 Solution = 1.5921478271e+00 error =

1.5258789062e-

n = 16 Solution = 1.5921401978e+00 error =

7.6293945312e-

n = 17 Solution = 1.5921440125e+00 error =

3.8146972656e-

n = 18 Solution = 1.5921421051e+00 error =

1.9073486328e-

n = 19 Solution = 1.5921430588e+00 error =

9.5367431641e-

n = 20 Solution = 1.5921425819e+00 error =

4.7683715820e-

n = 21 Solution = 1.5921428204e+00 error =

2.3841857910e-

n = 22 Solution = 1.5921429396e+00 error =

1.1920928955e-

n = 23 Solution = 1.5921428800e+00 error =

5.9604644775e-

n = 24 Solution = 1.5921429098e+00 error =

2.9802322388e-

n = 25 Solution = 1.5921429247e+00 error =

1.4901161194e-

n = 26 Solution = 1.5921429321e+00 error =

7.4505805969e-

Computed Solution = 1.592143e+

Iteration count = 26

ans =

1.592142932116985e+

OUTPUT

  • Initial guess = 1.00000e+00 Tolerance = 1.00000e-
    • k = 1 Solution = 1.6666666667e+00 Error = 6.6666666667e-
    • k = 2 Solution = 1.5932929205e+00 Error = 7.3373746155e-
    • k = 3 Solution = 1.5921432155e+00 Error = 1.1497050570e-
    • k = 4 Solution = 1.5921429371e+00 Error = 2.7839632491e-
    • k = 5 Solution = 1.5921429371e+00 Error = 1.6308093484e-

MATLAB LOG for HW2, Problem 6 (Extra Credit)

Step 1. Plot the frequency function for each value of alpha to see approximately where

the smallest root (fundamental frequency) lies, and to select a suitable bracket for the

bisection method. See the attached plot.

Step 2. Design a Matlab program to compute and plot the root for each alpha. This is

done by writing a calling script Frequency_main.m, which calls a function script

frequency.m to evaluate the frequency function, and the bisection script bisect2.m to

evaluate the root to the desired tolerance, here specified as 0.0001. See the attached

numerical output and the plot of frequency against alpha.

% Script File: Frequency_main

% Calling program for finding frequency at various alpha

clc

tol=0.0001;

global alpha

% Defining alpha as 'global' here and in other scripts called by

% this program eliminates the need to pass its value in the

calling

% list

data=[0.1 1.6 1.8;1 0 1.5;10 0 1.5;100 0 1.5;1000 0 1.5];

% The matrix 'data' has five rows; each row specifies an alpha

and

% the corresponding bracket for the root, estimated from the

% corresponding plot of the frequency function

result=[];

% The 'result' matrix will store alpha and the corresponding

frequency

for n=1:

alpha=data(n,1); a=data(n,2); b=data(n,3);

xb=bisect2(a,b,tol);

result=[result; alpha,xb];

end

fprintf(' alpha frequency \n\n')

format short e

disp(result)

figure

semilogx(result(1:5,1),result(1:5,2),'ro-')

xlabel('alpha'), ylabel('frequency')

title('Fundamental Frequency versus alpha')

xb=0.5*(a+b);

end

Numerical Output

alpha frequency

1.0000e-01 1.7228e+

1.0000e+00 1.2480e+

1.0000e+01 7.3581e-

1.0000e+02 4.1592e-

1.0000e+03 2.3410e-

10 −1^100 101 102

alpha

frequency

Fundamental Frequency versus alpha