Besides one dimensional integrals and derivatives, what other types of integrals and derivatives can Root calculate?

Hi. Besides one dimensional integrals and derivatives, what other types of integrals and derivatives can Root calculate?; Can Root calculate double integrals (2 dimensions); Can Root calculate Triple integrals (3 dimensions)?; How many dimensions, at most, can be considered in Root to calculate integrals and derivatives?. Thanks

ROOT Version: 5.34.25
Platform: Windows 10
Compiler:


Hello @alfredo10101,

it depends a bit how you define the function. Using TF1, TF2, TF3, for example, you can simply call Integral(), and you will get 1-, 2- or 3-dimensional Integrals.

If you defined a generic multi-dimensional function with a signature like double func(double argumentArray[]), you can use ROOT::Math::Functor to create an adapter to the numeric integrators. The integrators can be reached from ROOT::Math::IntegratorMultiDim. They support any dimension.
The tutorial here show how to use these:

And here is the corresponding manual:

Lastly, in RooFit, any dimensionality is possible, but this will be relevant only if you want to perform a multi-dimensional fit.

1 Like

If you want derivatives, you can e.g. use ROOT::Math::Derivator to wrap the function in a numerical derivation algorithm. The list of all derivators can be found here:

1 Like

Ok, Thanks for all the information. The information has been helpful. So, with the information you shared I’m going to try to integrate and derive in one, two and three dimensions, and then I’m going to try to integrate and derive in more than three dimensions. Thank you

Hi. Today I was able to calculate in Root: integrals of functions with one independent variable, double integrals (2 dimensions) and triple integrals (3 dimensions). I was unable to draw the graph of a function of 3 variables (TF3) with the Draw() method; on the Internet I read that I can do something like that if I type “ISO“ inside the parentheses of the Draw() method, but I could not draw the graph of a TF3. So, What do I need to type in the Root command line to see / draw the graph of a TF3 ( f(x,y,z) )?

Hi. I took a look at the information on derivatives you shared, but I couldn´t differentiate. Therefore, I was reading about it online and found the following: I read online that I can derive a one dimensional function with the Derivative() method of TF1, having previously defined a one dimensional function (TF1); In this way I was able to derive one dimensional functions. Then, defining a function of 2 independent variables (TF2), I tried to get the partial derivative with respect to x, but I couldn´t. Below is what I typed in the Root command line to get the partial derivative with respect to x of a function of 2 independent variables; x[0] means x, and x[1] means y; so, this function is x^2 + y^2; this partial derivative is evaluated at x_val, y_val.

TF2 *f2 = new TF2(“f2”,“x[0]*x[0] + x[1]*x[1]”, 0, 10, 0, 10);

double x_val = 2;
double y_val = 3;

double dfdx = f2->DerivativeX(x_val,y_val);

std::cout << "The partial derivative with respect to x is (evaluated at x_val, y_val): " << dfdx << std::endl;

After trying to calculate that partial derivative, the following appears on the Root command line:

Error: Can´t call TF2::DerivativeX(x_val,y_val) in current scope

Possible candidates are…

(in TF2)

(in TF1)

(in TFormula)

So, What do I need to do / type to be able to calculate that partial derivative in Root using the DerivativeX(x_val, y_val) method?; Regarding the method you mentioned and this method, which one is easier to use?.

Hi,

It’s because there is no such thing as “TF2::DerivativeX(...)”.

Ok, thanks, I’ll keep that in mind.

Hi. Using ROOT:: Math::Functor and ROOT::Math::IntegratorMultiDim I was able to calculate the integral of a function f(x,y). Considering the code from the first link you shared (mathmoreIntegrationMultidim), I thought that in order to do an integral of a function f(x,y,z,w) I could type the following:

double f4(const double * x) {
return x[0] + x[1] + x[2] + x[3]; // f= f(x,y,z,w)= x + y + z + w

ROOT::Math::Functor fu(&f4,4);
double a[2] = {0,0};
double b[2] = {1,1};

double c[2] = {2,2};
double d[2] = {3,3};

ROOT::Math::IntegratorMultiDim ig(ROOT::Math::IntegrationMultiDim::kADAPTIVE);
ig.SetFunction(fu);
double val = ig.Integral(a,b,c,d);

However, the following error appeared:

Error: Can´t call IntegratorMultiDim::Integral(a,b,c,d) in current scope

Possible candidates are…

Error: class, struct, union or type IntegratorMultiDim not defined

So, Any suggestions on what i need to type / code in order to integrate a function f(x,y,z,w)?. Thanks in advance

double xmin[] = {0., 0., 2., 2.};
double xmax[] = {1., 1., 3., 3.};
double val = ig.Integral(xmin, xmax);

Hi. I tried to calculate the derivative of a function f(x,y) with Root, but I couldn´t. I´ll keep trying.

Based on the above, Could you tell me step by step what I need to do to calculate the derivative of a function f(x,y) with Root?. Thanks

Thanks for your help. I typed that in the macro and Root calculated the integral. The result is 6. The only thing left to do is calculate that integral with another tool or in another way to verify that the result is correct. What is the level of difficulty of calculating that integral?, Is it easy or difficult?. Is there an online tool to calculate that integral?

Wolfram|Alpha → integrate (x + y + z + w) dx dy dz dw, x=0..1, y=0..1, z=2..3, w=2..3

1 Like

Thanks for your help. This online tool also calculates the integral and the result is 6; I also calculated the integral on paper and the result is 6; therefore, the result is correct. The only thing left is to calculate the derivatives of a function f(x,y), the derivatives of a function f(x,y,z) and the derivatives of a function f(x,y,z,w); I think I have to follow a similar approach (using functors, and using pointers within the function argument) to the approach used to calculate the integral of a function f(x,y,z,w), right?, Any suggestions?.

AFAIK, ROOT can only calculate 1-dimensional derivatives (i.e., for a “TF1”):
TF1::Derivative
TF1::Derivative2
TF1::Derivative3

For multi-dimensional functions, you may try to play with the “ROOT::Math::Derivator” class, but I know of no examples/tutorials/tests.

Ok, thanks for your reply. I’ll keep that in mind. So, I’ll keep trying to get those derivatives.

Hello, one option to draw a TF3 is the “gl” option. There is a tutorial here:

Otherwise, if given no further options you get iso surfaces like shown in the TF3 documentation:

or here:

1 Like

Hi. Thanks for all the information. It has been helpful. I could Draw with Root:

  1. the Klein bottle
  2. the function f = sin(x)*cos(y) + sin(y)*cos(z) + sin(z)*cos(x) shown in one of the macros you shared
  3. the function f = sin(x*x+y*y+z*z-36) shown in one of the macros you shared
  4. In the macro (one of the macros you shared) where the “gyroid“ function is defined, I defined the function f = x+y+z, and Root shows a plane. What I’m not sure about is whether it’s a three-dimensional plane or a hyperplane (a four-dimensional plane). What type of plane did Root make (after Draw(“FBBB”) is considered on the Root command line)?, A 3D plane or a 4D plane?. Below is the graph that Root makes:

What I’m not sure about is whether it’s a three-dimensional plane or a hyperplane (a four-dimensional plane). What type of plane did Root make (after Draw(“FBBB”) is considered on the Root command line)?, A 3D plane or a 4D plane?

In general, ROOT draws the isosurface where the function is equal to zero. It’s hard to see from this angle, but it certainly seems to cross (0, 0, 0) in the centre of this screenshot.

Ok, thanks for the reply. Below is the graph that Root makes, from different angles:

So, with the images above, Is it now possible to know if what is shown in the Root graph is a 3-dimensional plane or a 4-dimensional plane?