HP prime: derivatives - Printable Version +- HP Forums (https://archived.hpcalc.org/museumforum) +-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html) +--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html) +--- Thread: HP prime: derivatives (/thread-257267.html) |
HP prime: derivatives - Alberto Candel - 11-28-2013 Hi Being a holiday here, I had some extra time to play with this instrument. Here is an issue with how the prime handles derivatives of functions that I do not comprehend. Maybe there is documentation in xcas about it, but ....
I define a function b(x):=IFTE(x=0,1,x/(exp(x)-1) This is a nice function that has a power series around 0 whose coefficients are the Bernoulli number B(n) divided by n! So the derivative b'(0)=-1/2, but the HP prime computes b'(0)=+/- inf. I cannot figure out how it does that. Thanks!
Edited: 28 Nov 2013, 12:58 p.m.
Re: HP prime: derivatives - Dieter - 11-28-2013 What happens if you use the more exact and dedicated ex-1 command in the denominator, i.e. EXPM1(x) ? Dieter
Edited: 28 Nov 2013, 1:09 p.m.
Re: HP prime: derivatives - Alberto Candel - 11-28-2013 Thanks, I did not know about EXPM1. But if I set h(x):=IFTE(x=0,1,x/(EXPM1(x)-1))I obtain (if not mistaken) h'(0)=-1 Re: HP prime: derivatives - Dieter - 11-28-2013 Alberto, EXPM1(x) already subtracts 1. That's why it says M1 (minus one). You must not add another subtraction. ;-) h(x):=IFTE(x=0,1,x/EXPM1(x))Compare the results of EXP(x) - 1 with those obtained by using EXPM1(x) for some x close to zero, and you will see why this special command exists. Dieter
Edited: 28 Nov 2013, 1:40 p.m.
Re: HP prime: derivatives - Alberto Candel - 11-28-2013 Ah! Thank you for the clarification. h(x):=IFTE(x=0,1,x/EXPM1(x))results in h'(0)=+/- inf
It may be something with xcas algorithms for derivatives.
Re: HP prime: derivatives - Tim Wessman - 11-28-2013 Dunno. However, you can natively do piecewise functions. I'd use that instead. I suspect that will be easier.
TW Edited: 28 Nov 2013, 2:15 p.m.
Re: HP prime: derivatives - parisse - 11-29-2013 There is a bug that I'm fixing in the source code, infinity-undef should return undef, not infinity, hence you should have undef as result. Re: HP prime: derivatives - Alberto Candel - 11-29-2013 OK, thanks.
BTW, what is the real difference between exp(x)-1 and EXPM1(x)? Re: HP prime: derivatives - Dieter - 11-29-2013 EXPM1(x) is far more accurate as x approaches zero. Consider a small x-value like 1E-12. With 12-digit accuracy, EXP(x) is evaluated as excactly 1, so EXP(x)-1 becomes zero due to roundoff.
Here EXPM1(x) comes to rescue. It is evaluated differently so that the result is exact. Here are some results for 12 digit working precision: x EXP(x) EXP(x)-1 EXPM1(x)So EXPM1(x) (and also its inverse function LNP1(x) = ln(1+x)) allow exact results where their conventional counterparts would return inexact or even useless results. There are extremely useful in many everyday applications. Dieter
Edited: 29 Nov 2013, 3:17 p.m.
Re: HP prime: derivatives - Alberto Candel - 11-29-2013 Thank you again, Dieter. The example EXPM1(0.23) given in Help is very misleading. Are there any references to how these functions are evaluated?
|