int i;
for (i=0;i<n;i++) {
for (int j=0;j<n;j++) a[i][j] = -dfdy[i][j];
a[i][i] += 1.0/(gam*h);
}
LUdcmp alu = new LUdcmp(a);
for (i=0;i<n;i++)
ytemp[i]=dydx[i]+h*d1*dfdx[i];
alu.solve(ytemp,k1);
for (i=0;i<n;i++)
ytemp[i]=y[i]+a21*k1[i];
derivs.derivs(x+c2*h,ytemp,dydxnew);
for (i=0;i<n;i++)
ytemp[i]=dydxnew[i]+h*d2*dfdx[i]+c21*k1[i]/h;
alu.solve(ytemp,k2);
for (i=0;i<n;i++)
ytemp[i]=y[i]+a31*k1[i]+a32*k2[i];
derivs.derivs(x+c3*h,ytemp,dydxnew);
for (i=0;i<n;i++)
ytemp[i]=dydxnew[i]+h*d3*dfdx[i]+(c31*k1[i]+c32*k2[i])/h;
alu.solve(ytemp,k3);
for (i=0;i<n;i++)
ytemp[i]=y[i]+a41*k1[i]+a42*k2[i]+a43*k3[i];
derivs.derivs(x+c4*h,ytemp,dydxnew);
for (i=0;i<n;i++)
ytemp[i]=dydxnew[i]+h*d4*dfdx[i]+(c41*k1[i]+c42*k2[i]+c43*k3[i])/h;
alu.solve(ytemp,k4);
for (i=0;i<n;i++)
ytemp[i]=y[i]+a51*k1[i]+a52*k2[i]+a53*k3[i]+a54*k4[i];
double xph=x+h;
derivs.derivs(xph,ytemp,dydxnew);
for (i=0;i<n;i++)
k6[i]=dydxnew[i]+(c51*k1[i]+c52*k2[i]+c53*k3[i]+c54*k4[i])/h;
alu.solve(k6,k5);
for (i=0;i<n;i++)
ytemp[i] += k5[i];
derivs.derivs(xph,ytemp,dydxnew);
for (i=0;i<n;i++)
k6[i]=dydxnew[i]+(c61*k1[i]+c62*k2[i]+c63*k3[i]+c64*k4[i]+c65*k5[i])/h;
alu.solve(k6,yerr);
for (i=0;i<n;i++)
yout[i]=ytemp[i]+yerr[i];
}