In the below code I'm having trouble calculating the algebraic equation on the line marked with &&&. I attempt to calculate it both within the member function Energy(x) and within find_kin_en(x), but in the latter I find the result equal to zero, which is wrong and disagrees with the correct value calculated in Energy(x). I think the problem might be having multiple nested member functions, i.e. operator() calls Energy(x) which calls find_kin_en().
Anybody know if this is the problem? and what would fix it?
Thanks!
John
#include "/u7/tolsma/Numerical_Recipes/nr_c304/code/nr3.h" // these are numerical recipes libraries, not important for the problem below I believe.
#include "/u7/tolsma/Numerical_Recipes/nr_c304/code/mins.h"
#include "/u7/tolsma/Numerical_Recipes/nr_c304/code/mins_ndim.h"
struct Funcd{ // A functor that gets passed
to the numerical recipes libraries
(where the function Energy(x) is
Doub Energy (VecDoub_IO &x); minimized).
Doub find_kin_en (VecDoub_IO &nx);
//It is clear that in this simple case I do not need to call the member function find_kin_en(xn) but could just as well evaluate it internally in the member function Energy(x). I'm doing it though because Energy(x) will need to call a bunch of other functions as well as find_kin_en(xn) when I get the whole code put together.
Int main(void) {
Doub xmin;
Funcd funcd;
Frprmn<Funcd> frprmn(funcd); // Frprmn is a numerical recipes functor that finds the minimum of the function funcd passed to it
VecDoub p(2);
FILE *f1,*f2;
p[0]=1.0; // initial guesses for the variable x[0] and x[1] used above.
p[1]=2.0;
p=frprmn.minimize(p);
xmin=frprmn.fret; // the minimum value of the function. when evaluated
using the included values, it should give 4.40.
return 0;
}