Table of Contents

Class NumericalMethods

Namespace
Utils.Mathematics
Assembly
Utils.Mathematics.dll

Numerical integration and interpolation utilities.

public static class NumericalMethods
Inheritance
NumericalMethods
Inherited Members

Methods

Integrate<T>(Func<T, T>, T, T, int)

Numerically integrates f over [a, b] using the composite Simpson's 1/3 rule.

public static T Integrate<T>(Func<T, T> f, T a, T b, int steps = 1000) where T : struct, IFloatingPoint<T>

Parameters

f Func<T, T>

Integrand function. Must be defined and finite on [a, b].

a T

Lower bound of integration.

b T

Upper bound of integration.

steps int

Number of sub-intervals. Must be positive and even; an odd value is rounded up by one. Higher values increase accuracy at the cost of more function evaluations.

Returns

T

The approximate value of ∫f(x)dx from a to b. If f returns a non-finite value anywhere in the interval, that non-finite value propagates into the result (visible to the caller as NaN or an infinity) rather than being silently discarded.

Type Parameters

T

Floating-point scalar type.

Exceptions

ArgumentNullException

Thrown when f is null.

ArgumentOutOfRangeException

Thrown when steps is not positive, when steps is the odd value MaxValue (which cannot be rounded up to an even count without overflowing), or when a/b is not finite.

Lagrange<T>(IEnumerable<(T x, T y)>, T)

Evaluates the Lagrange interpolating polynomial at at, given a set of data points.

public static T Lagrange<T>(IEnumerable<(T x, T y)> points, T at) where T : struct, IFloatingPoint<T>

Parameters

points IEnumerable<(T x, T y)>

Sequence of (x, y) data points. All x values must be distinct and every coordinate finite.

at T

The point at which to evaluate the interpolating polynomial. Must be finite.

Returns

T

The interpolated value at at.

Type Parameters

T

Floating-point scalar type.

Remarks

The result is exact at each data point and provides a polynomial approximation elsewhere. For large point sets, consider alternative methods as Lagrange interpolation can exhibit Runge's phenomenon near the boundaries.

Exceptions

ArgumentException

Thrown when no points are provided, a coordinate is not finite, or x values are not distinct.

ArgumentOutOfRangeException

Thrown when at is not finite.