I have a mathematical function f(x,p)
that depends on argument x
and parameters p
. I want to dynamically allocate memory for p ( void *)
and return a function g(x)
after the parameters values are fed f
. How do I implement this in C++?
More specifically, this is the usage scenario I'm hoping to achieve:
double x;
p1 = new double[2];
p2 = new double[2];
g1 = f(p1)
g2 = f(p2)
g1(x);
g2(x);
g1(x)
and g2(x)
are functions that compute f(x,p1)
and f(x,p2)
, respectively.
Thank you.