#### CITS2401 Computer Analysis & Visualisation — Lab4 | Problem 8

**8. Writing a small Matlab function that involves using a for loop**

A Taylor series is a representation of a function as an infinite sum of terms. Very often we take the first *N* terms as an approximate value of the function. For instance, the Taylor series for the exponential function *e*^{x} at *x* = 0 that stops at the first 6 terms is:

Write a Matlab function called **myexp** that approximates *e*^{x} for small *x* values near 0 using **N** terms from the Taylor series given above. Your function should have the following heading:

**function value = myexp(x, N)**

Your function should inspect that **N** is greater than 2; otherwise, it should issue an error message (by calling Mathab’s built-in **error** function). You can use the **factorial** function to compute the factorial.

Save your function to the file called `myexp.m`.

Compare the output value of your function with Matlab’s built-in function **exp** function. e.g.,

` >> value = myexp(0.1, 5)`

` >> exp(0.1)`

` >> value = myexp(-0.2, 10)`

` >> exp(-0.2)`