I wanted to know how could I change the values of arguments in a C++/C program from python. In the program below I use the Newton-Raphson method to compute the roots of a function. What I want is to change the value of the variable xn (for the initial guess) to a certain value given in a python interface. This code is very simple but I am trying a bigger code where I need to change the values of some variables and I dont want to compile the code each time I change the values of these variables.
I can write an input file in order to avoid compiling the code again but what I want is
controlling the code even more, for instance, stop the program at a certain time step and
change the values of the variables and the continue the execution.
Could you tell me if there is a straightforward way to do that?
Regards.
#include <iostream>
using namespace std;
double first_derivative(double x)
{
double dummy;
// Parabolic Function
dummy = 2.0 * x + 7.0;
return (dummy);
}
double second_derivative(double x)
{
double dummy;
//Parabolic Function
dummy = 2.0 ;
return(dummy);
}
int main ()
{
double xn,fd,sd;
int i,n;
i=0;
xn=4.0 ;
cout << i << " " << xn << "\n" ;
for(i=0; i<10 ; i++) {
fd = first_derivative(xn);
sd = second_derivative(xn);
xn = xn - fd/sd ;
cout << i << " " << fd << " " << sd << " " << xn << "\n" ;
}
return 0;
}