trkstep.cpp - numeric - C++ library with numerical algorithms | |
git clone git://src.adamsgaard.dk/numeric | |
Log | |
Files | |
Refs | |
LICENSE | |
--- | |
trkstep.cpp (541B) | |
--- | |
1 #include <stdlib.h> | |
2 #include <cmath> | |
3 #include <vector> | |
4 | |
5 using namespace std; | |
6 | |
7 // Stepper function | |
8 void rkstep( | |
9 void f(int, double, vector<double>*, vector<double>*), | |
10 int n, double t, vector<double>* y, double h, vector<double>* y1… | |
11 { | |
12 vector<double> k0(n); | |
13 vector<double> y12(n); | |
14 vector<double> k12(n); | |
15 (*f)(n,t,y,&k0); | |
16 for(int i = 0;i<n;i++) y12[i] = (*y)[i]+k0[i]*h/2; | |
17 (*f)(n,(t+h/2),&y12,&k12); | |
18 for(int i = 0;i<n;i++) (*y1)[i] = (*y)[i]+k12[i]*h; | |
19 for(int i = 0;i<n;i++) (*dy)[i] = (k0[i]-k12[i])*1*(h)/2; | |
20 }; |