Post Reply 
Need help with RPL Listing for "SOLVER FOR ANY VARIABLE"
07-08-2019, 06:26 PM
Post: #3
RE: Need help with RPL Listing for "SOLVER FOR ANY VARIABLE"
Namir, if you're simply wanting an RPL version of the same program logic that you're using in the other supplied programs, then the following may provide a starting point.

This is meant to mimic your 71B structure/flow as closely as possible, and uses the same variable names that you specified in that version. As Claudio has mentioned, the built-in solver would be better to use, but I'm guessing you simply want to have an RPL equivalent to the other programs. That's what I've attempted to do here.

Code:
\<<
   0. 20. NDUPN \->ARRY          @ X[]
   4.                            @ N
   1.                            @ K
   1E-7                          @ T
   'X(1)-X(2)*(1.+X(3))^X(4)'    @ F
   0. DUPDUP DUP                 @ F0, X0, H, D
   \-> X N K T F F0 X0 H D
   \<<
      @ obtain X values
      1. N FOR index
         "X("
         IF
            index K SAME
         THEN
            "Guess for " SWAP +
         END
         index R\->I \->STR +
         "):" +
         "" INPUT STR\->
         'X' index ROT PUT
      NEXT

      @ repeat until current delta within specified tolerance
      DO
         X K GET ABS 1. + 0.01 *
         'H' STO

         F \->NUM
         'F0' STO

         X K GET
         'X0' STO

         'X' K
         X0 H +
         PUT

         H F0 * F \->NUM F0 - /
         'D' STO

         'X' K
         X0 D -
         PUT
      UNTIL
         D ABS T \<=
      END

      @ output X(K)
      X K GET "Root" \->TAG
   \>>
\>>

No attribution needed, you (and everyone else) should feel free to make improvements or modify however you like. My goal in this case was to replicate the same logic flow as the other programs as opposed to focusing on code size, speed, or special RPL features. I used an algebraic for F in this case to make the coding a closer match to the 71B version.

If logic flow parity wasn't your intended target for this, please ignore and move on. Smile

Hope this helps!
- David
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Need help with RPL Listing for "SOLVER FOR ANY VARIABLE" - DavidM - 07-08-2019 06:26 PM



User(s) browsing this thread: 2 Guest(s)