Thursday, March 20, 2014

4th Order Runge-Kutta numerical method.

Wrote a C object to manage the code and data around generating Runge-Kutta 4th order interpolation of data.  Fairly efficient algorithm.  I estimate that it will process about 3 million points a second on a single core of a slow netbook computer.  I tried to use the same variable names in the interface that seemed to be used in most books and papers on this topic.

I  do auto ranging based on a step size per number unit.  So if your function runs from 0 to 5 and you ask for 5 steps per number, then you would end up with 5*5+1 = 26 max steps.  The +1 comes from the initial value at the start of the range, then you would do 5 steps in the 1 interval, 5 steps in the 2 interval, and so on.

Source code is here:
https://github.com/BuckRogers1965/Examples/blob/master/Math/NumericAnalysis/RungeKuttaTest.c
https://github.com/BuckRogers1965/Examples/blob/master/Math/NumericAnalysis/RungeKutta.h
https://github.com/BuckRogers1965/Examples/blob/master/Math/NumericAnalysis/RungeKutta.c



The example program, you pass in the starting value, the start and end points, the step per unit, and the function you are interpolating.
 
The object does the rest with the interface below:


The Object Interface to the Runge-Kutta module.
Once you create an object you can retrieve all the properties and data values for the object.
When you are done, you dispose the object to free the memory. 


The output for the example from the book, exact same values.

No comments:

Post a Comment