Trying to built a program but meet some problem in it about the pointer to use.
I have created this
which work fine with a function.
Now I try to implement it with a equation in a function
something like this
A bit stuck on how to pass the equation to the receiving function. Anyone have any idea? Might have to pass equation 1 on some time and pass equation to on another time. Or should i implement the solution in the class rather than calling it externally?
I have created this
Code:
double runge_kutta_4th(double(*equation)(double,double), double initial, double t, double dt){
double k1 = equation(initial, t);
double k2 = equation(initial + 0.5 * k1 * dt, t + 0.5 *dt);
double k3 = equation(initial + 0.5 * k2 * dt, t + 0.5 *dt);
double k4 = equation(initial + k3 * dt, t + dt);
return initial + (k1 + 2*k2 + 2*k3 + k4)/6 * dt;
}
Now I try to implement it with a equation in a function
something like this
Code:
class equation{
public:
double a;
double b;
double c;
equation(double a, double b, double c):
a(a),
b(b),
c(c)
{
}
~equation(){
}
double equation1(double y, double t){
return (a) * t - b* y;
}
double equation2(double y, double t){
return 3 * (a) * t - b* y;
}
};
Comment