programming a piecewise function on the 48 G Fernando Leyton Junior Member Posts: 1 Threads: 1 Joined: Jan 1970 06-30-2002, 08:19 AM 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? Ellis Easley Posting Freak Posts: 909 Threads: 40 Joined: Jan 1970 06-30-2002, 11:45 AM Maybe you need to press "-> NUM"? Rupert (Northern Italy, EU) Junior Member Posts: 25 Threads: 2 Joined: Jan 1970 06-30-2002, 12:27 PM > 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 >> >> -- Vieira, Luiz C. (Brazil) Posting Freak Posts: 4,027 Threads: 172 Joined: Aug 2005 06-30-2002, 11:44 PM 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. Arnold Steekelenburg Junior Member Posts: 22 Threads: 1 Joined: Jan 1970 07-01-2002, 09:29 AM 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 « Next Oldest | Next Newest »

 Possibly Related Threads... Thread Author Replies Views Last Post HP50g: Writing a function that returns a function Chris de Castro 2 636 12-10-2013, 06:49 PM Last Post: Han 50g piecewise functions Kurt Fankhauser 6 689 09-15-2013, 08:01 PM Last Post: Kurt Fankhauser Weekend programming challenge: Euler's Totient function Allen 36 2,330 06-03-2012, 10:39 PM Last Post: Paul Dale Programming RPN on the 48? snaggs 58 2,854 09-08-2011, 04:35 PM Last Post: Howard Owen 48's Ron 9 807 10-19-2005, 02:36 PM Last Post: Crawl Custom Programming vs. Pre-packaged programming Eddie Shore 3 479 01-24-2005, 03:42 AM Last Post: Karl Schneider HP 48 G Peter Torrione 4 460 12-15-2004, 02:11 AM Last Post: Tnohl x=4? Function Shawn 2 352 10-01-2002, 10:12 AM Last Post: Vieira, Luiz C. (Brazil) Implement 'AND' function with 'XOR' function. tal 4 467 12-13-2000, 05:55 AM Last Post: Steve (Australia) HP-48 Programming Books Jeff 4 454 11-06-1999, 09:38 PM Last Post: Chuck Ratliff

Forum Jump: