MATLAB and higher mathematics--Taylor expansion

Taylor expansion of the function

basic knowledge

If we want to get sin(x)the Taylor expansion, enter the following command:

>> syms x;
>> s = taylor(sin(x))

result:

s =
 
x^5/120 - x^3/6 + x

Although it seems that MATLABonly 3 items were returned, it actually returned 5 items because MATLABonly non-zero items were returned.
Now we draw the image:1

Expansion order

To make the image of the polynomial expansion closer sin(x), we must MATLABreturn more terms. Suppose we want to get the mterm expansion, use the ordercommand, followed by the order we want to expand

s = taylor(sin(x),'order',m);

Let's try the first 20 items:

syms x;
s = taylor(sin(x),'order',10)
s =
 
- x^19/121645100408832000 + x^17/355687428096000 - x^15/1307674368000 + x^13/6227020800 - x^11/39916800 + x^9/362880 - x^7/5040 + x^5/120 - x^3/6 + x
 

image:
2

This time the image is smoother than last time.
Another problem is that the order of our expansion is from high to low, which is not what we want, we want to make it from low to high, you can use the symprefcommand:

sympref('PolynomialDisplayStyle','ascend');
s =
 
x - x^3/6 + x^5/120 - x^7/5040 + x^9/362880 - x^11/39916800 + x^13/6227020800 - x^15/1307674368000 + x^17/355687428096000 - x^19/121645100408832000
 

Where to unfold

As we wish, the order is from low to high.
We know that the Taylor formula can be expanded at any point, and at the zero point we call the McLaurin formula.
So, we can also use the command 'ExpansionPoint'to expand at the specified point

s = taylor(sin(x),'order',20,'ExpansionPoint',1)
s = 
sin(1) - (sin(1)*(- 1 + x)^2)/2 + (sin(1)*(- 1 + x)^4)/24 - (sin(1)*(- 1 + x)^6)/720 + (sin(1)*(- 1 + x)^8)/40320 - (sin(1)*(- 1 + x)^10)/3628800 + (sin(1)*(- 1 + x)^12)/479001600 - (sin(1)*(- 1 + x)^14)/87178291200 + (sin(1)*(- 1 + x)^16)/20922789888000 - (sin(1)*(- 1 + x)^18)/6402373705728000 + cos(1)*(- 1 + x) - (cos(1)*(- 1 + x)^3)/6 + (cos(1)*(- 1 + x)^5)/120 - (cos(1)*(- 1 + x)^7)/5040 + (cos(1)*(- 1 + x)^9)/362880 - (cos(1)*(- 1 + x)^11)/39916800 + (cos(1)*(- 1 + x)^13)/6227020800 - (cos(1)*(- 1 + x)^15)/1307674368000 + (cos(1)*(- 1 + x)^17)/355687428096000 - (cos(1)*(- 1 + x)^19)/121645100408832000
Published 84 original articles · won 18 · views 5805

Guess you like

Origin blog.csdn.net/qq_44486550/article/details/105416505
Recommended