|
CS 323 - Spring 2006 Homework 3
Due at start of class: Wednesday, March 8 |
Instructions
Answer the following questions. When writing up your solution,
include some brief narrative to explain your approach (in other
words, show your work; don't just give the final answer.)
Clearly state any assumptions you make.
When you use MATLAB, hand in everything: the programs, transcripts (from the command window) and graphs. Label them (by hand is ok). No need to write a general program (such as one that accepts varying input) unless explicitly specified. Comment the program and output so that it can be understood without too much trouble. Print out any graphs.
Problem 1
Do problem 1(c) and 1(g) in section 3.1 (page 77).
Use a graph to determine your intervals for bisection. No need to print out this graph. Just print out the command you use to make the graph, along with the commands and output to determine each root.
You'll need bisect.m from the text. Edit the functions in this file, and print out just the end of this file (the part you change). (It might be convenient for you to do a "type bisect.m" from matlab, and then edit out the parts you don't need in your output.)
Problem 2
Do problem 10 in § 3.2 (page 89 of text).
You'll need newton.m from the
text. Also, see example 2.2.2 on page 51 which was examined in class
(see the relevant matlab transcript).
[Update 2/28] You might want to comment
out the iteration = ... and pause commands in the
main loop so it doesn't print out all this junk. (Only do that once
you understand what the program does.)
[Update 2/28] There are actually two unusual things about this function. One is that the derivative of f at the root is zero. For this example, as long as you don't set your initial guess to be the root, it's ok. It does converge much more slowly, however. But that's not what this problem is about. Instead, investigate how different ways of evaluating the function (and its derivative) affect the accuracy of the root (i.e. the error in the result). Hint: you'll need to set the error bound small enough to get an effect. Explain what you find.
Problem 3
Consider the function:
f(x) = x4 + 3x3 - 2x - 2
It has two real roots.
(a) Write a matlab program that runs Newton's method for a range of starting locations in [-5,5]; test all locations in this interval with a separation of 0.1. (i.e. in matlab-speak, -5:0.1:5.) Select a reasonable tolerance value (so that the results don't vary significantly when they are converging to the same place). Make a dot-plot where the y-value is the where Newton's method converges for that corresponding x-value. (If it doesn't converge, or has some difficulty, then set it to some value that doesn't mess up your graph, or simply reset the range of your graph). Explain what you find (i.e. for steps 0.1 apart, do there seem to be clear boundaries for where Newton's method converges to one root, or the other, or diverges (if this happens at all)?
(b) Alter the code for both Newton's method and the secant method so that they return a vector of the iterates, and not just the final iterate. Pick an initial guess x0=10 for Newton, and for the secant method, use the same x0=10, and set x1 to be the value that Newton's method computes upon its first iteration. Select a reasonable tolerance value. Make a plot of the errors in each iteration for both methods on the same graph. ([Update 2/28] Plot the real error, not the estimated error.) You should take the log of the error magnitude to make the differences visible.
[Update 2/28] When you have zero error for
some iteration and take the log, you'll get an error from matlab.
It puts an -Inf value in there. Matlab stops plotting
when it finds a point like that, but this always happens in the last
iteration, so it's not a big deal.
If you want to still graph something, you could replace all the
zeros in a vector err with very tiny numbers (say, 1e-30)
using a fancy vectorized matlab command like:
err(err==0) = 1e-30;
(c) Compute the M (equation 3.21, page 85) for Newton's method and c value for the secant method (equation 3.31, page 92) for this positive root (from (b)). How well can you relate these values to the regions where there is super-linear convergence (i.e. using relationships like equation 3.24, page 85)? Explain.
[Update 2/28] As we saw in class (see the matlab transcripts from 2/20 and 2/22), the point where super-linear convergence starts is easily found in an log-error plot. It's where the plot starts to bend, as in areas of linear convergence it will be a line.
Start with newton.m and secant.m from the text. Print out the modified versions when you hand in your solution.
Problem 4
Do problem 4 in § 3.4 (page 106 of text). Recall the derivative of tan-1(x) = 1 / (1+x2).
Problem 5
Do problem 1 in § 3.5 (page 115 of text). Just look at the root near -1, and ignore the positive root.
[Update 3/1] Oops! Had the wrong problem number there...