# SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.analysis.differentialequation.ode.ivp.solver.rungekutta

## Class RungeKuttaFehlberg

• java.lang.Object
• com.numericalmethod.suanshu.analysis.differentialequation.ode.ivp.solver.rungekutta.RungeKuttaFehlberg
• All Implemented Interfaces:
ODESolver

public class RungeKuttaFehlberg
extends Object
implements ODESolver
The Runge-Kutta-Fehlberg method is a version of the classic Runge-Kutta method, which additionally uses step-size control and hence allows specification of a local truncation error bound.

In particular, the algorithm estimates the error by comparing the results of the 5th and the 4th order Runge-Kutta solutions. This step requires six evaluations of the input method.

To be conservative, a safety factor γ is included in the step size update formula, to make the new step size somewhat smaller than that predicted to yield the local error exactly equal to the error upper bound.

In this implementation, the step size is updated by this formula: $h_1 = \gamma \left( \frac{\max\left\{ \left \| y \right \|, 1 \right\} \epsilon}{\left \| E \right \|} \right)^{1/5} h_0,$ where $$\gamma$$ is the safety factor, $$y$$ and $$E$$ are the current abscissa and error respectively, $$\epsilon$$ is the lower bound of the local truncation error, until the error criterion $\left \| E \right \| \le \max\left\{ \left \| y \right \|, 1 \right\} \epsilon$ is met.

Wikipedia: Runge-Kutta-Fehlberg method
• ### Field Summary

Fields
Modifier and Type Field and Description
static double DEFAULT_SAFETY_FACTOR
Default value for the safety factor γ.
• ### Constructor Summary

Constructors
Constructor and Description
RungeKuttaFehlberg(double epsilon, double minStepSize)
Create a new instance of the Runge-Kutta-Fehlberg method for the given parameters, with the default safety factor value.
RungeKuttaFehlberg(double epsilon, double minStepSize, double gamma)
Create a new instance of the Runge-Kutta-Fehlberg method with the given safety factor.
• ### Method Summary

All Methods
Modifier and Type Method and Description
ODESolution solve(ODE1stOrder ode)
Solve the given ODE using Runge-Kutta-Fehlberg method.
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Field Detail

• #### DEFAULT_SAFETY_FACTOR

public static final double DEFAULT_SAFETY_FACTOR
Default value for the safety factor γ.
Constant Field Values
• ### Constructor Detail

• #### RungeKuttaFehlberg

public RungeKuttaFehlberg(double epsilon,
double minStepSize)
Create a new instance of the Runge-Kutta-Fehlberg method for the given parameters, with the default safety factor value.
Parameters:
epsilon - the upper bound on the local truncation error
minStepSize - the lower bound on step size
• #### RungeKuttaFehlberg

public RungeKuttaFehlberg(double epsilon,
double minStepSize,
double gamma)
Create a new instance of the Runge-Kutta-Fehlberg method with the given safety factor.
Parameters:
epsilon - the upper bound on the local truncation error
minStepSize - the lower bound on step size
gamma - the safety factor (0 < γ ≤ 1)
• ### Method Detail

• #### solve

public ODESolution solve(ODE1stOrder ode)
Solve the given ODE using Runge-Kutta-Fehlberg method. The result will range from α to β, where the steps taken depends on the execution of the algorithm, which in turn depends on the accuracy of the respective step sizes.

If the error criterion cannot be satisfied using step sizes greater than or equal to hMin, an UnsatisfiableErrorCriterionException will be thrown. In this case, either hMin has to be decreased or epsilon has to be increased.

Specified by:
solve in interface ODESolver
Parameters:
ode - the ODE problem
Returns:
the solution