Exercise 1: Taylor series
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 ex at x = 0 that stops at the first 6 terms is:
-(see attached file)-
Write a Matlab function called myexp that approximates ex 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)
What is your function code?