#include #include "nr.h" using namespace std; void NR::stiff(Vec_IO_DP &y, Vec_IO_DP &dydx, DP &x, const DP htry, const DP eps, Vec_I_DP &yscal, DP &hdid, DP &hnext, void derivs(const DP, Vec_I_DP &, Vec_O_DP &)) { const DP SAFETY=0.9,GROW=1.5,PGROW= -0.25,SHRNK=0.5; const DP PSHRNK=(-1.0/3.0),ERRCON=0.1296; const int MAXTRY=40; const DP GAM=1.0/2.0,A21=2.0,A31=48.0/25.0,A32=6.0/25.0,C21= -8.0, C31=372.0/25.0,C32=12.0/5.0,C41=(-112.0/125.0), C42=(-54.0/125.0),C43=(-2.0/5.0),B1=19.0/9.0,B2=1.0/2.0, B3=25.0/108.0,B4=125.0/108.0,E1=17.0/54.0,E2=7.0/36.0,E3=0.0, E4=125.0/108.0,C1X=1.0/2.0,C2X=(-3.0/2.0),C3X=(121.0/50.0), C4X=(29.0/250.0),A2X=1.0,A3X=3.0/5.0; int i,j,jtry; DP d,errmax,h,xsav; int n=y.size(); Mat_DP a(n,n),dfdy(n,n); Vec_INT indx(n); Vec_DP dfdx(n),dysav(n),err(n),ysav(n),g1(n),g2(n),g3(n),g4(n); xsav=x; for (i=0;i ERRCON ? SAFETY*h*pow(errmax,PGROW) : GROW*h); return; } else { hnext=SAFETY*h*pow(errmax,PSHRNK); h=(h >= 0.0 ? MAX(hnext,SHRNK*h) : MIN(hnext,SHRNK*h)); } } nrerror("exceeded MAXTRY in stiff"); }