How to set variable degree to TF1 polN


I am implementing a C++ program using ROOT to make point interpolations and I would like to know how to set a different polynomial degree in polN for TF1 writing a variable for the degree desired instead of the integer. For example, I want to create a polynomial of n degree (n is the number of data points received in my program), which isn’t equal for every set of points. How can I do it?


You should be able to define a parametric TF1 where n is the parameter of the polynomial. You can use for example the ROOT::Math::Polynomial class of MathMore (see )

Here is an example:

auto func = [](double *x, double *p) { 
                     int n = p[0]; 
                     double * params = p+1;
                     ROOT::Math::Polynomial pol(n); 
                     return   pol(x, params);
double xmin = -2; double xmax = 2; 
int n = 3;  
int npar = n + 2;
TF1 * f1 = new TF1("f1",func, xmin, xmax, npar); 
f1->SetParameters(n, 1, -3, 0 ,2); 


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.