Skip to content

Instantly share code, notes, and snippets.

@quirinpa
Created April 1, 2016 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quirinpa/701d6b3c85913ceebaa3b99bbf431bd0 to your computer and use it in GitHub Desktop.
Save quirinpa/701d6b3c85913ceebaa3b99bbf431bd0 to your computer and use it in GitHub Desktop.
#ifndef RK4_H
#define RK4_H
double rk4(double xi, double yi, double h, double df()) {
double k[4];
k[0] = df(xi, yi);
k[1] = df(xi + h/2, yi + h*k[0])/2;
k[2] = df(xi + h/2, yi + h*k[1])/2;
k[3] = df(xi + h, yi + h*k[2]);
return yi + h(k[0]+2*(k[1]+k[2]) + k[3])/6;
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment