I'm trying to use odeint to solve a differential equation of the form:
y[0]'(r)=y1,
y[1]'(r)=f(y,r)
where t appears explicitly. How do I write "r" in the code for the equation?
See example below
typedef std::vector< double > state_type;
class phieq{
double lambda, mu, g, sigma, rv;
public:
phieq(double mlambda, double mmu, double mg, double msigma, double mrv) : lambda(mlambda), mu(mmu), g(mg), sigma(msigma), rv(mrv) {}
void operator() (const state_type &y , state_type &dydr , const double /* t */)
{ dydr[0] = y[1];
dydr[1] = -((2.0*y[1])/r)+lambda*y[0]*y[0]*y[0]-(mu*mu)*y[0];
}
};
r is your independent variable in this case. odeint originates from dynamical systems so it uses t (for time) for this in its example. In your case you should write
void operator() (const state_type &y , state_type &dydr , const double r)
and then you can use r in the expressions below.