using System; using static System.Console; using static System.Math; using System.Collections.Generic; public partial class ODE{ public static Func,double,vector,double,(vector,vector)> stepper = rkstep23; //stepper = rkstep12; public static vector driver( Func F, /* equation */ double a, vector ya, double b, double acc=0.01, double eps=0.01, double h=0, List xlist=null, List ylist=null, int limit=999 ) {// ODE driver int nsteps=0; if(h==0)h=(b-a)/64; if(xlist!=null) {xlist.Clear(); xlist.Add(a);} if(ylist!=null) {ylist.Clear(); ylist.Add(ya);} double x=a; vector y=ya, tol=new vector(y.size); do{ if(x>=b) return y; if(nsteps>limit) throw new Exception($"driver: nsteps>{limit}\n"); if(x+h>b) h=b-x; var (yh,erv) = stepper(F,x,y,h); for(int i=0;itol[i])ok=false; // double tol = Max(acc,yh.norm()*eps) * Sqrt(h/(b-a)); // double err = erv.norm(); // bool ok = (err<=tol); if(ok){ x+=h; y=yh; nsteps++; if(xlist!=null) xlist.Add(x); if(ylist!=null) ylist.Add(y); } // if(err==0) h *= 2; // else h *= Min( Pow(tol/err,0.25)*0.95 , 2); double factor = tol[0]/Abs(erv[0]); for(int i=1;i