HP Forums
How to evaluate A Taylor series at a specific value - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: How to evaluate A Taylor series at a specific value (/thread-10729.html)

Pages: 1 2


How to evaluate A Taylor series at a specific value - Seisner - 05-11-2018 11:44 PM

Just got the Prime and was able to get the Taylor expansion for a function. But cannot figure out how to evaluate it at a specific value of x. Thanks!


RE: How to evaluate A Taylor series at a specific value - Tim Wessman - 05-12-2018 03:40 AM

Put your cursor on the "taylor" part of the input, or select the function in the menu and press the HELP button. Does any of the help for the taylor function explain what you need?


RE: How to evaluate A Taylor series at a specific value - Seisner - 05-12-2018 10:13 AM

Thanks but no, it gives me the syntax for using the Taylor function but does not include an option to evaluate the polynomial at, say, x = 3. I can change the Taylor to be centered at x = 3, but that is not the same.


RE: How to evaluate A Taylor series at a specific value - parisse - 05-12-2018 02:25 PM

CAS:
p:=taylor(sin(x),x=0,5,polynom);
p(x=3)


RE: How to evaluate A Taylor series at a specific value - Joe Horn - 05-12-2018 02:36 PM

EDIT: Yikes, while I was writing the following reply, Bernard beat me to it with his simpler method above. I leave the following here for historical purposes. Wink

There might be a simpler way, but this way only takes two steps and it does work.

(1) In CAS, execute taylor(function)
(2a) select and copy the result to the command line, then backspace the entire "order_size" term
(2b) press the template key (C) and tap the third item (the "where" function)
(2c) type x=whatever value you want, and press Enter
(3) optional: compare with the exact value

Example for sin(x) where x=0.5:

[Image: taylor.png]

Note: The default order for the taylor() function is 5. If a different order is desired, just specify it using taylor's syntax, e.g. taylor(sin(x),x,7)) for order 7.


RE: How to evaluate A Taylor series at a specific value - DrD - 05-12-2018 02:44 PM

(Variation on a theme):

taylor(sin(x))|x = 0.5

-Dale-


RE: How to evaluate A Taylor series at a specific value - Seisner - 05-12-2018 02:53 PM

Thanks all for the very quick replies! I knew there had to be a way. Still getting used to the Prime.


RE: How to evaluate A Taylor series at a specific value - Joe Horn - 05-12-2018 02:56 PM

(05-12-2018 02:44 PM)DrD Wrote:  (Variation on a theme):

taylor(sin(x))|x = 0.5

-Dale-

Hmmmm.... That seems to return sin(.5), not the desired result. Not sure why. Perhaps the x gets substituted right away, resulting in taylor(sin(.5))?


RE: How to evaluate A Taylor series at a specific value - DrD - 05-12-2018 03:01 PM

Probably due to settings ...
[attachment=5930]


RE: How to evaluate A Taylor series at a specific value - Joe Horn - 05-12-2018 03:06 PM

(05-12-2018 03:01 PM)DrD Wrote:  Probably due to settings ...

That's not the desired result. That's sin(.5). See my screen shot above and compare the two outputs to yours.


RE: How to evaluate A Taylor series at a specific value - DrD - 05-12-2018 03:13 PM

I see what you mean. I tried it another way, and it seems to just return the SIN(x), not the taylor series evaluation. Oopsie!

Same thing if you make it into a function of x:

f(x):=taylor(SIN(x));
f(.5) ⇒ sin(.5) = 0.479425538604

Ignores the tayor() series expansion. Is that fair play, or bug?


RE: How to evaluate A Taylor series at a specific value - Mark Hardman - 05-12-2018 04:00 PM

Bernard's example used an extra, undocumented 4th paramter: polynom. This appears to return the expansion without the O term. If we use his syntax, it works:

taylor(sin(x),x,5,polynom) = x-1/6*x^3+1/120*x^5

taylor(sin(x),x,5,polynom)|x=(1/2) = 1841/3840 = 0.479427083333


RE: How to evaluate A Taylor series at a specific value - DrD - 05-12-2018 04:42 PM

The trick is trying to remember the tricks!


RE: How to evaluate A Taylor series at a specific value - Mark Hardman - 05-12-2018 04:53 PM

[Image: 258141405ffc9510_giphy.gif]


RE: How to evaluate A Taylor series at a specific value - Aries - 08-21-2018 03:00 PM

[Image: taylor.jpg]

Best,

Aries Wink


RE: How to evaluate A Taylor series at a specific value - parisse - 08-21-2018 04:47 PM

But a Taylor expansion has two parts: the polynomial part and the remainder term. Unfortunately students tend to forget the remainder term, and that will not help if the calculator ignores it as well. That's why you have taylor(.) and taylor(.,polynom) on the HP. And if you don't remind the polynom trick, you can still run f:=taylor(sin(x),x=0,5) then f|x=0.5 and ignore the order_size term.
:-)


RE: How to evaluate A Taylor series at a specific value - Komanguy - 08-21-2018 07:37 PM

(08-21-2018 04:47 PM)parisse Wrote:  But a Taylor expansion has two parts: the polynomial part and the remainder term. Unfortunately students tend to forget the remainder term, and that will not help if the calculator ignores it as well. That's why you have taylor(.) and taylor(.,polynom) on the HP. And if you don't remind the polynom trick, you can still run f:=taylor(sin(x),x=0,5) then f|x=0.5 and ignore the order_size term.
:-)

Best answer.

Thanks a lot.


RE: How to evaluate A Taylor series at a specific value - Han - 08-21-2018 08:54 PM

(05-12-2018 02:56 PM)Joe Horn Wrote:  
(05-12-2018 02:44 PM)DrD Wrote:  (Variation on a theme):

taylor(sin(x))|x = 0.5

-Dale-

Hmmmm.... That seems to return sin(.5), not the desired result. Not sure why. Perhaps the x gets substituted right away, resulting in taylor(sin(.5))?

This is somewhat related to the original question. Computer software is not as adept at identifying the intended order of operations. While taylor(sin(x))|x = 0.5 seems "obvious" to most readers, one must ask (from the point of view of the software) when should substitution occur? Should it be after the evaluation of the taylor() command (or more generally, any command), or should it occur before the evaluation? Even extra parentheses would not help; think carefully as to why. To avoid such ambiguity, users should separate the operations into two separate steps.


RE: How to evaluate A Taylor series at a specific value - KeithB - 08-22-2018 02:09 PM

Much like the comma operator in C. When you use the comma operator:

x = 5, 6;
the order of execution is fixed and the results are clear.

But, in a function call:

x = f(g(), h());

the comma is *not* a comma operator but a list separator and the operations can be done in any order. Probably in the order YACC does it. 8^)


RE: How to evaluate A Taylor series at a specific value - Albert Chan - 08-22-2018 06:56 PM

[Image: taylor.png]

(05-12-2018 02:56 PM)Joe Horn Wrote:  
(05-12-2018 02:44 PM)DrD Wrote:  taylor(sin(x))|x = 0.5

Hmmmm.... That seems to return sin(.5), not the desired result. Not sure why.
Perhaps the x gets substituted right away, resulting in taylor(sin(.5))?

This is a bug.
Evaluate a taylor series while carrying the O[x] term is meaningless.
This is how Mathematica hande it:

In[1]:= taylor = Series[Sin[x], {x, 0, 5}]
Out[1]= x - x^3/6 + x^5/120 + O[x]^6

In[2]:= taylor /. x -> 0.5
SeriesData::ssdn: Attempt to evaluate a series at the number 0.5; returning Indeterminate.
Out[2]= Indeterminate

In[3]:=Normal[taylor] /. x -> 0.5 (* Drop the O[x] term, then substitute *)
Out[3]= 0.479427

BTW, Mathematica (v 4.0) had the bug too, if x had Pi in it.

In[4]:= taylor /. x-> 1/2 + Pi/10^10 // N
Out[4]= 1. 0.5 - 0.166667 0.125 + .00833333 0.03125 + O[0.5]^6

In[5]:= % // Normal (* above should be Indeterminate too ! Sad *)
Out[5]= 0.479427

BTW, you can test evaluation order with this: (x/x) |x = 0
For Mathematica, it is evaluation before substitution, result = 1, not 0/0