# How to use two given vectors of numbers rather than a formula such as "sin(x)"

**URL:** <https://root-forum.cern.ch/t/how-to-use-two-given-vectors-of-numbers-rather-than-a-formula-such-as-sin-x/51144>\
**Category:** Newbie\
**Tags:** root\
**Created:** [August 10, 2022, 4:12pm UTC](https://root-forum.cern.ch/t/how-to-use-two-given-vectors-of-numbers-rather-than-a-formula-such-as-sin-x/51144 "2022-08-10T16:12:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jerome\_Kunegis](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jerome_kunegis/32/30549_2.png) [@Jerome\_Kunegis](https://root-forum.cern.ch/u/Jerome_Kunegis)\
**Post date:** [August 10, 2022, 4:12pm UTC](https://root-forum.cern.ch/t/how-to-use-two-given-vectors-of-numbers-rather-than-a-formula-such-as-sin-x/51144/1 "2022-08-10T16:12:04Z")

</div>

I’m following the tutorial and have this, which works (I’m compiling it, and then running it – no interactivity):

```auto
	TCanvas c("c", title.c_str(), 0, 0, width, height);
	TF1 f1("f1","sin(x)", -5, 5);
	f1.SetTitle(title.c_str());
	f1.Draw();
	c.Print("plot/all.pdf");

```

Now, instead of passing an expression like “sin(x)” I want to pass two vectors declared as  
`vector <double> x, y;`. How do I do that?

I’m sorry, I’m new to ROOT and couldn’t find a solution in the tutorial/documentation.

Best regards  
Jérôme

* * *

_ROOT Version:_ 6.26/06  
_Platform:_ Ubuntu 18.04  
_Compiler:_ g++ (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0

* * *

---

<div class="post-metadata">

**Author:** ![FoxWise](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/foxwise/32/37588_2.png) [@FoxWise](https://root-forum.cern.ch/u/FoxWise)\
**Post date:** [August 10, 2022, 4:18pm UTC](https://root-forum.cern.ch/t/how-to-use-two-given-vectors-of-numbers-rather-than-a-formula-such-as-sin-x/51144/2 "2022-08-10T16:18:26Z")

</div>

Hi Jérôme,

Welcome to the forum 🙂

If you want to make a plot using predefined data points, instead of mathematical formula, I would use `TGraph` instead of `TF1`.

```cpp
        TCanvas c("c", title.c_str(), 0, 0, width, height);
        std::vector <double> x {1., 2., 3., 4., 5.};
        std::vector <double> y {1., 4., 9., 16., 25.};
        TGraph gr(x.size(), &x[0], &y[0]);
	    gr.Draw("APL");
        gr.SetMarkerStyle(20);
	    c.Print("plot/all.pdf");

```

---

<div class="post-metadata">

**Author:** ![Jerome\_Kunegis](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jerome_kunegis/32/30549_2.png) [@Jerome\_Kunegis](https://root-forum.cern.ch/u/Jerome_Kunegis)\
**Post date:** [August 10, 2022, 4:29pm UTC](https://root-forum.cern.ch/t/how-to-use-two-given-vectors-of-numbers-rather-than-a-formula-such-as-sin-x/51144/3 "2022-08-10T16:29:31Z")

</div>

Cheers! That’s exactly what I was looking for
