Dear all,

I am trying to integrate a 2D function.

The function is given in cartesian coordinates, but should be integrated within a certain radius.

Therefore the function is defined in such a way that it results equal to 0 for

(x-x0)^2+(y-y0)^2>r, whith a chosen r.

Then the function is integrated between (-0.5, 0.5,-0.5,0.5), i.e. over a square domain.

But in this case the obtained integral is 0.

The routine is in attachment.

Could someone tell me what do I make wrong, please?

Thanks,

regards,

Francesca

test.c (2.81 KB)

A very brutal fix (works just in this case; in another cases you’ll need to “tune” the “number of points”):

g2D1->SetNpx(700); g2D1->SetNpy(700); // “number of points” >= 700

I guess the problem is that your “g2dBIF1” is not smooth at the “edge” given by the “radius” (i.e. it’s not differentiable there) and the “numerical integrator” gets fooled (there’s a “jump” from about 8000 to 0).

That’s not a problem for your “g2dBIF2” because the “radius” is much larger and the “jump” at the “edge” is quite small.

However, the proper solution would be defining another function of two variables: “radius” and “angle” (and then integrate it from “radius” 0 to some_radius_max and from “angle” 0 to 2 pi).

BTW. Instead of FixParameter use simply SetParameter.