it.grypho.scala.leonardo.ode

Members list

Type members

Classlikes

case class _ODE(rhs: _Expression, depVar: _Variable, indepVar: _Variable, t0: _Expression, y0: _Expression, target: _Expression) extends _Functional

Symbolic node for the solution value of a first-order initial-value problem.

Symbolic node for the solution value of a first-order initial-value problem.

Represents y(target) where y satisfies y' = rhs(t, y), y(t0) = y0.

Both depVar (the dependent variable y) and indepVar (the independent variable t) are binders: they are excluded from children so that substitute and dependsOn never recurse into them, matching the convention of scalar._Derivative and scalar._Limit. The expression positions rhs, t0, y0, and target are ordinary children and may hold free variables (e.g. a symbolic target keeps the result closed-form).

Evaluation strategy (two tiers, in order):

  1. Closed-form via solveODESymbolic: handles y' = a*y + b for constant (t-free) a, b; returns a symbolic expression that stays closed-form when t0/y0/target are free.
  2. Numeric RK4 via solveODE: folds t0/y0/target to concrete _Numbers and runs the integrator; returns Right(_Number(result)). When neither applies, eval returns Left(this) — the fixpoint convention shared with the transform nodes and the scalar._Functional hierarchy.

Round-trip: toString emits ode(rhs, depVar, indepVar, t0, y0, target), which re-parses to an equivalent node.

Value parameters

depVar

the dependent variable (the unknown function, e.g. y)

indepVar

the independent variable (what y is differentiated against, e.g. t)

rhs

the right-hand side f(t, y) of the ODE

t0

the initial time point

target

the point at which the solution is evaluated

y0

the initial value y(t0)

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class _Functional
trait _Expression
class Object
trait Matchable
class Any
Show all

Value members

Concrete methods

def solveODE(rhs: _Expression, depVar: _Variable, indepVar: _Variable, t0: Double, y0: Double, target: Double, env: Environment): Option[Double]

Integrates y' = rhs(t, y), y(t0) = y0 to y(target) via RK4.

Integrates y' = rhs(t, y), y(t0) = y0 to y(target) via RK4.

Value parameters

depVar

the dependent variable name (bound to the current y at each stage)

env

the evaluation environment (provides precision and other bindings)

indepVar

the independent variable name (bound to the current t at each stage)

rhs

the right-hand side f(t, y) as a symbolic expression

t0

the initial time

target

the time at which the solution is requested

y0

the initial value y(t0)

Attributes

Returns

Some(y(target)) on success; None if any stage is non-numeric or non-finite

def solveODESymbolic(rhs: _Expression, depVar: _Variable, indepVar: _Variable, t0: _Expression, y0: _Expression, target: _Expression, env: Environment): Option[_Expression]

Closed-form tier for linear first-order IVPs y' = a(t)*y + b(t).

Closed-form tier for linear first-order IVPs y' = a(t)*y + b(t).

The right-hand side must be linear in the dependent variable (collect(rhs, depVar) yields at most a degree-1 coefficient vector [b, a]); non-linear shapes such as sin(y) or y^2 return None (the caller falls back to RK4).

Two sub-tiers:

  1. Constant coefficients (a, b free of the independent variable t) — the exact tau = target - t0 forms, avoiding any substitution:

    • y' = a*y (b = 0): y = y0 * exp(a*tau)
    • y' = b (a = 0): y = y0 + b*tau
    • y' = a*y + b (general): y = (y0 + b/a) * exp(a*tau) - b/a
  2. Variable coefficients (a or b depends on t) — the integrating-factor method. With A = integral(a dt) and mu = exp(-A) the equation (mu*y)' = mu*b integrates to mu*y = Q + C, Q = integral(mu*b dt); the initial condition fixes C = mu(t0)*y0 - Q(t0), giving

   y(target) = (Q(target) - Q(t0) + y0*mu(t0)) / mu(target)

This closes whenever both integral(a dt) and integral(mu*b dt) reduce to a closed form (it reuses the full indefinite-integration engine, so e.g. mu*b = t*e^t is handled by integration by parts); if either stays symbolic, this tier returns None and the caller falls back to RK4.

In both tiers the result stays symbolic when target, y0, t0, or a coefficient is free, and folds to a _Number once everything is concrete.

Value parameters

depVar

the dependent variable (y)

env

the evaluation environment

indepVar

the independent variable (t)

rhs

the right-hand side of the ODE y' = rhs

t0

the initial time (may be symbolic)

target

the evaluation point (may be symbolic)

y0

the initial value (may be symbolic)

Attributes

Returns

Some(closed-form expression for y(target)), or None if not recognised