# Integral of 2D function

**URL:** <https://root-forum.cern.ch/t/integral-of-2d-function/15146>\
**Category:** ROOT\
**Created:** [October 25, 2012, 6:50pm UTC](https://root-forum.cern.ch/t/integral-of-2d-function/15146 "2012-10-25T18:50:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![franciuska](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/b9e5f3/32.png) [@franciuska](https://root-forum.cern.ch/u/franciuska)\
**Post date:** [October 25, 2012, 6:50pm UTC](https://root-forum.cern.ch/t/integral-of-2d-function/15146/1 "2012-10-25T18:50:03Z")

</div>

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](https://root-forum.cern.ch/uploads/default/original/2X/8/8bddcd528d6b61efbe02bcabf13132d4e8b37b83.c) (2.81 KB)

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [October 25, 2012, 7:50pm UTC](https://root-forum.cern.ch/t/integral-of-2d-function/15146/2 "2012-10-25T19:50:04Z")

</div>

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](http://root.cern.ch/root/html/TF1.html#TF1:FixParameter) use simply [SetParameter](http://root.cern.ch/root/html/TFormula.html#TFormula:SetParameter@1).

---

<div class="post-metadata">

**Author:** ![franciuska](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/b9e5f3/32.png) [@franciuska](https://root-forum.cern.ch/u/franciuska)\
**Post date:** [October 25, 2012, 8:01pm UTC](https://root-forum.cern.ch/t/integral-of-2d-function/15146/3 "2012-10-25T20:01:55Z")

</div>

Hi.  
Thank you a lot!

Fra
