 The Museum of HP Calculators

HP Forum Archive 08

 programming a piecewise function on the 48 GMessage #1 Posted by Fernando Leyton on 30 June 2002, 8:19 a.m. I'm taking a first calculus course at Paris VI and i want to programm a piecewise function on the HP 48 calculator. The function is : F(x)= 3x if x<-5 = x/2 -5 if -50 I programmed: << ---> X << CASE ' x<-5' THEN ' 3x' END ' -5< x < 0 ' THEN ' x/2 -5 ' END ' x > 0' THEN ' exp(x)' END END >> >> But i don't get the numeric result, only the algebraic expression corresponding to the input domain?

 Re: programming a piecewise function on the 48 GMessage #2 Posted by Ellis Easley on 30 June 2002, 11:45 a.m.,in response to message #1 by Fernando Leyton Maybe you need to press "-> NUM"?

 Re: programming a piecewise function on the 48 GMessage #3 Posted by Rupert (Northern Italy, EU) on 30 June 2002, 12:27 p.m.,in response to message #1 by Fernando Leyton > But i don't get the numeric result, only the algebraic expression > corresponding to the input domain? Just add EVAL after any algebraic expression you need to evaluate. It looks like there is a test who needs to be re-written, too: << ---> X << CASE 'X < -5' THEN '3*X' EVAL END 'X > -5 AND X < 0' THEN 'X/2-5' EVAL END 'X > 0' THEN 'EXP(X)' EVAL END END >> >> --

 Re: programming a piecewise function on the 48 GMessage #4 Posted by Vieira, Luiz C. (Brazil) on 30 June 2002, 11:44 p.m.,in response to message #1 by Fernando Leyton Hi; Just to know: does the final expression, when evaluated, return the expected result? If so, a single ->NUM after the last END is enough, because all possible CASEs return an algebraic expression. Say, you could try: ```« -> X « CASE 'X<-5' THEN '3*X' END 'X>-5 AND X<0' THEN 'X/2-5' END 'X>0' THEN 'EXP(X)' END END ->NUM » » ``` (the ->NUM can also come between both » and »). If you wanna try an RPL solution (no need of a ->NUM adding): ```« -> X « CASE X -5 < THEN X 3 * END X -5 > X 0 < AND THEN X 2 / 5 - END X 0 > THEN X EXP END END » » ```(I know you did not ask for it, but I am a compulsive RPL programmer... my shrink said so.) Hope you have success.

 Re: programming a piecewise function on the 48 GMessage #5 Posted by Arnold Steekelenburg on 1 July 2002, 9:29 a.m.,in response to message #1 by Fernando Leyton Hi Fernando, Another way is this: Type in: 'F(X)=IFTE(X<-5,3*X,IFTE(X>-5 AND X<0,X/2-5,EXP(X)))' Then press left-shift STO (= Define) Press VAR and you'll see the variable (function) F. Type a value and press the softkey for F and this will be evaluated immediately. Right-shift F will give you the program the HP48 has created as a result of the DEFinition. IFTE = short IF THEN ELSE Using this construction you can plot piecewise functions too. Arnold Go back to the main exhibit hall