Table of Contents

Class AdaptiveRungeKutta<T>

Namespace
NanoQL.Numerics
Assembly
NanoQL.dll

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

T

The values' type: double, or Complex for a complex equation.

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

eps double

The error prescribed for the solution.

h1 double

The first step's size.

hmin double

The 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

ode Func<double, ImmutableArray<T>, ImmutableArray<T>>

F, returning a vector of its argument's length.

y1 ReadOnlySpan<T>

The initial value.

x1 double

The initial point.

x2 double

The point of the solution, before or after x1.

Returns

ImmutableArray<T>

f(x2).

Exceptions

ArgumentNullException

ode is null.

NanoQLException

ode returned 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

ode Func<double, T, T>

F.

y1 T

The initial value.

x1 double

The initial point.

x2 double

The point of the solution, before or after x1.

Returns

T

f(x2).

Exceptions

ArgumentNullException

ode is null.

NanoQLException

The step size fell to the smallest allowed or underflowed, or the integration took too many steps.