# How can I include a previously created variable in the definition of a TF1 function?

**URL:** <https://root-forum.cern.ch/t/how-can-i-include-a-previously-created-variable-in-the-definition-of-a-tf1-function/54839>\
**Category:** Newbie\
**Created:** [May 13, 2023, 9:42am UTC](https://root-forum.cern.ch/t/how-can-i-include-a-previously-created-variable-in-the-definition-of-a-tf1-function/54839 "2023-05-13T09:42:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![antares01](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/f07891/32.png) [@antares01](https://root-forum.cern.ch/u/antares01)\
**Post date:** [May 13, 2023, 9:42am UTC](https://root-forum.cern.ch/t/how-can-i-include-a-previously-created-variable-in-the-definition-of-a-tf1-function/54839/1 "2023-05-13T09:42:53Z")

</div>

Hi all!  
I want to make a fit on a TH1F histogram and the fitting function must be a linear combination of 3 normalized gaussians multiplied by a double variable (N in the example below) I’ve previously defined and calculated.  
So I tried something like:

```auto
double N;
//...calculate N...
auto *f1 = new TF1("f1", "N*(gausn(0) + gausn(3) + gausn(6))",93.,110.); 

```

but, during the execution, it compares an error message saying basically that it doesn’t recognize N.  
How can I solve this problem?  
Thank you a lot!

---

<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 13, 2023, 9:49am UTC](https://root-forum.cern.ch/t/how-can-i-include-a-previously-created-variable-in-the-definition-of-a-tf1-function/54839/2 "2023-05-13T09:49:54Z")

</div>

`TF1 *f1 = new TF1("f1", TString::Format("%.17g * (gausn(0) + gausn(3) + gausn(6))", N), 93., 110.);`

---

<div class="post-metadata">

**Author:** ![antares01](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/f07891/32.png) [@antares01](https://root-forum.cern.ch/u/antares01)\
**Post date:** [May 13, 2023, 9:54am UTC](https://root-forum.cern.ch/t/how-can-i-include-a-previously-created-variable-in-the-definition-of-a-tf1-function/54839/3 "2023-05-13T09:54:00Z")

</div>

It worked very well! Thank you very much!
