



















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




















For each point in the plot of g(x), I wanted to plot the point (xν , g(xν )) = (xν , xν+1), followed by the point (xν+1, xν+1). The next point would be (xν+1, xν+2), and so on. Hence, I plotted a sequence of points where each x value is repeated twice, and the array of x and y coordinates are offset by one array position. To construct a matrix with two x values for each coor- dinate, I used the command [x;x] to concatenate two copies of the matrix of x values into an 2 × n matrix. I then made this into an n × 2 matrix with the transpose operator. Since MatLab reads across rows and then down columns, the matrix element x(3) then refers to the first element in the sec- ond row. Using one-dimensional indices, the matrix [x;x]’ then represents an array containing two copies of each x value. To plot the desired points, I use [x;x]’ for both the x and the y coordinate, with the indices of the coordinates offset by one. In the plot of f (x), I wanted to plot (xν , f (xν )) followed by the point (xν+1, 0). The next point would be (xν+1, f (xν+1)). I used the same display array from the first plot for the x coordinate. For the y coordinate, I made an array of 2n zeros, and then using a for loop, I filled every second element with f (xν ).
Part 1 - Chord method
General method
The function we are examining is f (x) = x^2 −2. The chord method constructs a chord with fixed slope from a given point on the curve y = f (x). The intercept of this chord with the x axis is taken as the next x value, and the iterative process is repeated. The slope of the chord is thus
m =
f (xν ) xν − xν+
Solving for xν+1 yields
xν+1 = xν −
f (xν ) m Thus the function g that defines the iterative process is
g(x) = x −
x^2 − 2 m To examine the error in the iteration, I assume { xν } converges to some value, call it α, and I write each xν in terms of the error, ǫν = xν − α. With this substitution,
ǫν+1 = ǫν −
f (α + ǫν ) m
I Taylor expand the numerator of the fractional term above. Since { xν } is assumed to converge to α, it must be that { ǫν } converges to 0, and so I keep only first order terms in ǫν (with some foresight, I know that the chord method has only first-order convergence, so it is sufficient to keep only first- order terms in the Taylor expansion). By the definition of the fixed point α, f (α) = 0. Hence the Taylor expansion simplifies,
f (α + ǫν ) = f ′(α)ǫν + O(ǫ^2 ν )
With this substitution,
ǫν+1 = ǫν
f ′(α) m
⇒ lim ν→∞
ǫν+ ǫν
f ′(α) m
fp = ’/Users/adrian/Documents/Documents/Academic/School/Classes/Current/Math 128A/ ff = ’-depsc’; fn = ’’; format long; % Increased display precision err = zeros(1,n+1); % Error errrat = zeros(1,n); %Error ratio err(1) = sqrt(2) - x(1); % Initial error for k = 1:n x(k+1) = x(k) - (x(k).^2 - 2) ./ m; % Compute next iterate err(k+1) = x(k+1)-sqrt(2); % Compute error errrat(k) = err(k+1) ./ err(k); % Compute ratio of successive errors end tablestr = ’’; if (table) % If the table flag is on, make a LaTeX table for k = 1:n tablestr = strvcat(tablestr,[’$’ num2str(k) ’$ & $’ num2str(x(k)) ’$ & $’ end end disp1=[x;x]; % See discussion about plotting methods x=x(:)’; plot(disp1(2:end-1),disp1(3:end),’b’) hold on xf=linspace(-20,20,10000); plot(xf,xf-1/m(xf.^2-2),’k’) plot([-20 20],[-20 20],’r’) axis([max(min(x)-.5,-20) min(max(x)+.5,20) max(min(x)-.5,-20) min(max(x)+.5,20)]) legend(’Iterations’,’g(x)=x-m^{-1}(x^{2}-2)’,’y=x’) title([’Chord method, finding the fixed point of g(x), m=’ num2str(m) ’ , x_{1}=’ if (save) % If save flag is on, save and close graph fn = [fp fp1 ’g-m-’ int2str(m) ’-x-’ int2str(x(1))]; print(ff,fn); close(gcf); end figure disp2 = zeros(2,n+1); for k = 1:n disp2(2k-1) = x(k).^2-2; end
plot(disp1(2:end),disp2(1:end-1),’b’) hold on plot(xf,xf.^2-2,’k’,xf,0*xf,’r’) axis([max(min(x)-.5,-20) min(max(max(x),2)+.5,20) max(min(min(disp2)),-20)-.5 min( legend(’Iterations’,’f(x)=x^{2}-2’,’y=0’) title([’Chord method, finding the zero of f(x), m=’ num2str(m) ’ , x_{1}=’ num2str if (save) fn = [fp fp1 ’f-m-’ int2str(m) ’-x-’ int2str(x(1))]; print(ff,fn); close(gcf); end
−0.5 1 1.5 2 2.
0
1
2
Chord method, finding the zero of f(x), m=4 , x 1 = Iterations f(x)=x^2 − y=
(c)
1 1.5 2 2.
1
2
Chord method, finding the fixed point of g(x), m=4 , x 1 = Iterations g(x)=x−m−1(x^2 −2) y=x
(d)
−2.5−0.5 0 0.5 1 1.5 2 2.
−
−1.
−
−0.
0
1
2
Chord method, finding the zero of f(x), m=1 , x 1 = Iterations f(x)=x^2 − y=
(e)
−0.5 −0.5 0 0.5 1 1.5 2 2.
0
1
2
Chord method, finding the fixed point of g(x), m=1 , x 1 = Iterations g(x)=x−m−1(x^2 −2) y=x
(f)
ν xν ǫν = α − xν ǫν ǫ+1ν 1 4 − 2. 585786438 1. 707106781 2 − 3 − 4. 414213562 1. 792893219 3 − 6. 5 − 7. 914213562 3. 542893219 4 − 26. 625 − 28. 03921356 13. 60539322 5 − 380. 0703125 − 381. 4845261 190. 3280495 6 − 72605. 79153 − 72607. 20575 36303. 18866 7 − 2635873087 − 2635873088 1317936544 8 − 3. 473913468 e + 18 − 3. 473913468 e + 18 1. 736956734 e + 18 9 − 6. 034037391 e + 36 − 6. 034037391 e + 36 3. 017018696 e + 36 10 − 1. 820480362 e + 73 − 1. 820480362 e + 73 9. 10240181 e + 72 11 − 1. 657074374 e + 146 − 1. 657074374 e + 146 8. 285371871 e + 145 12 − 1. 372947741 e + 292 − 1. 372947741 e + 292 Inf 13 −Inf −Inf NaN 14 −Inf −Inf NaN 15 −Inf −Inf NaN 16 −Inf −Inf NaN 17 −Inf −Inf NaN 18 −Inf −Inf NaN 19 −Inf −Inf NaN 20 −Inf −Inf NaN
Part 2
General method
Newton’s method constructs a chord from the function f (x) at the point xν to the x axis with slope f ′(xν ). This process is then repeated at the point xν+1, where xν+1 is the x intercept of the previous chord line. Finding the
slope of the chord line,
f ′(xν ) =
∆y ∆x
f (xν ) − 0 xν − xν+
⇒ xν+1 = xν −
f (x) f ′(x)
Hence the function g characterizing the iterative method is
g(x) = x −
f (x) f ′(x)
Taking f (x) = x^2 − 2, f ′(x) = 2x, so
g(x) = x −
x^2 − 2 2 x = x −
x 2
x
x 2
x To examine the limiting behavior of the iteration, I write xν = α + ǫν , where ǫν is the error term. With this substitution,
ǫν+1 = ǫν −
f (α + ǫν ) f ′(α + ǫν )
As before, I assume convergence and expand the functions on the right, using the fact that f (α) = 0 and that limν→∞ ǫν = 0. With some foresight, I know that Newton’s method should yield second-order convergence, so I keep terms to second order in ǫν.
1 f ′(α + ǫν )
f ′(α)
f ′′(α) f ′(α)^2
ǫν + O(ǫ^2 ν )
f (α + ǫν ) = f ′(α)ǫν +
f ′′(α)ǫ^2 ν + O(ǫ^3 ν ) f (α + ǫν ) f ′(α + ǫν )
= ǫν −
f ′′(α) f ′(α)
ǫ^2 ν +
f ′′(α) f ′(α)
ǫ^2 ν + O(ǫ^3 ν )
= ǫν −
f ′′(α) f ′(α)
ǫ^2 ν + O(ǫ^3 ν )
ǫν+1 = (^) ǫν − (^) ǫν +
f ′′(α) f ′(α)
ǫ^2 ν + O(ǫ^3 ν )
⇒ lim ν→∞
ǫν+ ǫ^2 ν
f ′′(α) f ′(α)
if (table) % If the table flag is on, make a LaTeX table for k = 1:n tablestr = strvcat(tablestr,[’$’ num2str(k) ’$ & $’ num2str(x(k),10) ’$ & end tablestr end disp1=[x;x]; % See discussion about plotting methods x=x(:)’; plot(disp1(2:end-1),disp1(3:end),’b’) hold on xf=linspace(-20,20,10000); plot(xf,xf./2+1./xf,’k’) plot([-20 20],[-20 20],’r’) axis([max(min(x)-.5,-20) min(max(x)+.5,20) max(min(x)-.5,-20) min(max(x)+.5,20)]) legend(’Iterations’,’g(x)=.5x+x^{-1}’,’y=x’) title([’Chord method, finding the fixed point of g(x), x_{1}=’ num2str(x(1))]) if (save) % If save flag is on, save and close graph fn = [fp fp1 ’g-x-’ int2str(x(1))]; print(ff,fn); close(gcf); end figure disp2 = zeros(2,n+1); for k = 1:n disp2(2k-1) = x(k).^2-2; end plot(disp1(2:end),disp2(1:end-1),’b’) hold on plot(xf,xf.^2-2,’k’,xf,0xf,’r’) axis([max(min(x)-.5,-20) min(max(max(x),2)+.5,20) max(min(min(disp2)),-20)-.5 min( legend(’Iterations’,’f(x)=x^{2}-2’,’y=0’) title([’Chord method, finding the zero of f(x), x_{1}=’ num2str(x(1))]) if (save) fn = [fp fp1 ’f-x-’ int2str(x(1))]; print(ff,fn); close(gcf); end
ν xν ǫν = α − xν ǫν ǫ+1 (^2) ν 1 2 0. 5857864376 0. 25 2 1. 5 0. 08578643763 0. 3333333333 3 1. 416666667 0. 002453104294 0. 3529411764 4 1. 414215686 2. 123901415 e − 06 0. 3535223846 5 1. 414213562 1. 594724353 e − 12 − 87311002. 13 6 1. 414213562 − 2. 220446049 e − 16 − 4. 503599627 e + 15 7 1. 414213562 − 2. 220446049 e − 16 − 4. 503599627 e + 15 8 1. 414213562 − 2. 220446049 e − 16 − 4. 503599627 e + 15 9 1. 414213562 − 2. 220446049 e − 16 − 4. 503599627 e + 15 10 1. 414213562 − 2. 220446049 e − 16 − 4. 503599627 e + 15
2 4 6 8 10 12 14 16 18 20
0
2
4
6
8
10
12
14
16
18
20
Chord method, finding the zero of f(x), x 1 = Iterations f(x)=x^2 − y=
(k)
2 4 6 8 10 12 14 16 18 20
2
4
6
8
10
12
14
16
18
20
Chord method, finding the fixed point of g(x), x 1 = Iterations g(x)=.5x+x− y=x
(l)