# HP Forums

Full Version: How to evaluate A Taylor series at a specific value
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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!
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?
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.
CAS:
p:=taylor(sin(x),x=0,5,polynom);
p(x=3)
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. 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: 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.
(Variation on a theme):

taylor(sin(x))|x = 0.5

-Dale-
Thanks all for the very quick replies! I knew there had to be a way. Still getting used to the Prime.
(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))?
Probably due to settings ...
[attachment=5930]
(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.
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?
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
The trick is trying to remember the tricks!  Best,

Aries 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.
:-)
(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.
:-)

Thanks a lot.
(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.
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^) (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:= taylor = Series[Sin[x], {x, 0, 5}]
Out= x - x^3/6 + x^5/120 + O[x]^6

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

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

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

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

In:= % // Normal (* above should be Indeterminate too ! *)
Out= 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
Pages: 1 2
Reference URL's
• HP Forums: https://www.hpmuseum.org/forum/index.php
• :