diff-grok - v1.0.10
    Preparing search index...

    Function printVdpol

    • Print solution of the VDPOL benchmark problem

      Returns void

      // TypeScript usage example
      import {printVdpol} from 'diff-grok';

      printVdpol();
      # Python reference calculation for comparison
      import numpy as np
      import pandas as pd
      from scipy.integrate import solve_ivp
      
      # -------------------------
      # 0. Solver method
      # -------------------------
      METHOD = "Radau"  # stiff solver recommended for van der Pol with large mu
      
      # -------------------------
      # 1. Define van der Pol ODE (stiff)
      # -------------------------
      def vdpol(t, y):
         x1, x2 = y
         dx1 = x2
         dx2 = -x1 + 1000 * (1 - x1**2) * x2  # mu = 1000
         return [dx1, dx2]
      
      # -------------------------
      # 2. Initial conditions and time
      # -------------------------
      y0 = [-1, 1]
      t_start = 0.0
      t_end = 2000.0
      t_step = 0.1
      
      # Use linspace to avoid "t_eval not in t_span" error
      n_points = int(np.ceil((t_end - t_start) / t_step)) + 1
      t_eval = np.linspace(t_start, t_end, n_points)
      
      # -------------------------
      # 3. Solve ODE
      # -------------------------
      sol = solve_ivp(
         vdpol,
         (t_start, t_end),
         y0,
         method=METHOD,
         t_eval=t_eval,
         rtol=1e-12,
         atol=1e-12
      )
      
      print("Success:", sol.success)
      print("Message:", sol.message)
      
      # -------------------------
      # 4. Save solution to CSV
      # -------------------------
      data = np.column_stack((sol.t, sol.y.T))
      col_names = ['t', 'x1', 'x2']
      
      df = pd.DataFrame(data, columns=col_names)
      filename = f"VANDERPOL-using-{METHOD}.csv"
      df.to_csv(filename, index=False)
      
      print(f"Solution saved to '{filename}'")