TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Nonanti/mathcore/llms.txt
Use this file to discover all available pages before exploring further.
mathcore::differential module provides numerical solvers for ordinary and partial differential equations. DifferentialEquations handles scalar first-order ODEs (RK4), systems of ODEs, second-order ODEs, Euler’s method, stiff ODEs (implicit Euler with Newton iteration), and linear constant-coefficient ODEs. The companion PDESolver struct implements finite-difference schemes for the heat equation, wave equation, and Laplace equation. All time-evolution solvers return an ODESolution containing sampled time and state values.
pub struct ODESolution
The result type returned by all ODE solver methods.
| Field | Type | Description |
|---|---|---|
t | Vec<f64> | Monotonically increasing time (or spatial) values, starting at t0 and ending at t_final. Length is steps + 1. |
y | Vec<Vec<f64>> | State values at each time step. Each inner Vec<f64> holds the values of all dependent variables. For scalar ODEs the inner vector has length 1; for systems it has length equal to the number of equations. |
pub enum BoundaryCondition
Encodes the two standard forms of boundary data for ODE problems.
| Variant | Fields | Use case |
|---|---|---|
InitialValue | t0, y0 | Standard Cauchy / IVP problems where all state is known at the start. |
BoundaryValue | ta, tb, ya, yb | BVPs where partial state is specified at both ends of the domain. |
pub struct DifferentialEquations
A zero-sized unit struct grouping all ODE solver methods.
solve_ode_first_order
Solves a scalar first-order ODE dy/dt = f(t, y) using the fourth-order Runge-Kutta (RK4) method. The expression f is evaluated symbolically at each stage of every step by substituting the current t and y values via the engine.
RK4 update rule (per step of size h):
The right-hand side expression
f(t, y). Must evaluate to Expr::Number when t_var and y_var are substituted with numeric values.The name of the independent variable (time). Bound at each evaluation.
The name of the dependent variable (state). Bound at each stage of RK4.
Tuple
(t0, y0) — the initial time and initial state value.The end time of integration. The step size is computed as
h = (t_final - t0) / steps.Number of equal sub-intervals. The solution grid has
steps + 1 points.Ok(ODESolution) with t and y vectors, or Err(MathError::InvalidOperation) if f evaluates to a non-numeric result at any stage.
euler_method
Solves dy/dt = f(t, y) using the simple first-order forward Euler method. Less accurate than RK4 but computationally cheaper and useful for pedagogical comparison.
solve_ode_first_order. The update rule is y ← y + h * f(t, y).
solve_stiff_ode
Solves a stiff first-order scalar ODE using the implicit (backward) Euler method with Newton iteration to resolve the implicit equation at each step. The jacobian parameter optionally supplies a symbolic expression for ∂f/∂y; when None, a numerical finite-difference approximation is used.
The right-hand side expression
f(t, y).Optional expression for
∂f/∂y. When None, the Jacobian is approximated numerically with a finite-difference step of 1e-8.Independent variable name.
Dependent variable name.
Tuple
(t0, y0).End time.
Number of time steps.
Newton-iteration convergence tolerance. The inner Newton loop runs up to 10 iterations; it terminates early when
|residual| < tolerance.solve_ode_second_order
Reduces a second-order linear ODE y'' + p(x)*y' + q(x)*y = r(x) to a system of two first-order equations and solves it with RK4.
Coefficient of
y' (may depend on x_var).Coefficient of
y (may depend on x_var).The forcing (right-hand side) function (may depend on
x_var).The name of the independent variable.
Tuple
(x0, y(x0), y'(x0)) — starting position, value, and first derivative.End of the integration domain.
Number of steps. Each
y vector in the solution contains [y, y'] at the corresponding x.solve_ode_system
Solves a system of n coupled first-order ODEs dy_i/dt = f_i(t, y₁, ..., y_n) simultaneously using RK4.
Slice of expressions
f₁, ..., fₙ. Must have the same length as y_vars and initial_conditions.1.The independent variable name.
Names of the dependent variables in the same order as
functions.Tuple
(t0, [y₁(t0), y₂(t0), ..., yₙ(t0)]).Integration end time.
Number of time steps. Each
y inner vector has length n.solve_linear_constant_coeff
Finds the general analytical solution of a linear ODE with constant coefficients by factoring the characteristic polynomial and constructing the basis of exponential (and oscillatory) solutions. The equation is represented by its coefficient vector [aₙ, aₙ₋₁, ..., a₁, a₀] for the operator aₙ y^(n) + ... + a₁ y' + a₀ y = 0.
The method builds the characteristic polynomial aₙ rⁿ + ... + a₁ r + a₀, finds its roots via Solver::solve, and assembles the general solution using terms of the form Cᵢ · e^(rᵢ t) for real roots and e^(αt) · (Cᵢ cos(βt) + Cⱼ sin(βt)) for complex-conjugate pairs.
Coefficients of the ODE in descending order of derivative:
[aₙ, aₙ₋₁, ..., a₁, a₀]. The leading coefficient a₀ corresponds to the highest-order derivative y^(n). Must be non-empty.Initial values
[y(0), y'(0), ..., y^(n-1)(0)]. The length must equal coefficients.len() - 1 (i.e. the order of the ODE).Ok(Expr) containing the symbolic general solution (with undetermined constants C1, C2, etc.), or Err(MathError) if the coefficient or initial condition arrays are empty or have mismatched sizes.
pub struct PDESolver
Implements finite-difference PDE solvers for the three classical second-order PDEs.
solve_heat_equation
Solves the 1-D heat equation ∂u/∂t = α ∂²u/∂x² using the explicit (forward-in-time, centred-in-space) finite-difference scheme. Enforces the CFL-like stability criterion α * dt/dx² ≤ 0.5; violating it returns an error.
Thermal diffusivity coefficient.
Closure evaluated at each spatial grid point to set
u(x, 0).Dirichlet boundary value at
x = x_min for all t > 0.Dirichlet boundary value at
x = x_max for all t > 0.Spatial domain
(x_min, x_max).Total simulation time.
Number of spatial grid points.
Number of time steps.
Ok(Vec<Vec<f64>>) of shape nt × nx containing the field u(t, x), or Err if the stability criterion is violated.
solve_wave_equation
Solves the 1-D wave equation ∂²u/∂t² = c² ∂²u/∂x² using an explicit second-order finite-difference scheme. Enforces the CFL condition c * dt/dx ≤ 1.
Wave propagation speed.
Sets
u(x, 0) — the initial displacement profile.Sets
∂u/∂t(x, 0) — the initial velocity profile.solve_laplace_equation
Solves the 2-D Laplace equation ∇²u = 0 on a rectangular domain using Gauss-Seidel iteration. Boundary values are supplied via a closure that returns Some(value) at boundary points and None at interior points.
Given coordinates
(x, y), returns Some(u) to fix the value as a boundary condition, or None to mark the point as an interior unknown.Gauss-Seidel convergence threshold. Iteration stops early when the maximum change in any cell drops below this value.
Hard upper bound on iteration count regardless of convergence.
