Chalkboard - v3.0.1
    Preparing search index...

    Function solve

    • Solves an ordinary differential equation using an explicit method.

      Parameters

      • ode: ChalkboardODE

        The ordinary differential equation to solve.

      • config: {
            h?: number;
            method?: "euler" | "midpoint" | "heun" | "ralston" | "rk4";
            returnObject?: boolean;
            steps?: number;
            t0?: number;
            t1: number;
            y0: number | number[] | Record<string, any>;
        }
        • Optionalh?: number

          The 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?: boolean

          Whether to return the results as an array of objects (only if initial state was provided as an object).

        • Optionalsteps?: number

          The number of steps to take. Either this or h must be provided.

        • Optionalt0?: number

          The initial time.

        • t1: number

          The final time.

        • y0: number | number[] | Record<string, any>

          The initial state.

      Returns { t: number[]; y: number[][]; yObj?: { [key: string]: number }[] }

      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]
      });