The Newton-Raphson Method and the Secant Method

If your answer for the **calc_realmax** program is greater than
one-half the value returned by MATLAB when you type **realmax**,
you're at least on the right track -- your value has the largest
possible exponent. Don't get stuck on finishing this program if it
prevents you from answering the rest of the questions.

- implementing the Newton-Raphson zero-finding algorithm
- implementing the Secant Method zero-finding algorithm
- a little bit of graphing in MATLAB

If you have not already done so, create a directory for this lab and copy the lab 2 files into it. If you start off in your home directory you can do the following:

mkdir ~/cs371/lab2 cd ~/cs371/lab2 cp ~cs371/lab2/* .and (as always) don't forget to type that last period.

- The difference between MATLAB script files and MATLAB function files
- Various plotting commands (
**plot**,**semilogx**,**semilogy**,**loglog**) - Some cool things to put around your plots (
**xlabel**,**ylabel**,**title**) - Plotting more than one thing on the same set of axes with
**hold** - Putting more than one set of axes on a window with
**subplot** - zeroing in on a specific location in the graph with
**axis**

- Evaluate the function at arbitrary points
- Evaluate the derivative of the function at arbitrary points

2 f(x) = sin(x) + x - 1 .It is usually a good idea, before running any zero-finding algorithm, to take a look at your function and see more or less where the zeros are. Take a look at the program

It should look like f(x) has a zero somewhere around -1.4 or so and another one around .7 or so.

Now that we have an idea of what f(x) looks like - it looks smooth and fairly simple - we can choose good initial values and expect the Newton-Raphson method to work.

Note that to correctly compute the next step in the Newton-Raphson method, we need the derivative of f(x). Fortunately our f(x) is simple enough to do that algebraically. (I'm leaving that up to you.)

Now look at the program **newton.m**. Note
that this is a MATLAB function instead of a MATLAB script. You will
run it by specifying an initial value for it to start with. For
example, you would type **newton(2)** to start with an initial
guess of 2.

**Finish the program newton.m and answer the corresponding questions
on the answer sheet.**

The program **secant.m** is again just a skeleton, and in fact it
probably looks almost exactly like the skeleton for **newton.m** -
this should not be surprising at these are fairly similar methods
attacking the same problem.

**Finish the program secant.m (for the same function f(x) used above)
and answer the corresponding questions on the answer sheet.**

Feel free to take a crack at the extra credit problem if you want.