Why do I get this error in my Taylor Expansion?
7 views (last 30 days)
Show older comments
I have this code below:
clearvars
% Define Symbols
syms x f(x)
% Define Function
f(x) = sqrt(sin(x))+2;
% Taylor Expansion f(x)
T = taylor(sqrt(sin(x))+2, x, 'ExpansionPoint', 0, 'Order', 6)
And I get this error
Why am I getting this error?
0 Comments
Answers (1)
John D'Errico
on 23 Mar 2020
Edited: John D'Errico
on 23 Mar 2020
It might seem a subtle point. But what is the shape of sqrt(sin(x)), where x is near zero? (I'll just disregard the +2, since that is just a translation upwards.)
Why not plot it, if you are not positive?
symx x
fplot(sqrt(sin(x)) + 2,[0,1])
That should work. What do you see? Think about it.
If you are still unsure, what does sin(x) look like near x==0? In fact, sin(x) is very much like x. FOr small x, the two are very close. So we should expect, that for x near zero, that sqrt(sin(x)) looks a lot like sqrt(x).
Still not getting the idea? Can you build a Taylor series around a function that has a singularity at the expansion point? In fact, no. Do you see why not?
We could write that expansion as simply
f(x0) + f'(x0)/2*(x-x0) + ...
The problem arises at f'(x0), where x0 is the expansion point. That function has a singularity in the first derivative at x==0.
So taylor gets upset. What can you expect?
Suppose however, we decided to form an expansion around a different point? As long as there is no singularity, no problem.
T = taylor(sqrt(sin(x)) + 2, x, 'ExpansionPoint', 1, 'Order', 6)
T =
sin(1)^(1/2) + ((x - 1)^5*((5*cos(1)*(sin(1)^(3/2)/2 + cos(1)^2/(4*sin(1)^(1/2))))/(24*sin(1)) - (cos(1)*sin(1)^(1/2))/24 + (7*cos(1)*(sin(1)^(3/2)/24 + (5*cos(1)^2)/(48*sin(1)^(1/2)) - (5*cos(1)*((cos(1)*sin(1)^(1/2))/4 - (3*cos(1)*(sin(1)^(3/2)/2 + cos(1)^2/(4*sin(1)^(1/2))))/(4*sin(1))))/(6*sin(1))))/(8*sin(1))))/(5*sin(1)) + (cos(1)*(x - 1))/(2*sin(1)^(1/2)) - (((cos(1)*sin(1)^(1/2))/4 - (3*cos(1)*(sin(1)^(3/2)/2 + cos(1)^2/(4*sin(1)^(1/2))))/(4*sin(1)))*(x - 1)^3)/(3*sin(1)) - ((x - 1)^4*(sin(1)^(3/2)/24 + (5*cos(1)^2)/(48*sin(1)^(1/2)) - (5*cos(1)*((cos(1)*sin(1)^(1/2))/4 - (3*cos(1)*(sin(1)^(3/2)/2 + cos(1)^2/(4*sin(1)^(1/2))))/(4*sin(1))))/(6*sin(1))))/(4*sin(1)) - ((sin(1)^(3/2)/2 + cos(1)^2/(4*sin(1)^(1/2)))*(x - 1)^2)/(2*sin(1)) + 2
Now taylor has absolutely no problem, since everything is well defined around x==1.
0 Comments
See Also
Categories
Find more on Calculus in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!