# How to specify the initial values for the parameters

**URL:** <https://root-forum.cern.ch/t/how-to-specify-the-initial-values-for-the-parameters/35230>\
**Category:** Newbie\
**Created:** [July 17, 2019, 2:43am UTC](https://root-forum.cern.ch/t/how-to-specify-the-initial-values-for-the-parameters/35230 "2019-07-17T02:43:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DANTE0316](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/e79b87/32.png) [@DANTE0316](https://root-forum.cern.ch/u/DANTE0316)\
**Post date:** [July 17, 2019, 2:43am UTC](https://root-forum.cern.ch/t/how-to-specify-the-initial-values-for-the-parameters/35230/1 "2019-07-17T02:43:40Z")

</div>

Hi all，I am facing the following problem：How to initialize parameters when fitting functions with Chi2 Fits？Whether the initial value is arbitrarily given？But I don’t know anything about the range of initial values.

Thank you in advance！

---

<div class="post-metadata">

**Author:** ![vpadulan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/vpadulan/32/25315_2.png) [@vpadulan](https://root-forum.cern.ch/u/vpadulan)\
**Post date:** [July 17, 2019, 7:04am UTC](https://root-forum.cern.ch/t/how-to-specify-the-initial-values-for-the-parameters/35230/2 "2019-07-17T07:04:02Z")

</div>

Hi @DANTE0316,  
I would point you to the [users’ guide for fitting histograms](https://root.cern.ch/root/htmldoc/guides/users-guide/FittingHistograms.html), in particular section 7.2.2.2 Creating a TF1 with Parameters explains how to set the initial values for the parameters of the fitting function. Let me know if this helps you.  
Best,  
Vincenzo

---

<div class="post-metadata">

**Author:** ![DANTE0316](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/e79b87/32.png) [@DANTE0316](https://root-forum.cern.ch/u/DANTE0316)\
**Post date:** [July 17, 2019, 8:47am UTC](https://root-forum.cern.ch/t/how-to-specify-the-initial-values-for-the-parameters/35230/3 "2019-07-17T08:47:00Z")

</div>

Oh，I see，thank you Vincenzo！I do have one more question though，I know how to set the initial values for the parameters of the fitting function now 。This is my code:

```auto
TF1 *f1 = new TF1("f1","[0]*(((x+[1]*exp(-[2]*x*x)+[3]*exp(-[4]*x*x)+[5]+[6]*pow(1*x*x,[7]))*(x+[1]*exp(-[2]*x*x)+[3]*exp(-[4]*x*x)+[5]+[6]*pow(1*x*x,[7])))*exp(-(x+[1]*exp(-[2]*x*x)+[3]*exp(-[4]*x*x)+[5]+[6]*pow(1*x*x,[7]))/([8]+[9]*TMath::Log(1*x*x)+[10]*TMath::Log(1*x*x)*TMath::Log(1*x*x)+[11]*pow(1*x*x,[12])))/(2*([8]+[9]*TMath::Log(1*x*x)+[10]*TMath::Log(1*x*x)*TMath::Log(1*x*x)+[11]*pow(1*x*x,[12]))*([8]+[9]*TMath::Log(1*x*x)+[10]*TMath::Log(1*x*x)*TMath::Log(1*x*x)+[11]*pow(1*x*x,[12]))*([8]+[9]*TMath::Log(1*x*x)+[10]*TMath::Log(1*x*x)*TMath::Log(1*x*x)+[11]*pow(1*x*x,[12]))) +(([13]*exp(-[14]*x*x)+[15]*exp(-[16]*x*x)+[17]+[18]*pow(1*x*x,[19]))*1) *(([21]*exp(-(([22]*exp(-[23]*x*x)+[24]*exp(-[25]*x*x)+[26]+[27]*pow(1*x*x,[28]))*[29])*(x+[30])))+([31]*exp(-(([32]*exp(-[33]*x*x)+[34]*exp(-[35]*x*x)+[36]+[37]*pow(1*x*x,[38]))*[39])*(x+[30])))))",0,4500);

```

I don’t know anything about the range of 40 initial values,what should I do？Arbitrarily setting or other method？

---

<div class="post-metadata">

**Author:** ![vpadulan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/vpadulan/32/25315_2.png) [@vpadulan](https://root-forum.cern.ch/u/vpadulan)\
**Post date:** [July 17, 2019, 8:58am UTC](https://root-forum.cern.ch/t/how-to-specify-the-initial-values-for-the-parameters/35230/4 "2019-07-17T08:58:33Z")

</div>

Hi @DANTE0316,  
The suggested way to go is that you should set the initial values of the parameters to their best estimate available. Then you can use `SetParLimits` to fix a value range in which the parameter can vary, otherwise it would be able to vary freely. This is explained in section _7.3.1 Fixing and Setting Parameters’ Bounds_ of the fitting guide I linked previously.  
Best,  
Vincenzo

---

<div class="post-metadata">

**Author:** ![DANTE0316](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/e79b87/32.png) [@DANTE0316](https://root-forum.cern.ch/u/DANTE0316)\
**Post date:** [July 17, 2019, 12:33pm UTC](https://root-forum.cern.ch/t/how-to-specify-the-initial-values-for-the-parameters/35230/5 "2019-07-17T12:33:42Z")

</div>

I see.Thank you very much!
