Homework: Assigned Monday, Sep 4
Due Friday, September 8
1. In Matlab, find the smallest value of p for which the expression:
tan(x) − x
x3
when evaluated in double precision at x = 10−p has no correct significant digits. (Hint:
First we need the exact value- Take the limit (by hand) as x → 0. Then let p = −1, −2,
etc. until you find the right p value).
Solution: First we find the limit using L’Hospital’s rule (by the way, did you check
that L’Hospital was valid at each step?)
tan(x) − x
sec2 (x) − 1
2 sec2 (x) tan(x)
=
=
lim
=
lim
x→0
x→0
x→0
x3
3x2
6x
lim
1
4 sec2 (x) tan2 (x) + 2 sec4 (x)
=
x→0
6
3
In Matlab, we could type:
lim
format long
x=10.^[-1 -2 -3 -4 -5 -6 -7 -8 -9];
y=(tan(x)-x)./(x.^3); %Why is this ./ and .^?
You should see that the expression, evaluated at 10−8 returns 0.
2. Use the Bisection Method (in Matlab) to find the root to six correct decimal places:
3x3 + x2 = x + 5.
Solution: We first need to rewrite this as f (x) = 0:
f (x) = 3x3 + x2 − x − 5
Now we need an initial interval, so we do a quick plot:
x=linspace(-3,3);
y=3*x.^3+x.^2-x-5;
plot(x,y)
In my case, I’ll take the interval [0, 2]. Note that I can now predict how many iterations
I’ll need to get the right accuracy:
|b − a|
1
≤
× 10−6
n+1
2
2
2
⇒
2n+1
≤
1
× 10−6
2
⇒
Using the Bisection function from class, in Matlab I would type:
1
n = 21 >> format long
>> f=inline(’3*x.^3+x.^2-x-5’);
>> y=bisect(f,0,2,0.5e-6);
Finished after 21 iterates
>> y
y =
1.16972589492798
3. Use Bisection to find two real numbers x, correct to within 6 decimal places, that make
the determinant of the matrix:
A=
1 2 3 x
4 5 x 6
7 x 8 9
x 10 11 12
equal to 1000. Hint: A little preprocessing in Maple might make this an easier problem.
Solution: First, use Maple:
with(linalg):
A:=matrix(4,4,[1,2,3,x,4,5,x,6,7,x,8,9,x,10,11,12]);
f:=det(A);
2
4
-2475 - 202 x + 1404 x + x
plot(f-1000,x=-20..15);
We’ll be using −3475 for our constant, since we’re trying to find where the determinant
is 1000.
We see that the zeros are between −20, −15 and 5, 15. Therefore, I’ll use Matlab with
intervals [2, 4] and [4, 6] (many choices possible):
format long
f=inline(’x.^4-202*x.^2+1404*x-3475’);
y=bisect(f,5,15,0.5e-6);
Finished after 24 iterates
y =
9.70829933881760
y=bisect(f,-20,-15,0.5e-6);
Finished after 23 iterates
y =
-17.18849807977676
4. You have a spherical tank with radius 1 meter. You pour 1 cubic meter of water into
the tank. Find the height of the water to within 1 millimeter.
Hint: The volume of the bottom H meters of a hemisphere of radius R is πH 2 (R − 31 H).
2 Solution: We are solving the following equation for H:
1
1 = πh2 (1 − h)
3
where we want h to be accurate to the thousandths place, or to within 0.0005. Make
this into a root finding problem and find an initial interval (from physical conditions,
we know the answer must be between 0, 1, but we can plot it anyway):
>> format long
>> f=inline(’pi*x.^2.*(1-(1/3)*x)-1’);
>> x=linspace(0,1);
>> y=f(x);
>> plot(x,y);
>> y=bisect(f,0,1,0.0005);
Finished after 10 iterates
>> y
y =
0.63525390625000
5. Use fixed point iteration to find a root of cos(x) = sin(x). In order to compare your
results with other people, let us get our iteration method by adding x to both sides, and
start with x0 = 0, with 19 iterations (before using Matlab, what is the solution?).
Have Matlab compute ei+1 /ei . Does this number look right? (Hint: Recall our proof of
convergence).
Solution: First we note that the solution is π/4. Next re-write the equation to a fixed
point form. One way to do this would be to write:
cos(x) = sin(x) ⇔ cos(x) − sin(x) + x = x
Does this work? Let’s be sure that the derivative is less than 1 (this wasn’t a requirement,
but it is a good idea):
√
f 0 (π/4) = −2/ 2 + 1 ≈ −0.414...
Now perform fixed point iteration:
>> f=inline(’cos(x)-sin(x)+x’);
>> y=fixpt(f,0,19);
>> format long
>> Error=abs(y-pi/4);
>> Z=Error(2:20)./Error(1:19);
>> Z’
ans =
0.27323954473516
0.40338351109981
0.41244791418838
0.41391310875287
(middle terms deleted)
3 0.41421356224673
0.41421356252052
0.41421356222495
0.41421356323653
If we let f (x) = cos(x) − sin(x) + x, we see that the limit is |f 0 (π/4)|, as we used in our
proof of convergence! That was,
|xn+1 − r| = |f (xn ) − f (r)| ≤ |f 0 (cn )||xn − r|
4
⇒
|xn+1 − r|
≤ |f 0 (cn )| → |f 0 (r)|
|xn − r|