 The Museum of HP Calculators

HP Articles Forum

HP-15C First Degree Runge-Kutta Order 4

Posted by Patrick on 4 Aug 2003, 2:56 p.m.

## Description

Here is an HP-15C program that implements a fourth-order Runge-Kutta algorithm for a first degree ODE. It has the attributes of being somewhat miserly in its use of resources compared with routines published in HP Solutions handbooks. The program is only 45 steps long and requires the use of only 4 registers and 1 flag.

## Usage

```Label A
Input: h ENTER y ENTER x [A]
Output: X = new x, Y = new y, Z = delta X = h, T = delta Y
```

```Label B
Assumes: Label A previously run.
Input: h [B]
Output: Same as for Label A
```

```Label C
Assumes: Label A previously run.
Input: Nothing.
Output: Same as for Label A.
```

```Label D (not provided)
This is the label under which you must code the function, f(x,y), which defines the derivative: y' = f(x,y).
```

Basically, Label A is used to initialize the algorithm and compute a single step. Label C is used to take additional steps with the same step size. Label B is used to take additional steps with a new step size (for use with adaptive step-size techniques).

## Resources Used

```R0 = h/2
R1 = x
R2 = y
R3 = Used
Flag 0 = Used, left clear
```

## Program

```001	LBL A	Main algorithm entry point specifying x, y, and h
002	STO 1	Initialize R1 = x
003	RDN
004	STO 2	Initialize R2 = y
005	RDN
006	LBL B	Entry point for adaptive step size techniques.
007	2
008	/
009	STO 0	Initialize R0 = h/2
010	LBL C	Entry point for RK iteration using current values
011	CLx
012	STO 3
013	CF 0
014	0
015	GSB 0
016	SF 0
017	1
018	GSB 0
019	1
020	GSB 0
021	CF 0
022	2
023	GSB 0
024	RCL 3
025	3
026	/
027	STO+2
028	2
029	RCL*0
030	STO+1
031	RCL 2
032	RCL 1
033	RTN
034	LBL 0	Internal label
035	*
036	RCL+2
037	LAST x
038	RCL*0
039	RCL+1
040	GSB D	Derivative at specified (x,y) point
041	RCL*0
042	STO+3
043	FS?0
044	STO+3
045	RTN
046	LBL D
Code derivative function here
RTN
```