# Use graph-\>Integral() encouter problem

**URL:** <https://root-forum.cern.ch/t/use-graph-integral-encouter-problem/38964>\
**Category:** ROOT\
**Tags:** graphics, hist\
**Created:** [April 18, 2020, 12:22pm UTC](https://root-forum.cern.ch/t/use-graph-integral-encouter-problem/38964 "2020-04-18T12:22:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![renqipan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/renqipan/32/22738_2.png) [@renqipan](https://root-forum.cern.ch/u/renqipan)\
**Post date:** [April 18, 2020, 12:22pm UTC](https://root-forum.cern.ch/t/use-graph-integral-encouter-problem/38964/1 "2020-04-18T12:22:51Z")

</div>

Hi experts,  
I met an incredible problem when use graph-\>Integral(). I integrate a graph from the first point to the third point using graph-\>Integral(0,2), then it return a value 0 but it should have not be zero. I have outputed the first, second and third point and find they are all larger than zero, so the integral should not be zero. the code I wrote and parts of output are given below. Hope you can help me resolve the problem. thank you.

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/2/b/2b7cc168c7e3219bd421bde3ad4fc3ee0591d62a.png)

output:  
0.0839837 0.141478 0.198973  
xstart:0 xend:2 Integral: 4.44089e-16  
340 0.0839837  
350 0.141478  
360 0.198973  
370 0.256467  
380 0.313961  
390 0.286965  
400 0.259969

---

<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:** [April 18, 2020, 2:29pm UTC](https://root-forum.cern.ch/t/use-graph-integral-encouter-problem/38964/2 "2020-04-18T14:29:12Z")

</div>

[TGraph::Integral](https://root.cern/doc/master/classTGraph.html#a06b6dfc69d4fe9336ade71a47864f974)

---

<div class="post-metadata">

**Author:** ![renqipan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/renqipan/32/22738_2.png) [@renqipan](https://root-forum.cern.ch/u/renqipan)\
**Post date:** [April 18, 2020, 2:47pm UTC](https://root-forum.cern.ch/t/use-graph-integral-encouter-problem/38964/3 "2020-04-18T14:47:11Z")

</div>

I am using this function. it has problem.

---

<div class="post-metadata">

**Author:** ![renqipan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/renqipan/32/22738_2.png) [@renqipan](https://root-forum.cern.ch/u/renqipan)\
**Post date:** [April 19, 2020, 2:47am UTC](https://root-forum.cern.ch/t/use-graph-integral-encouter-problem/38964/5 "2020-04-19T02:47:31Z")

</div>

Thank you Wile,  
Now I realized that this function computes the area of the polygon enclosed by the points of the graph. This is not the function I wanna. I wanna integrate the graph from xlow to xup. Would you mind telling me how can I make it?

---

<div class="post-metadata">

**Author:** ![renqipan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/renqipan/32/22738_2.png) [@renqipan](https://root-forum.cern.ch/u/renqipan)\
**Post date:** [April 19, 2020, 3:37am UTC](https://root-forum.cern.ch/t/use-graph-integral-encouter-problem/38964/6 "2020-04-19T03:37:17Z")

</div>

I found an example for calculating the area under the graph.

```cpp
double x[] = { 1,2,3,4,5,6,7,8,9,10};
double y[] = { 1,2,3,4,5,6,7,8,9,10}; 
TGraph g(10,x,y);
TF1 f1("f",[&](double *x, double *){ return g.Eval(x[0]); },1,10,0);
double integral = f1.Integral(1,10);

```

cite: [Integral of TGraph](https://root-forum.cern.ch/t/integral-of-tgraph/4745/12)

---

<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 3, 2020, 3:37am UTC](https://root-forum.cern.ch/t/use-graph-integral-encouter-problem/38964/7 "2020-05-03T03:37:19Z")

</div>

Closed on May 3, 2020, 3:37am UTC

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