Sei sulla pagina 1di 6

Homework 3 solutions

id558966080 pdfMachine by Broadgun Software - a great PDF writer! - a great PDF creator! - http://www.pdfmachine.com http://www.broadgun.com

Section 2.3: Ex 1,4; AP 1,2


Section 2.4: Ex 2,8,12,14; AP 3,8

Section 2.3

1,4 Graphically determine the approximate location of the roots of f(x)=0 in the given
interval. Determine an interval [a,b] over which the bisection or false position algorithms
can be used to determine the roots.

1. f(x) = x2 – ex for x in [-2, 2]


The graph of f(x) is shown below:

So the root is approximately at x=-0.7. You could use the interval [-1,-.5] in the
algorithms.

4. f(x) = cos(x) + (1+x2)-1 for x in [-2,2]


The graph of f(x) is shown below:

There are two roots, at approximately x = -1.8 and x = 1.8. You could use the intervals
[-2, -1.6] or [1.6, 2].
Algorithms and Programs

1-2. Approximate the real roots, to 12 decimal places, of each function over the given
interval.

1. f(x) = 1,000,000 x3 – 111,000 x2 + 1110 x – 1, for x in [-2, 2].


Three roots, at x = 0.1, .01, .001.
(Note that f(x) can be factored: f(x) = (1000 x – 1) (100 x – 1) (10 x -1) . )

2. f(x) = 5 x10 – 38 x9 + 21 x8 – 5  x6 – 3  x5 – 5x2 + 8x – 3, for x in [-15, 15]


Two roots, at x = -0.847129818132 and x = 7.010824348276

MATLAB code is shown below. Three files were used: (i) a script that defines the
function and bounds, (ii) a function to find coarse approximations of the roots (approot.m
in the text), and (iii) a function that performs the bisection algorithm to find a fine
approximation of the roots (bisect.m in the text). The output was the following:

f(x) = 1,000,000 x3 – 111,000 x2 + 1110 x – 1 f(x) = 5x10 – 38x9 + 21x8 – 5  x6 – 3  x5 – 5x2 + 8x – 3


Coarse approximation: 1.0500e-003 Coarse approximation: -8.4715e-001
28 iterations 28 iterations
Root: 1.000000000372e-003, Root: -8.471298181321e-001,
Error: 7.451e-013 Error: 7.451e-013
f(c)=3.318e-010 f(c)=4.005e-011

Coarse approximation: 9.9500e-003 Coarse approximation: 7.0108e+000


28 iterations 28 iterations
Root: 1.000000000037e-002, Root: 7.010824348276e+000,
Error: 7.451e-013 Error: 7.452e-013
f(c)=-3.017e-010 f(c)=5.923e-005

Coarse approximation: 1.0005e-001


28 iterations
Root: 1.000000000004e-001,
Error: 7.451e-013
f(c)=3.318e-009
MATLAB code

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Find root of f(x)=0 using bisection method %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Define function to find zero of, and region to find zero in

f=@(x)1000000*x.^3-111000*x.^2+1110*x-1; ai=-2; bi=2;


f=@(x)5*x.^10 - 38*x.^9 + 21*x.^8 - 5*pi*x.^6 - 3*pi*x.^5 - 5*x.^2 +
8*x - 3; ai=-5; bi=8;

% Tolerances for error

delta1 = 10^-4; % error in coarse approximation


delta2 = 10^-12; % error in bisection method

% Find (coarse) approximation of roots:

R = approot(f,(ai:delta1:bi));
rts=0;

% Use bisection method to find fine approximation:

for i=1:length(R)
a=R(i)-delta1; b=R(i)+delta1;
[c,err,yc,k]=bisect(f,a,b,delta2);
rts(i)=c;
disp(sprintf('\nCoarse approximation: %.4e\n%i iterations\nRoot:
%.12e, \nError: %.3e \nf(c)=%.3e',R(i),k,c,err,f(c)))
end

% Plot function and roots

figure(1);
ezplot(f,[ai,bi])
hold on;
plot(rts,0*rts,'r*')%,[ai bi],[0 0],'g')
Section 2.4

2. Let f(x) = x2 – x – 3.
(a) Find the Newton-Raphson formula pk = g(pk-1)
g(x) = x – f(x)/f’(x)
= x – (x2 – x – 3)/(2x – 1) = ((2x – 1)x – x2 + x + 3)/(2x – 1)
= (x2 + 3)/(2x – 1),
so pk = (pk-12+3)/(2 pk-1 – 1)
(b) Start with po = 1.6 and find p1, p2, and p3.
p1 = 2.527272, p2 = 2.31520, p3 = 2.302818
(c) Start with po = 0.0 and find p1, p2, and p3. What do you conjecture about this
sequence?
p1 = -3, p2 = -1.71429, p3 = -1.34101
The sequence is converging quadratically to the zero at x = -1.3027756377.

8. Use the secant method to compute the next two iterates p2 and p3.
f(x) = x2 – 2x – 1; po = 2.6, p1 = 2.5, p2 = 2.41935484, p3 = 2.4136464

12. Consider f(x) = xN – A, where N is a positive integer.


(a) What real values are the solutions to f(x) = 0?
 N A if A > 0 and N is even, N A if N is odd (all real A)
(b) Derive the recursive formula
( N  1) p k 1  A / p kN11
pk  for k = 1, 2, …
N
for finding the Nth root of A.
Use the fact that f’(x) = N xN-1 and the Newton iteration:
p N  A ( N  1) p k 1  A / p kN11
p k  p k 1  f ( p k 1 ) / f ' ( p k 1 )  p k 1  k 1 N 1 
Np k 1 N

14. Can Newton-Raphson iteration be used to solve f(x) = 0 if f(x) = x1/3? Why?
NO. f’(x) = 1/3 x-2/3 is not continuous at the root of f(x) = 0, which is x=0.
p 1k / 31
The iteration is p k  p k 1  f ( p k 1 ) / f ' ( p k 1 )  p k 1   2 p k 1 ,
1 2 / 3
p k 1
3
which exhibits oscillatory divergence from the root at x=0.
Algorithms and Programs

3. Modify the Newton iteration program to approximate each of the following square
roots to 10 decimal places.
The code shown below produces the results for the following problems:
(a) Start with po = 3 and approximate 8
[p0,err,k,y]=newton(@(x)x^2-8,@(x)2*x,3,10^(-10),10^(-5),10^3);
Iteration 1, p_1 = 2.8333333333e+000
Iteration 2, p_2 = 2.8284313725e+000
Iteration 3, p_3 = 2.8284271247e+000
(b) Start with po = 10 and approximate 10
[p0,err,k,y]=newton(@(x)x^2-91,@(x)2*x,10,10^(-10),10^(-5),10^3);
Iteration 1, p_1 = 9.5500000000e+000
Iteration 2, p_2 = 9.5393979058e+000
Iteration 3, p_3 = 9.5393920142e+000
(c) Start with po = -3 and approximate - 8
[p0,err,k,y]=newton(@(x)x^2-8,@(x)2*x,-3,10^(-10),10^(-5),10^3);
Iteration 1, p_1 = -2.8333333333e+000
Iteration 2, p_2 = -2.8284313725e+000
Iteration 3, p_3 = -2.8284271247e+000

8. (a) Find the point on the parabola y = x2 that is closest to the point (3,1) accurate to 10
decimal places.
The distance from a point (x,y) = (x,x2) on the parabola to (3,1) is
D  ( x  3) 2  ( y  1) 2  ( x  3) 2  ( x 2  1) 2 .
To minimize D, we find the point where the derivative of D2 with respect to x is zero.
d 2
D  2( x  3)  2( x 2  1) 2 x  2 x 3  x  3
dx
In other words, we need to find a zero of
f(x) = 2x3 – x – 3.
Using the Newton iteration above, we find that x = 1.2896239015, and since y = x2 on the
parabola, the point is
(1.289623902, 1.663129807).
2
The graph of y = x , the point above, and the point (3,1) are shown below.

(b) Find the point on the graph of y = sin(x – sin(x)) that is closest to the point (2.1, 0.5),
accurate to 10 decimal places.
The distance from a point (x,y) = (x,sin(x-sin(x))) to (2.1, 0.5) is
D  ( x  2.1) 2  ( y  0.5) 2  ( x  2.1) 2  (sin( x  sin( x ))  0.5) 2
Again, we differentiate D2 with respect to x and set the resulting expression = 0.
d 2
D  2( x  2.1)  2(sin( x  sin( x ))  0.5) cos( x  sin( x ))(1  cos( x))
dx
So, we must find the zero of
f ( x )  2( x  2.1)  2(sin( x  sin( x ))  0.5) cos( x  sin( x ))(1  cos( x ))
Again using the Newton iteration, with a starting point po = 2, we find the desired point:
(1.869372237, 0.7917177973)
The graph of y = sin(x-sin(x)), the point above, and the point (2.1,0.5) are shown below.

(c) Find the value of x at which the minimum vertical distance between the graphs of
f(x) = x2 + 2 and g(x) = x/5 – sin(x) occurs accurate to 10 decimal places.
The minimum vertical distance is simply the difference between the functions:
|f(x) – g(x)|.
To minimize this quantity, we again find where the derivative with respect to x is zero.
f’(x) – g’(x) = 2x – 1/5 + cos(x).
Using the Newton iteration, we find that this quantity has a zero at
x = -0.3667490121.
The graphs of the functions f(x) and g(x), and the line x = -0.3667490121 are shown
below.

Potrebbero piacerti anche