# Boundary integral

**URL:** <https://root-forum.cern.ch/t/boundary-integral/17872>\
**Category:** ROOT\
**Created:** [July 4, 2014, 8:16pm UTC](https://root-forum.cern.ch/t/boundary-integral/17872 "2014-07-04T20:16:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mutu53](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@mutu53](https://root-forum.cern.ch/u/mutu53)\
**Post date:** [July 4, 2014, 8:16pm UTC](https://root-forum.cern.ch/t/boundary-integral/17872/1 "2014-07-04T20:16:30Z")

</div>

I want to integrate two dimensional [function.it](http://function.it) is easy when boundary is constant.I mean boundary is number.How can ı calculate when boundary is variable…  
Example f(x,y)=x\*y^2  
boundary x change y to 1 and boundary y change 0 to 1.

Can anybody help me?

---

<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:** [July 4, 2014, 8:33pm UTC](https://root-forum.cern.ch/t/boundary-integral/17872/2 "2014-07-04T20:33:15Z")

</div>

Well, a “brutal fix” would be to redefine your function:  
`if (x >= y) return f(x, y); else return 0;`  
and then integrate it from 0 to 1 in both dimensions (i.e. in a 2D rectangular region).  
Some warnings: [Creating TF1 from TGraph - #10 by Pepe\_Le\_Pew](https://root-forum.cern.ch/t/creating-tf1-from-tgraph/10522/10) and [Convolution of two TF1 - #8 by Pepe\_Le\_Pew](https://root-forum.cern.ch/t/convolution-of-two-tf1/23625/8)

BTW. Note that there’s a special “[Stat and Math Tool Support](http://root.cern.ch/phpBB3/viewforum.php?f=15)” forum here.

---

<div class="post-metadata">

**Author:** ![mutu53](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@mutu53](https://root-forum.cern.ch/u/mutu53)\
**Post date:** [July 4, 2014, 9:01pm UTC](https://root-forum.cern.ch/t/boundary-integral/17872/3 "2014-07-04T21:01:03Z")

</div>

Thank you for your reply…I dont know what is brutal fix mean.This is my code.but here the boundary x change from 0 to 1 and there is no problem.How can ı change my code when boundary x change y to 1.

```cpp
double f2(const double *x) {
return x[0]*x[1];
} 

void deneme()
{
ROOT::Math::Functor wf(&f2,2);
double a[2] = {0,0};
double b[2] = {1,1};
  ROOT::Math::IntegratorMultiDim ig(ROOT::Math::IntegrationMultiDim::kADAPTIVE); 
  ig.SetFunction(wf);
double val = ig.Integral(a,b);
   std::cout << "integral result is " << val << std::endl;

}

```

---

<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:** [July 4, 2014, 9:07pm UTC](https://root-forum.cern.ch/t/boundary-integral/17872/4 "2014-07-04T21:07:15Z")

</div>

```cpp
double f2(const double *x) {
  if (x[0] >= x[1]) return (x[0] * x[1]);
  return 0; // out of boundaries
}

```

```cpp
double f2(const double *x) {
  if (x[0] < x[1]) return 0; // out of boundaries
  return (x[0] * x[1]);
}

```

---

<div class="post-metadata">

**Author:** ![mutu53](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@mutu53](https://root-forum.cern.ch/u/mutu53)\
**Post date:** [July 4, 2014, 9:21pm UTC](https://root-forum.cern.ch/t/boundary-integral/17872/5 "2014-07-04T21:21:25Z")

</div>

thank yo so much.I dont understand but it works…

---

<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:** [July 7, 2014, 4:57pm UTC](https://root-forum.cern.ch/t/boundary-integral/17872/6 "2014-07-07T16:57:46Z")

</div>

Here’s the “proper solution”:

```cpp
// Problem: integrate a two dimensional function "f(x,y)" using limits:
// "y" from 0 to 1 and "x" from "y" to 1.
// Solution: change the variable "x:[y, 1]" -> "t:[0, 1]" and
// then the integration goes from 0 to 1 in both dimensions.
// So "x = (1 - y) * t + y" and "dx/dt = (1 - y)".
// See also:
// http://en.wikipedia.org/wiki/Integration_by_substitution
// http://en.wikipedia.org/wiki/Multiple_integral#Change_of_variables
//
double f2(const double *X)
{
  double f = 0.0;
  double t = X[0]; // "t" (i.e. the original "x")
  double y = X[1]; // "y"
  double x = (1.0 - y) * t + y; // calculate new "x"
  
  // calculate the original function "f(x,y)"
  f = x * y; // f(x,y) = x * y
  // f = x * y * y; // f(x,y) = x * y^2
  
  f *= (1.0 - y); // multiply the result by "dx/dt"
  return f;
}

```

Just for reference: “[Non-rectangular region integration](https://root-forum.cern.ch/t/non-rectangular-region-integration/23765)”

---

<div class="post-metadata">

**Author:** ![mutu53](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@mutu53](https://root-forum.cern.ch/u/mutu53)\
**Post date:** [July 7, 2014, 10:15pm UTC](https://root-forum.cern.ch/t/boundary-integral/17872/7 "2014-07-07T22:15:53Z")

</div>

oo excellent…I understood …I can solve my complex integral now:) Thank you very much for your great explanation.
