Post Reply 
(15C) Runge-Kutta 4th order method
06-23-2015, 06:25 PM (This post was last modified: 06-15-2017 01:18 PM by Gene.)
Post: #1
(15C) Runge-Kutta 4th order method
This program is from a post by Valentin Albillo in the old forum:
Small HP calc versus MATHEMATICA ! [LONG]

Code:
001 - 42,21,11  LBL A       013 -    44  3  STO 3       025 -    45  1  RCL 1       037 -    32  2  GSB 2
002 -    44  0  STO 0       014 -    32  0  GSB 0       026 -    42 31  PSE         038 - 44,40, 3  STO+ 3
003 -       33  R↓          015 -    32  0  GSB 0       027 -    45  2  RCL 2       039 -    43 32  RTN
004 -    43 32  RTN         016 - 45,40, 2  RCL+ 2      028 -    42 31  PSE         040 - 42,21, 2  LBL 2
005 - 42,21,12  LBL B       017 -    45  0  RCL 0       029 -    22  1  GTO 1       041 - 45,40, 1  RCL+ 1
006 -    44  1  STO 1       018 -    32  2  GSB 2       030 - 42,21, 0  LBL 0       042 -    32 13  GSB C
007 -       34  x<>y        019 -    45  3  RCL 3       031 -        2  2           043 - 45,20, 0  RCL× 0
008 -    44  2  STO 2       020 -        6  6           032 -       10  ÷           044 - 44,40, 3  STO+ 3
009 - 42,21, 1  LBL 1       021 -       10  ÷           033 - 45,40, 2  RCL+ 2      045 -    43 32  RTN
010 -       34  x<>y        022 - 44,40, 2  STO+ 2      034 -    45  0  RCL 0       046 - 42,21,13  LBL C
011 -    32 13  GSB C       023 -    45  0  RCL 0       035 -        2  2           047 -    43 32  RTN
012 - 45,20, 0  RCL× 0      024 - 44,40, 1  STO+ 1      036 -       10  ÷

Example:
Quote:Given the equation \({y}' = x^2 + y^2\), with \(y(0) = 0\), find an accurate value for \(y(2)\).

It turns out that there is a singularity near \(x = 2\) which can be removed using a change of variable: \(y = \tan(z)\)
This leads to:

\({z}' = \frac{x^2 + \tan^2(z)}{1 + \tan^2(z)}\)

The initial condition is: \(z(0) = 0\)

This differential equation is programmed under LBL C:
Code:
046 - 42,21,13  LBL C
047 -    43 11  x²
048 -       34  x<>y
049 -       25  TAN
050 -    43 11  x²
051 -       40  +
052 -        1  1
053 -    43 36  LSTx
054 -       40  +
055 -       10  ÷
056 -    43 32  RTN

In RAD mode, using \(h = 0.1\), then \(h = 0.05\), we get:

\(\begin{array}{l l l}
\hline\hline
x & y (h=0.1) & y (h=0.05) \\
\hline
0 & 0 & 0 \\
1 & 0.3368811 & 0.3368813 \\
1.7 & 1.2463033 & 1.2463031 \\
1.8 & 1.3606417 & 1.3606412 \\
1.9 & 1.4666491 & 1.4666485 \\
2.0 & 1.5676491 & 1.5676489 \\
\hline
\end{array}
\)

This clearly shows that the singularity has been effectively removed, so we've got:

z(2) = 1.5676489

and thus:

y(2) = tan(z(2)) = 317.7225457


Attached File(s)
.zip  runge-kutta.zip (Size: 1.01 KB / Downloads: 6)
Find all posts by this user
Quote this message in a reply
Post Reply 




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