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

    Function printRobertson

    • Print solution of the ROBER benchmark problem

      Returns void

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

      printRobertson();
      # Python reference calculation for comparison
      import numpy as np
      import pandas as pd
      from scipy.integrate import solve_ivp
      
      METHOD = "Radau" # "BDF" or "LSODA"
      
      # -------------------------
      # 1. Define Robertson ODE
      # -------------------------
      def robertson(t, y):
         A, B, C = y
         dA = -0.04 * A + 1e4 * B * C
         dB = 0.04 * A - 1e4 * B * C - 3e7 * B**2
         dC = 3e7 * B**2
         return [dA, dB, dC]
      
      # -------------------------
      # 2. Initial conditions
      # -------------------------
      y0 = [1.0, 0.0, 0.0]
      t_start = 0.0
      t_end = 1e11
      t_step = 2.5e6
      t_span = (t_start, t_end)
      
      # Output points
      t_eval = np.arange(t_start, t_end + t_step, t_step)
      
      # -------------------------
      # 3. Solve ODE
      # -------------------------
      sol = solve_ivp(
         robertson,
         t_span,
         y0,
         method=METHOD,
         t_eval=t_eval,
         rtol=1e-7,
         atol=1e-7
      )
      
      print("Success:", sol.success)
      print("Message:", sol.message)
      
      # sol.t → time array, sol.y.T → concentrations (n_points, 3)
      data = np.column_stack((sol.t, sol.y.T))
      
      # Create DataFrame with headers
      df = pd.DataFrame(data, columns=['time', 'A', 'B', 'C'])
      
      # Save to CSV
      df.to_csv(f'ROBER-using-{METHOD}.csv', index=False)