Saturday, September 21, 2013

This program calculates y(x), once is given dy/dx expression and na initial value, y(xo). This calculation is based on Runge-Kutta 4th order algorithm. For more information, consult the following link of Wikipedia http://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods

Variables:

Y : Current variable y.
X : Current variable x.
Z : Value of x for which you want to calculate the value of y.
F : Expression in the format dy/dx = f(y,x).
N : Number of steps will be divided the lenth between initial x and final x (Z).
H : Length of each step, so N x H = (Z- xo).
J, K and I : Intermediate variables.
A : Intermediate variable to keep saved the current variable x in each step of calculation.
B : Intermediate variable to keep saved the current variable y in each step of calculation.


Example:

dy/dx = y+ex
y(0)=1
y(3)=?

In fact, the analitical solution is y = (x+1)ex , so y(3) = 80.3421.  Case you don’t know the analitical solution, this program will give you the required information. The error depends of the number of steps. However, the computing time will increase with the number of steps.


N
Y(3)
Time spent by HP 35s (s)
10
80.5776
7
20
80.3857
14
30
80.3569
20
40
80.3488
26






See below the program listing for HP 35s scientific calculator.

Program R (Runge-Kutta, fourth-order)   LN=292  CK=75BD

R001 LBL R
R002 SF 10
R003 EDIT ROUTINE F
R004 DY÷DX=F(X,Y)
R005 INITIAL VALUE=
R006 X AND Y
R007 TARGET=DEFINE
R008 Y VALUE TO X=Z
R009 N = NUMBER
R010 OF STEPS
R011 CF 10
R012 INPUT N
R013 INPUT X
R014 STO A
R015 INPUT Y
R016 STO B
R017 x<>y
R018 INPUT Z
R019 x<>y
R020 -
R021 RCL÷ N
R022 STO H
R023 XEQ F001
R024 RCL× H
R025 STO I
R026 2
R027 ÷
R028 STO+ Y
R029 RCL H
R030 2
R031 ÷
R032 STO+ X
R033 XEQ F001
R034 RCL× H
R035 STO J
R036 2
R037 ÷
R038 RCL+ B
R039 STO Y
R040 XEQ F001
R041 RCL× H
R042 STO K
R043 RCL+ B
R044 STO Y
R045 RCL A
R046 RCL+ H
R047 STO X
R048 STO A
R049 XEQ F001
R050 RCL× H
R051 RCL J
R052 RCL+ K
R053 2
R054 ×
R055 RCL+ I
R056 6
R057 ÷
R058 STO+ B
R059 RCL X
R060 RCL Z
R061 x>y?
R062 GTO R023
R063 VIEW Y
R064 RTN
F001 LBL F
F002 RCL X
F003 ex
F004 RCL+ Y
F005 RTN



No comments:

Post a Comment