# User-defined function with numbering of parameters

**URL:** <https://root-forum.cern.ch/t/user-defined-function-with-numbering-of-parameters/61588>\
**Category:** Newbie\
**Created:** [September 6, 2024, 12:17pm UTC](https://root-forum.cern.ch/t/user-defined-function-with-numbering-of-parameters/61588 "2024-09-06T12:17:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Natalia\_D](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/f04885/32.png) [@Natalia\_D](https://root-forum.cern.ch/u/Natalia_D)\
**Post date:** [September 6, 2024, 12:17pm UTC](https://root-forum.cern.ch/t/user-defined-function-with-numbering-of-parameters/61588/1 "2024-09-06T12:17:07Z")

</div>

Good afternoon!

I would like to define a composite function similar to

```auto
TF1 *f = new TF1("f", "gausn(0) + gausn(3)");

```

but with own functions instead of `gausn`-s.

I have defined a custom function,

```auto
double test_fun(double *x, double *p){
    return p[0] * log(*x + p[1]) * exp(p[2] * (*x));
}

```

and I want to define a new function as

```auto
TF1 *f1 = new TF1("f1", "test_fun(0) + test_fun(3)", 0.2, 5.2, 6);

```

Is it possible to do so?  
And if so, how?

Best regards,  
Natalia

---

<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:** [September 6, 2024, 12:38pm UTC](https://root-forum.cern.ch/t/user-defined-function-with-numbering-of-parameters/61588/2 "2024-09-06T12:38:32Z")

</div>

I guess @moneta can help you

---

<div class="post-metadata">

**Author:** ![Natalia\_D](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/f04885/32.png) [@Natalia\_D](https://root-forum.cern.ch/u/Natalia_D)\
**Post date:** [September 13, 2024, 7:03am UTC](https://root-forum.cern.ch/t/user-defined-function-with-numbering-of-parameters/61588/3 "2024-09-13T07:03:17Z")

</div>

Does @moneta know about this, or I have somehow connect him?

---

<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:** [September 13, 2024, 7:10am UTC](https://root-forum.cern.ch/t/user-defined-function-with-numbering-of-parameters/61588/4 "2024-09-13T07:10:45Z")

</div>

No, you do not need to connect to him. just mentioning @moneta in a post is enough

---

<div class="post-metadata">

**Author:** ![mczurylo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mczurylo/32/33269_2.png) [@mczurylo](https://root-forum.cern.ch/u/mczurylo)\
**Post date:** [September 13, 2024, 8:04am UTC](https://root-forum.cern.ch/t/user-defined-function-with-numbering-of-parameters/61588/5 "2024-09-13T08:04:01Z")

</div>

Hi @Natalia_D,

your question seems similar to this exercise: [student-course/course/exercises/core/fitting-exercise.ipynb at main · root-project/student-course · GitHub](https://github.com/root-project/student-course/blob/main/course/exercises/core/fitting-exercise.ipynb)

If you’re new to ROOT in general, I recommend that you go through the whole course: [GitHub - root-project/student-course: ROOT course for students](https://github.com/root-project/student-course/tree/main) - there is a section dedicated to functions and fitting as well, you can also watch the recording of the course and follow the material along with it: [ROOT Summer Student Course 2024 · CDS Videos · CERN](https://videos.cern.ch/record/2300516)

Cheers,  
Marta
