# Numerical integration with ROOT. (Function defined in points)

**URL:** <https://root-forum.cern.ch/t/numerical-integration-with-root-function-defined-in-points/24651>\
**Category:** ROOT\
**Created:** [May 5, 2017, 5:29am UTC](https://root-forum.cern.ch/t/numerical-integration-with-root-function-defined-in-points/24651 "2017-05-05T05:29:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![p73](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/p73/32/14141_2.png) [@p73](https://root-forum.cern.ch/u/p73)\
**Post date:** [May 5, 2017, 5:29am UTC](https://root-forum.cern.ch/t/numerical-integration-with-root-function-defined-in-points/24651/1 "2017-05-05T05:29:28Z")

</div>

What if I know my function I want to integrate only in some points. Does ROOT provide any integration method for this case?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [May 5, 2017, 7:17am UTC](https://root-forum.cern.ch/t/numerical-integration-with-root-function-defined-in-points/24651/2 "2017-05-05T07:17:23Z")

</div>

[https://root.cern/doc/master/classTGraph.html#a635997a6d81e4e89529aaf1819cf7533](https://root.cern/doc/master/classTGraph.html#a635997a6d81e4e89529aaf1819cf7533)

---

<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 5, 2017, 7:51am UTC](https://root-forum.cern.ch/t/numerical-integration-with-root-function-defined-in-points/24651/3 "2017-05-05T07:51:02Z")

</div>

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;
}`

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [May 19, 2017, 7:56am UTC](https://root-forum.cern.ch/t/numerical-integration-with-root-function-defined-in-points/24651/4 "2017-05-19T07:56:05Z")

</div>

Closed on May 19, 2017, 7:56am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
