The ordinary differential equation to solve.
Optionalh?: numberThe time step size. Either this or steps must be provided.
Optionalmethod?: "euler" | "midpoint" | "heun" | "ralston" | "rk4"The integration method to use: "euler", "midpoint", "heun", "ralston", or "rk4".
OptionalreturnObject?: booleanWhether to return the results as an array of objects (only if initial state was provided as an object).
Optionalsteps?: numberThe number of steps to take. Either this or h must be provided.
Optionalt0?: numberThe initial time.
The final time.
The initial state.
The solution containing time points t, state array y, and optionally state objects yObj.
// Solve first-order ODE using Euler's method:
const ode1 = Chalkboard.diff.init((t, y) => -2 * y);
const sol1 = Chalkboard.diff.solve(ode1, {
t0: 0, t1: 5, h: 0.1,
y0: 1,
method: "euler"
});
// Solve second-order ODE using Ralston method:
const ode2 = Chalkboard.diff.init((t, y, dy) => -y);
const sol2 = Chalkboard.diff.solve(ode2, {
t0: 0, t1: 10, steps: 100,
y0: { y0: 1, dy0: 0 },
method: "ralston",
returnObject: true
});
// Solve system ODE using fourth-order Runge-Kutta method:
const odeSys = Chalkboard.diff.init((t, y) => [y[1], -y[0]], 2);
const solSys = Chalkboard.diff.solve(odeSys, {
t0: 0, t1: 10, steps: 100,
y0: [1, 0]
});
Solves an ordinary differential equation using an explicit method.