RPL Programming question


I have a question for guru RPL programmers. How do I pass an algebraic expression to an RPL program object so I can evaluate that expression in the object. I understand that I also need to pass the name of the variable that appear in the expression along with a value (at least one).

My goal is to be able to write different RPL program objects that perform various kinds of numerical analysis calculations for algorithms that require an expression/equation (such as root calculations, numerical integration, solving ODEs, and so on).

I appreciate any help.



If your RPL program is named FOO, and needs an algebraic expression to be passed in on the stack, you would invoke it like:

     '4*X^3-2*X^2+3*X-5' FOO

FOO could keep the algebraic object on the stack, or it might store it into a local variable:

    << -> f << blah blah 3.7 'X' STO blah f EVAL blah blah >> >>

Note that this works for using an RPL program as an argument, too:

    << X COS DUP * >> FOO

Edited: 18 Sept 2007, 2:40 p.m.


Thanks Eric!! I appreciate taking teh time to explain it for me.

Based on your example I created the following program object (and stored it as FOO):

<< -> F V << V STO F EVAL >> >>

Where F and V are variables that store the expression and the name of the variable used in that expression.

So the following sample input gives the correct result of 18:

4 'Z1*Z1+2' 'Z1' FOO


Edited: 18 Sept 2007, 4:18 p.m.



Building on your tip, here a program object that applies Newton's root algorithm:

<< DUP2 _derivative_ -> F V D
<< V STO
ABS 0.0000001 <

Note: _derivative_ stands for the derivative operator character.

The variables are:

1. Variable F stores the expression whose root is sought.

2. Variable V stores the name of the variable.

3. Variable D store the derivative of the expression.

To use the above program, enter the input in the following sequence:

1. An initial guess for the root, such as 4.

2. The expression whose root is sought, such as 'EXP(X)-3*SQ(X)'.

3. The name of the variable in the above expression, 'X' in this case.

Invoke the name of the program object to obtain a refined guess for the root.

The beauty of the above RPL object is that it obtains the derivative symbolically and uses it to evaluate the derivative in each iteration. For once, I don't have to worry about calculating an approximation to the derivative. Wooohoooo!


Edited: 18 Sept 2007, 8:06 p.m.

Possibly Related Threads…
Thread Author Replies Views Last Post
  Writing RPL programs on OS X Sean Freeman 18 5,228 11-30-2013, 03:59 PM
Last Post: Sean Freeman
  48G vs 49G+ User RPL Speed Comparison John Colvin 7 2,607 11-16-2013, 10:07 PM
Last Post: Han
  RPL 32 David Hayden 4 2,081 11-11-2013, 11:34 AM
Last Post: David Hayden
  HHC / HP Museum Programming Contest for RPN and RPL machines Gene Wright 18 5,584 09-22-2013, 09:39 AM
Last Post: Miguel Toro
  Simple? programming question [WP34S] Shawn Gibson 3 1,453 03-15-2013, 11:56 AM
Last Post: Didier Lachieze
  RPL long vs. short names peacecalc 5 2,037 10-30-2012, 01:25 PM
Last Post: peacecalc
  Mini-challenge: HHC2012 RPL programming contest with larger input David Hayden 14 3,604 10-05-2012, 10:36 PM
Last Post: David Hayden
  HHC 2012 RPL Programming Contest Gene Wright 33 7,800 09-27-2012, 01:57 AM
Last Post: Werner
  HHC 2012 programming contests coming soon (RPN and RPL) Gene Wright 9 2,688 09-21-2012, 03:38 PM
Last Post: Paul Dale
  WP-34S Programming Question Matt Agajanian 2 1,247 08-04-2012, 02:04 PM
Last Post: Matt Agajanian

Forum Jump: