Class AdaptiveRungeKutta<T>
The adaptive Runge-Kutta integrator of an ordinary differential equation f'(x) = F(x, f(x)), F from ℝ × Kⁿ to Kⁿ, K the real or the complex numbers: Cash and Karp's embedded fifth-order step, whose fourth-order error estimate sets the next step's size (Numerical Recipes in C, chapter 16.2).
public class AdaptiveRungeKutta<T> where T : INumberBase<T>
Type Parameters
- Inheritance
-
AdaptiveRungeKutta<T>
- Derived
- Inherited Members
Remarks
QuantLib's real coefficients multiply the values as values of T, and a value's magnitude is
T.Abs's, as a real. For finite values that is C++'s arithmetic on std::complex too.
An equation whose function returns a vector of another length than its argument's is refused, where QuantLib reads past the shorter one.
Immutable and thread-safe: it holds only its settings, and each integration works on its own state. Unsealed for its named class, QuantLib-Python's RungeKutta.
Constructors
AdaptiveRungeKutta(double, double, double)
Initializes a new instance of the AdaptiveRungeKutta<T> class.
public AdaptiveRungeKutta(double eps = 1E-06, double h1 = 0.0001, double hmin = 0)
Parameters
epsdoubleThe error prescribed for the solution.
h1doubleThe first step's size.
hmindoubleThe smallest step size allowed.
Methods
Evaluate(Func<double, ImmutableArray<T>, ImmutableArray<T>>, ReadOnlySpan<T>, double, double)
The solution at x2 of f'(x) = F(x, f(x)) with f(x1) = y1:
QuantLib's operator().
public ImmutableArray<T> Evaluate(Func<double, ImmutableArray<T>, ImmutableArray<T>> ode, ReadOnlySpan<T> y1, double x1, double x2)
Parameters
odeFunc<double, ImmutableArray<T>, ImmutableArray<T>>F, returning a vector of its argument's length.
y1ReadOnlySpan<T>The initial value.
x1doubleThe initial point.
x2doubleThe point of the solution, before or after
x1.
Returns
- ImmutableArray<T>
f(
x2).
Exceptions
- ArgumentNullException
odeis null.- NanoQLException
odereturned a vector of another length, the step size fell to the smallest allowed or underflowed, or the integration took too many steps.
Evaluate(Func<double, T, T>, T, double, double)
The solution at x2 of the one-dimensional f'(x) = F(x, f(x)) with
f(x1) = y1: QuantLib's operator() on a scalar function.
public T Evaluate(Func<double, T, T> ode, T y1, double x1, double x2)
Parameters
odeFunc<double, T, T>F.
y1TThe initial value.
x1doubleThe initial point.
x2doubleThe point of the solution, before or after
x1.
Returns
- T
f(
x2).
Exceptions
- ArgumentNullException
odeis null.- NanoQLException
The step size fell to the smallest allowed or underflowed, or the integration took too many steps.