Taylor's Approximation in Matlab

142 Views Asked by At

I'm trying to approximate a function $(e^x)$ to a $10th$ order approximate about $x = 0$. I have made my code compatible with anonymous functions and it works for the most part. When I approximate $e^x$ to a $8th$ order, it gives the correct answer, however when I go higher than the $8th$ order, the answer get weird.

Here is the code: enter image description here

When the code is run, this is what it displays:

$(1301357606610903*x^10)/4722366482869645213696 + (1626697008263629*x^9)/590295810358705651712 + x^8/40320 + x^7/5040 + x^6/720 + x^5/120 + x^4/24 + x^3/6 + x^2/2 + x + 1$

When it should display:

$x^{10}/3628800 + x^9/362880 + x^8/40320 + x^7/5040 + x^6/720 + x^5/120 + x^4/24 + x^3/6 + x^2/2 + x + 1$;

1

There are 1 best solutions below

0
On

This is very likely due to approximation error, as you can see by the difference in the leading coefficients: $|\frac{1301357606610903}{4722366482869645213696}-\frac{1}{3628800 }| \leq 3\times10^{-23}$.

The result is actually precise to the order of $10^{-22}$.