The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 795 - File: showthread.php PHP 7.4.33 (FreeBSD)
File Line Function
/showthread.php 795 errorHandler->error





Post Reply 
Need help with RPL Listing for "SOLVER FOR ANY VARIABLE"
07-07-2019, 08:45 PM (This post was last modified: 07-07-2019 08:46 PM by Namir.)
Post: #1
Need help with RPL Listing for "SOLVER FOR ANY VARIABLE"
Hi All,

I have a presentation for HHC2019 that Richard Nelson asked me to do. It is a multi-variable solver. Meaning that given an equation with N variables, you can solve for any variable given fixed values for the remaining N-1 variables.

I would like an RPL version (see teh HP-71B and HP-4C versions that solve for any variable in simple financial equation FV=PV*(1+i)^n).

I will give credit to the author of the author of the version I will use in my presentation. I will also mention that author in my presentation that will appear on YouTube.

Here is the HP-71B Listing

Code:
10 REM SOLVER FOR ANY VARIABLE
20 DIM X(20)
30 READ N, K, T
40 DATA 4, 1, 1E-7
50 FOR I=1 TO N
60 IF I=K THE DISP "GUESS FOR ";
70 DISP "X(";I;")"; @ INPUT X(I)
80 NEXT I
90 H = 0.01*(1 + ABS(X(K)))
100 GOSUB 1000 @ F0 = F
110 X0=X(K) @ X(K) = X0 + H
120 GOSUB 1000
130 D = H * F0 /(F - F0)
140 X(K) = X0 - D
150 IF ABS(D) > T THEN 90
160 DISP "ROOT = ";X(K)
1780 END
1000 REM CALCULATE F(X)=0
1001 REM X(1) = FV = PV*(1+I)^N
1002 REM X(2) = PV
1003 REM X(3) = I
1004 REM X(4) N
1010 F = X(1)-X(2)*(1+X(3))^X(4)
1020 RETURN

For an HP-41C Code, here is the memory map:

Code:
R00 = I
R01 = X(1)
R02 = X(2)
....
R20 = X(20)
R21 = N
R22 = K
R23 = Toler
R24 = h
R25 = F0
R26 = D
R27 = X0

And here is the HP-41C Listing:

Code:
LBL "MVSOLV"
LBL A
"N?"
PROMPT
STO 21
1E3
/
1
+
STO 00
"K?"
PROMPT
STO 22
"TOLER?"
PROMPT
STO 23
LBL 00        # Input variables
RCL 22
RCL 00
INT
CLA
X#Y?
"GUESS "
|-"X<"
FIX 0
ARCL X
|-">?"
FIX 5
PROMPT
STO IND 00
ISG 00
GTO 00        # end of input loop
LBL 01
RCL IND 22
ABS
1
+
0.01
*
STO 24        # calculate and store h
XEQ E
STO 25        # calculate F0
RCL IND 22
STO 27        # X0 = X(K)
RCL 24
STO+ IND 22    # X(K) = X(K) + h
XEQ E
RCL 25
-
1/X
RCL 25
*
RCL 24
*
STO 26        # Diff = X(K) - f(X(K)) / f'(X(K))
RCL 27
-
CHS
STO IND 22    # X(K) = X(K) - Diff
RCL 26
ABS
RCL 23
X<Y?        # Tolerance less than absolute difference in X(K)?
GTO 01        # resume iterations
"ROOT="
RCL IND 22
ARCL X
PROMPT
RTN
LBL E
1
RCL 03
+
RCL 04
Y^X
RCL 02
*
RCL 01
-
RTN
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Need help with RPL Listing for "SOLVER FOR ANY VARIABLE" - Namir - 07-07-2019 08:45 PM



User(s) browsing this thread: