Problem 4.2

advertisement
Problem 4.2
√
3 is the positive root of
g(x) = x2 − 3 = 0.
For this g(x) the Newton iteration scheme
xn+1 = xn −
g(xn )
g ′(xn )
becomes
x2n − 3
.
xn+1 = xn −
2xn
Since g(x) has no extreme points in x > 0, the iterates will approach the root for any
positive starting value x0 .
The iteration scheme for x0 = 0.1 is implemented in the following Matlab script file:
x=.1;xvals=x;eps=1;n=0;nmax=25;
while eps>=1e-5&n<=nmax
y=x-(x^2-5)/2/x;
eps=abs(y-x);
xvals=[xvals;y];
x=y;n=n+1;
end
The iterates are stored in the array xvals:
>> xvals
xvals =
0.10000000000000
15.05000000000000
7.62466777408638
4.00906377015993
2.37868407771026
1.81994280423458
1.73417312785826
1.73205210624066
1.73205080756936
The last value in this array is the desired approximation of
the more accurate answer given by Matlab:
>> sqrt(3)
ans =
1.73205080756888
1
√
3. We can compare this to
The starting value x0 = 0.1 was very close to x = 0 where g(x) has an extreme point.
This is clearly a bad choice. Convergence becomes faster if we choose a starting point
that is more close to the root. For example, if x0 = 3 we obtain the following sequence:
>> xvals
xvals =
3.00000000000000
2.00000000000000
1.75000000000000
1.73214285714286
1.73205081001473
1.73205080756888
Problem 4.3
We first plot the function g(x) = x − tanh(2x) in the interval 0 ≤ x ≤ 1.5 using the
Matlab command
>> ezplot(’x-tanh(2*x)’,[0 1.5])
which yields the following figure:
x−tanh(2 x)
0.4
0.2
0
−0.2
0
0.5
x
1
1.5
The root is close to 1, so we use x0 = 1 as starting value
(note that g ′ (x) = 1 − 2/ cosh2 (2x)),
x=1;eps=1;n=0;nmax=25;
while eps>=1e-5&n<=25
y=x-(x-tanh(2*x))/(1-2/cosh(2*x)^2);
eps=abs(y-x);
x=y;n=n+1;
end
This time we are not interested in the whole sequence, hence there was no need to
store the iterates in an array. When calling x in the workspace we obtain the answer
2
x = 0.95750402407728 which is the desired approximation of the root. In this case only
three iterations were needed to find x.
Problem 4.4
We first plot f (x) = x sin(x) in the interval 0 ≤ x ≤ 15:
>> ezplot(’x*sin(x)’,[0 15])
x sin(x)
15
10
5
0
−5
−10
0
x
5
10
15
The graph shows that f (x) has maxima near x = 2, x = 8 and x = 14. We use these
values as starting values for the Newton iteration.
Using f ′ (x) = sin(x) + x cos(x) and f ′′ (x) = 2 cos(x) − x sin(x), the Newton iteration
scheme for this maximum problem becomes
xn+1 = xn −
sin(xn ) + xn cos(xn )
.
2 cos(xn ) − x sin(xn )
For the starting value x0 = 2 this is implemented in Matlab as follows:
x=2;eps=1;n=0;nmax=25;
while eps>=1e-5&n<=25
y=x-(sin(x)+x*cos(x))/(2*cos(x)-x*sin(x));
eps=abs(y-x);
x=y;n=n+1;
end
with x = 2.02875783811043 as answer for the location of the first maximum. Changing the starting values to x0 = 8 and x0 = 14 yields x = 7.97866500177638 and
x = 14.20743725677721 for the locations of the second and third maximum, respectively.
3
Download