Project 6 Part B

Due Thursday 5/6 at 3pm

- vectors and vectorized code
- loops
- plots

Functions often can be approximated by infinite series. As more terms are added in the sequence, the approximation becomes better (usually). The exponential function e^{x} can be approximated by the series

The notation *n*! represents the factorial of number *n*, *n*!=1*2*3...**n*, 0!=1. The MATLAB function ` factorial` performs this computation.

We will use the MATLAB function ` exp` to calculate the "true" value of e

**Part (a):** Write a program (`eee.m`

) that uses the series shown above to approximate e^{0.5}. The program should start by approximating e^{0.5} with just the first term of the series and add the additional terms one by one until a *tolerance* of 0.001 is satisfied. Use a loop! The program should show one line of output for each additional term used. This line of output should display the number of terms used, the approximated value of e^{0.5}, and the approximation error. Below is an example of what the first few lines of output may look like:

No. of Terms Approximation Error 1 1.000000 0.648721 2 1.500000 0.148721

The above is an *example* of the output *format*, not the actual solution. Your output should have the same components but does not need to have exactly the same format.

**Part (b):**Now that you have a program to approximate e^{x}, let's experiment with the tolerance! Use six values of tolerance: 0.1, 0.01, 0.001, 0.0001, 0.00001, 0.000001. Do *not* submit M-files for Part (b). Instead, type a table (in plain text format) that shows how many terms of the series are needed for each tolerance value. Put this table at end of the program from Part (a) as a comment block.

- Program 1: (
`loop.m`

) Use aloop without using vectorized code. In this program, each iteration of the loop calculates one value of y for one value of x.**for** - Program 2: (
`vectorized.m`

) Write vectorized code. No loops! Draw a plot of the function values for $0.1<=x<=3$. The code should label the axes and give the plot a title. Read Section 10 in MATLAB Essentials (4/29 handout, p.4), and/or type`help plot`

in the command window, to learn about plotting. The code given in the 4/29 handout shows an example of using MATLAB function`plot`

.

Submit your files `eee.m`

, `loop.m`

, and `vectorized.m`

on-line using **CMS** (Course Management System) before the project deadline. **Make sure you are submitting the correct, up to date files. We will not accept any files after the deadline for any reason (except for documented medical reasons).** See the **CMS** link on the web page for instructions on using CMS.