parsing arguments from python to c++ -
i wanted know how change values of arguments in c++/c program python. in program below use newton-raphson method compute roots of function. want change value of variable xn (for initial guess) value given in python interface. code simple trying bigger code need change values of variables , dont want compile code each time change values of these variables.
i can write input file in order avoid compiling code again want is
controlling code more, instance, stop program @ time step , change values of variables , continue execution. tell me if there straightforward way 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 << << " " << xn << "\n" ; for(i=0; i<10 ; i++) { fd = first_derivative(xn); sd = second_derivative(xn); xn = xn - fd/sd ; cout << << " " << fd << " " << sd << " " << xn << "\n" ; } return 0; }
if want act python it's best write in python.
you cannot "change numbers" of compiled program. can do, however, make program accept parameters change @ runtime. can in c++ command-line parameters, configuration files, or asking input. easier involving python.
if reason parts of code have in c++ , want python, can expose c++ routines library python. 1 popular approach swig. make functions you'd call python accept changeable parameters. python script call them.
Comments
Post a Comment