# Sum of TGraph integrals

**URL:** <https://root-forum.cern.ch/t/sum-of-tgraph-integrals/29095>\
**Category:** ROOT\
**Created:** [May 22, 2018, 7:15pm UTC](https://root-forum.cern.ch/t/sum-of-tgraph-integrals/29095 "2018-05-22T19:15:06Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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:** [May 23, 2018, 7:29am UTC](https://root-forum.cern.ch/t/sum-of-tgraph-integrals/29095/3 "2018-05-23T07:29:17Z")

</div>

> [@Numerical integration with ROOT. (Function defined in points)](https://root-forum.cern.ch/t/numerical-integration-with-root-function-defined-in-points/24651/3):
>
> Be aware that the [TGraph::Integral](https://root.cern/doc/master/classTGraph.html#a635997a6d81e4e89529aaf1819cf7533) name is extremely misleading. It calculates the “pseudo-integral” of a closed polygon, NOT the “integral” of the function. Try this: { TGraph \*g = new TGraph(); g-\>SetPoint(0, 1.0, 1.0); g-\>SetPoint(1, 2.0, 0.0); g-\>SetPoint(2, 3.0, 2.0); g-\>SetPoint(3, 4.0, 1.0); g-\>Draw("AL\*"); std::cout \<\< "ROOT's pseudo-integral = " \<\< g-\>Integral(0, 3) \<\< std::endl; }

> [@Plotting the differences between two graphs](https://root-forum.cern.ch/t/plotting-the-differences-between-two-graphs/29009/4):
>
> Note that the solution proposed by Olivier assumes that both graphs have exactly the same numbers of points and that their X coordinates are exactly the same (for all points). If any of the above conditions is not met, try: { // Note: this macro needs ROOT 6 // define some variables used below Double\_t x[100], y[100]; Int\_t n; // create the first graph n = 22; for (Int\_t i = 0; i \< n; i++) { x[i] = i \* TMath::Pi() / (n - 1.); y[i] = TMath::Sin(x[i]); } TGraph \*g…

---

_[View the full topic](https://root-forum.cern.ch/t/sum-of-tgraph-integrals/29095)._
