MATLAB: Is MATLAB not giving me the correct Maclaurin polynomial

maclaurinpolynomial

I am trying to evaluate the 4th degree Maclaurin polynomial of the function below using MATLAB:
Capture.PNG
The following code is the one I used in ,
Capture.PNG
But clearly this is not the same answer to the one I computed manually by hand. I obtained the 4th degree Maclaurin Polynomial to be:
Capture.PNG

Best Answer

Lets look at what you did.
If you view this as the exponential function, applied to x^2, thus exp(x^2), we can use the standard Taylor series. That is,
exp(u) = 1 + u + u^2/2 + u^3/6 + u^4/24 + ...
Now, substitute u=x^2, and we have
exp(x^2) = 1 + x^2 + x^4/2 + x^6/6 + x^8/24 + ...
It looks like what you expected. So, you would be correct. Except that you need to read the help for taylor.
What happens in MATLAB?
syms x
taylor(exp(x^2),'order',4)
ans =
x^2 + 1
taylor(exp(x^2),'order',5)
ans =
x^4/2 + x^2 + 1
In the help for taylor, we see:
'Order' Compute the Taylor polynomial approximation with
order n-1, where n has to be a positive integer. The
default value n=6 is used.
So you passed in n=4. It computed a Taylor series approximation of order 3. Yes, I know, the words order and degree are sometimes used as synonyms in mathematics, but then sometimes we see order=degree+1.