# 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:** 1\
**Showing post:** 6

<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)”

---

_[View the full topic](https://root-forum.cern.ch/t/boundary-integral/17872)._
