Post Reply 
Need help with RPL Listing for "SOLVER FOR ANY VARIABLE"
07-08-2019, 11:52 PM
Post: #6
RE: Need help with RPL Listing for "SOLVER FOR ANY VARIABLE"
So there were actually 3 commands not supported on a 48GX, and I was right about the array subscripts (which are not supported on the 48 series). Also, one additional layer of locals is now needed since the function F references locals from the array that have to already have been declared and in-scope -- being able to define it as an algebraic in the previous example worked around that issue.

I also rearranged the input loop a bit to make it easier to read (IMHO).

It's always surprising to me how often I use commands and features that didn't come into play until the 49-50 series. It doesn't "feel" like I do it that often when I'm coding, but on those rare occasions when I write 48-series code I see the evidence firsthand. Smile

Code:
\<<
   { 20 } 0 CON                  @ X[]
   4                             @ N
   1                             @ K
   1E-7                          @ T
   0 DUP DUP DUP                 @ F0, X0, H, D
   \-> X N K T F0 X0 H D
   \<<
      \<<                        @ F
         @ X(1)-X(2)*(1+X(3))^X(4)
         X 1 GET
         X 2 GET
         X 3 GET 1 +
         X 4 GET ^
         * -
      \>>
      \-> F
      \<<
         @ obtain X values
         1 N FOR index
            "X(" index \->STR + "):" +
            IF
               index K SAME
            THEN
               "Guess for " SWAP +
            END
            "" 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 EVAL
            'F0' STO

            X K GET
            'X0' STO

            'X' K
            X0 H +
            PUT

            H F0 * F EVAL F0 - /
            'D' STO

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

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

Note: I'm just transcoding here, so I'm not asserting that this program is fully debugged and operational. I haven't done much testing -- just a couple of basic scenarios which seem to work.

Question: Have you insured in the algorithm that the indefinite loop exit condition is guaranteed to occur? In other words, is it possible that some inputs might cause the "delta" to always be greater than the tolerance value?
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 11:52 PM



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