Homework 1. Assigned: Tue Jan 23. Due: Tue Jan 30 at 6 p.m.
This homework may look long but nothing here is difficult. If you have questions
don't hesitate to email either me or the class mailing list for help.
Remember getting help is OK as long as it is acknowledged.
For all these questions, when displaying results, use
format long e so that full precision is displayed and remember
that the result of evaluating an expression is displayed when the ";" is omitted.
Alternatively you can, if you want, use fprintf.
- In the first class we implemented the bisection method to approximately
compute the square root of a number x.
Here is a more efficient method: given a
starting value y, repeatedly replace it by the average of y
and x/y (the motivation for this will be explained in class). Modify
the function bisectsqrt.m accordingly and
give it a new name. You will no longer be specifying inital values of left and
right, just x and an initial value for y.
How many steps of the loop are now required to compute the square root of 2
to full double precision (16-17 digits)?
One possible stopping condition is to stop when y no longer changes: does this work?
Print all iterates and underline the digits that
are correct (agree with the final answer) with a pen.
Approximately how does the number of correct digits change from one iteration to the next.
- In the second class we wrote a function
discretization_demo.m to approximate a derivative using a difference formula
(see Chapter 1 of Ascher-Greif as well as Chapter 11 of my book). Modify this to use
a centered difference formula
as explained in class and also on p. 75 of my book. Print the derivative approximation
for the various values of h and underline the correct digits with a pen.
Also, as before, use a log-log
plot to plot both the actual discretization error and the theoretical discretization
error (which is also given on p. 75). How do the results compare to the ones
we obtained in class? Why?
- This question concerns computing the integral in Example 1.2 of Ascher-Greif (p.12-13).
There is no formula for the value of the integeral, so we consider approximating it
in 3 different ways:
Print the results from the 3 methods for nmax = 20, for all 20 values of n.
Underline the digits that seem to be correct with a pen. Also, assuming that
quad gives correct answers to full precision, print the
absolute and relative errors for the two recursions for each value of n.
Which recursion is better and why?
- The unstable recursion formula on the top of p.13. Write a MATLAB function to do this,
passing nmax as an input parameter, and returning a vector of results for the
approximate integral for n from 1 to nmax. Use a for loop (not a recursive
- A backwards recursion that uses the same formula to define yn-1
in terms of yn. The only problem with this is that we don't have
a good initial value for ynmax, but it's not hard to see that the
integral converges to 0 for large n, so just use 0.
Write another function to do this, again using a for loop
and returning a vector of results for n from 1 to nmax.
- Calling the built-in routine quad. Figure out how to do this by typing
help quad and looking at the example. This uses a method that we'll discuss
much later in the semester. You'll have to use a for loop to call quad for each
n from 1 to nmax. When you write the function for the integrand,
remember that ^ is the operator for exponentiation.
- Exercises from my book: Exercises 4.1, 4.2 and 4.3 on p. 21.
Reading: Chapters 1 of Ascher-Greif; Chapters 1-4 of my book. You may also want
to read Chapter 2 of Ascher-Greif, which covers some of the same material as my
book, but this is not necessary and could be confusing as it uses different notation.
Please submit printed listings of all functions and printed copies of all plots.
Make sure you answer all the questions by writing the answers on the pages with
Homework may be given to me in class or in my office, or left under my office door.
Please do not leave homework in my lobby mailbox or send it by email.
Please staple all pages together. Late homework will be penalized 20%.
Homework will not be accepted more than one week late, except in special circumstances.