# How does TGraph::Eval() find interpolation points and how fast is it?

**URL:** <https://root-forum.cern.ch/t/how-does-tgraph-eval-find-interpolation-points-and-how-fast-is-it/38825>\
**Category:** Newbie\
**Created:** [April 10, 2020, 10:42pm UTC](https://root-forum.cern.ch/t/how-does-tgraph-eval-find-interpolation-points-and-how-fast-is-it/38825 "2020-04-10T22:42:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nyx](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/dc4da7/32.png) [@Nyx](https://root-forum.cern.ch/u/Nyx)\
**Post date:** [April 10, 2020, 10:42pm UTC](https://root-forum.cern.ch/t/how-does-tgraph-eval-find-interpolation-points-and-how-fast-is-it/38825/1 "2020-04-10T22:42:12Z")

</div>

Let’s say I have 2 arrays (set of coordinates):

```auto
x[]={x0,...,xN}
y[]={y0,....,yN}

```

If I want to know some `y(x)` I can just calculate the linear interpolation between some points of the array. `x` is the position of moving particle, so it increases with time. I can keep track of the lower and upper values of `x[]` for the linear interpolation, and find `y(x)` easily. However, it’s just tedious to have those lines of code in my script checking lower and upper values all the time.

I thought of doing this defining a TGraph object with `x[]` and `y[]`, so I can just use `TGraph::Eval(x)`. I’d like to know how this function finds the lower and upper values for `x` and if this significantly slower for large `N`

---

<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:** [April 14, 2020, 8:58am UTC](https://root-forum.cern.ch/t/how-does-tgraph-eval-find-interpolation-points-and-how-fast-is-it/38825/2 "2020-04-14T08:58:31Z")

</div>

See the reference guide for [TGraph::Eval()](https://root.cern/doc/master/classTGraph.html#ab33753b0102ae87f91274cf277baa39b)  
You can even look at [the code](https://root.cern/doc/master/TGraph_8cxx_source.html#l00869).
