HP prime: derivatives Alberto Candel Member Posts: 72 Threads: 16 Joined: Sep 2013 11-28-2013, 12:33 PM 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. Dieter Senior Member Posts: 653 Threads: 26 Joined: Aug 2010 11-28-2013, 01:06 PM 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. Alberto Candel Member Posts: 72 Threads: 16 Joined: Sep 2013 11-28-2013, 01:29 PM 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` Dieter Senior Member Posts: 653 Threads: 26 Joined: Aug 2010 11-28-2013, 01:37 PM 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. Alberto Candel Member Posts: 72 Threads: 16 Joined: Sep 2013 11-28-2013, 01:54 PM Ah! Thank you for the clarification. But then ` h(x):=IFTE(x=0,1,x/EXPM1(x))` results in `h'(0)=+/- inf` It may be something with xcas algorithms for derivatives. Tim Wessman Posting Freak Posts: 1,278 Threads: 44 Joined: Jul 2007 11-28-2013, 02:15 PM 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. parisse Junior Member Posts: 38 Threads: 0 Joined: Aug 2013 11-29-2013, 07:05 AM 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. You must use limit to find the derivative at a singular point, if you simply evaluate, then x is replaced by 0 in the analytic expression of the derivative (which does not take care of an ifte defined only for one point). Alberto Candel Member Posts: 72 Threads: 16 Joined: Sep 2013 11-29-2013, 12:02 PM OK, thanks. BTW, what is the real difference between exp(x)-1 and EXPM1(x)? The example given in the Help of the prime is EXPM1(0.23) and this is the same as exp(0.23)-1 for the Prime. But even much smaller numbers like x=0.00001 lead to the same result. Dieter Senior Member Posts: 653 Threads: 26 Joined: Aug 2010 11-29-2013, 03:14 PM 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) --------------------------------------------------------------- 0,23 1,25860000993 0,25860000993 0,258600009929 0,0022 1,00220242178 2,20242178000 E-3 2,20242177564 E-3 1 E-5 1,00001000005 1,00000500000 E-5 1,00000500002 E-5 1/9 E-7 1,00000001111 1,11110000000 E-8 1,11111111728 E-8 1/7 E-9 1,00000000014 1,40000000000 E-10 1,42857142867 E-10 1/6 E-11 1,00000000000 0,00000000000 1,66666666667 E-12 ``` 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. Alberto Candel Member Posts: 72 Threads: 16 Joined: Sep 2013 11-29-2013, 06:45 PM 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? « Next Oldest | Next Newest »

 Possibly Related Threads... Thread Author Replies Views Last Post HP 35s derivatives/extremums Richard Berler 16 3,184 09-14-2013, 04:55 PM Last Post: Matt Agajanian Derivation of (HP) Derivatives... Matt Agajanian 6 1,730 05-25-2012, 09:46 PM Last Post: Crawl derivatives and indefinate integrals JeffG 3 935 03-15-2002, 10:23 AM Last Post: Thibaut.be 38G Derivatives and Integrals Brandon 0 669 10-15-1999, 11:24 PM Last Post: Brandon

Forum Jump: