MATLAB Answers

Taylor polynomial of a not infinitely differentiable function.

1 view (last 30 days)
Yency Perez
Yency Perez on 22 Sep 2020
Commented: Yency Perez on 22 Sep 2020
Hello everyone,
First, I would like to thank any help provided, I truly appreciated.
Here's my problem:
Consider the function 𝑓(𝑥)=3𝑥^3+𝑥.
a. Without MATLAB, compute the first 5 (𝑛 = 0,1,2,3,4) Taylor Series coefficients (Cn) for the function about 𝑎=2.
After computation I got:
3x^3+x approx 26 + 37(x-2) + 18(x-2)^2 + 3(x-2)^3 + 0(x-2)^4
So, the first thing I noticed was that the fuction is not infinitely differentiable since the fourth derivative is zero and so on.
b. How many terms in the Taylor Series would you need for a good approximation of this target function? Justify your answer in three sentences or less.
HERE is where I'm having trouble and is simply because I might be missing something about Taylor Series, but I understand that having 5 and 4 terms would be exacly the same since the last of the 5 term is zero, regardless, I have tried 3 terms, got the relative error, and it is soo similar to having 4 terms. The difference is so big between the function and the taylor polynomial when x=0 or any other number, that is not even an approximation...
Thanks for the help!


Show 1 older comment
Yency Perez
Yency Perez on 22 Sep 2020
Hmm ok I see, I've been looking as for why my relative errors for 5, 4, 3 terms are so similar to each other, reading and watching videos on how and a Taylor approx can fail... if mine is failing... but thanks, now I know that it does not mean is not inifitely differentiable!
John D'Errico
John D'Errico on 22 Sep 2020
It did not fail. You appear to have gotten it right. Once you get past the terms with a cubic in it, the Taylor series for a cubic polynomial is identically the same as the original cubic. The expansion point is not really important here, because if you then expand those terms, you will see it all reduces to that original polynomial. I showed this works in my answer. At least, I let MATLAB show it for me, since I'm far too lazy to do real algebra anymore. :)

Sign in to comment.

Accepted Answer

John D'Errico
John D'Errico on 22 Sep 2020
Edited: John D'Errico on 22 Sep 2020
Your question has absolutely nothing to do with MATLAB, but you seem to have made some effort. So I will point out that you may be mistaken that the difference between the original polynomial and the Taylor polynomial is in fact zero.
And, since this forum is explicitly about MATLAB, and I really don't care what the rules for your homework assignment are... :)
syms x
taylor(3*x^3 + x,x,'expansion',2,'order',4)
ans =
37*x + 18*(x - 2)^2 + 3*(x - 2)^3 - 48
Which admittedly, does not look like the original polynomial, but is it really different? Note that you did seem to have gotten the correct Taylor polynomial. My constnt term is different from what you show, but you should see that the linear term does not have a constant term in it. MATLAB combined those terms.
simplify(taylor(3*x^3 + x,x,'expansion',2,'order',4) - (3*x^3 + x))
ans =
Just because it looks different, does not mean it really is.

  1 Comment

Yency Perez
Yency Perez on 22 Sep 2020
This is what I get for my relative error when I plug 0, 1, -1, 0.1, and -0.1:
%how many terms would give a good appx:
TS = @(x) 26 + 36*x + 18*x^2 + 3*x^3 + 0*x^4;
p = 0; %0 gives 0, -1/1 gives 3.33/28, 0.1/-0.1 gives 0.1100/0.1075 respectively.
RelErr = abs ( (TS(p) - 3*p^3 + p) / 3*p^3 + p);
And I notice that when i take out terms, the relative error is still the same (for 5, 4, and 3 terms) I was just wondering why that was.
Thanks so much for answering, I'm aware part a has nothing to do with matlab and I apologies for the inconvenience.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!