Class 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.

    See Also:
    Wikipedia: Runge-Kutta-Fehlberg method
    • Field Detail

      • DEFAULT_SAFETY_FACTOR

        public static final double DEFAULT_SAFETY_FACTOR
        Default value for the safety factor γ.
        See Also:
        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