Chalkboard - v3.0.1
    Preparing search index...

    Function ode

    • Plots an ODE solution. Supports both scalar and system ODEs. For scalar ODEs, plots y(t). For systems, can plot either y[j] vs t or y[j] vs y[i] (phase plot) based on the "phase" config option.

      Parameters

      • sol: { t: number[]; y: number[][] }

        The solution object from Chalkboard.diff.solve or Chalkboard.diff.solveAdaptive

      • config: {
            context?: CanvasRenderingContext2D;
            i?: number;
            j?: number;
            lineWidth?: number;
            phase?: boolean;
            size?: number;
            strokeStyle?: string;
            x?: number;
            y?: number;
        } = {}
        • Optionalcontext?: CanvasRenderingContext2D

          Canvas context

        • Optionali?: number

          x-component index (for phase plots)

        • Optionalj?: number

          y-component index (for phase plots)

        • OptionallineWidth?: number

          Stroke width

        • Optionalphase?: boolean

          If true, plots y[j] vs y[i] (phase plot), if false, plots y[i] vs t

        • Optionalsize?: number

          Scale, defaults to 1, divided by 100 internally for finer control

        • OptionalstrokeStyle?: string

          Stroke color

        • Optionalx?: number

          x-offset (canvas translation), defaults to canvas center

        • Optionaly?: number

          y-offset (canvas translation), defaults to canvas center

      Returns number[][]

      // Plot scalar solution y(t)
      const ode1 = Chalkboard.diff.exponential(-1);
      const sol1 = Chalkboard.diff.solve(ode1, { t0: 0, t1: 5, steps: 300, y0: 1 });
      Chalkboard.plot.ode(sol1, { strokeStyle: "red", size: 1 });

      // Phase plot for harmonic oscillator (y vs dy)
      const ode2 = Chalkboard.diff.harmonic();
      const sol2 = Chalkboard.diff.solve(ode2, { t0: 0, t1: 20, steps: 2000, y0: { y0: 1, dy0: 0 } });
      Chalkboard.plot.ode(sol2, { phase: true, i: 0, j: 1, strokeStyle: "blue" });