Re: Fit Function again

From: Rene Brun (Rene.Brun@cern.ch)
Date: Fri Mar 07 1997 - 17:01:54 MET


Soeren Lange wrote:
> 
> > Soeren Lange wrote:
> > >
> > > how is it possible to fit with a user defined function?
> > >
> 
> ...
> 
> > > root [20] TF1 *f1 = new TF1("f1", "sin(x)", 0., 3.14);
> > > root [21] graph->Fit("f1");
> > > Illegal number of parameters = 0
> > >
> 
> ...
> 
> Rene Brun wrote:
> 
> > Look at the example:
> >      http://root.cern.ch/root/html/examples/multifit.C.html
> 
> I am sorry, but the example multifit.C is only using the predefined
> fit function "gaus" which of course is working.
> But how to fit with sin(x), cos(x), tan(x), ...?
> Neither "sin(x)" nor "sin" nor "sinu" (like expo) is accepted.

Soeren,
When you define a function to fit, you must somewhere specify
the parameter(s) to fit. In your example above, you have 0 parameters.
You can look at the class TFormula or TF1 to see how to define an
expression whih parameters. Look also at:

      http://root.cern.ch/root/html/examples/fillrandom.C.html

For example, if you want to create a function to be fitted with
two parameters involving sin(x):
  TF1 *f1 = new TF1("f1","[0]*sin([1]*x)",0,3.14);
  f1->SetParameter(0,1.1);  //initialize first parameter to 1.1
  f1->SetParameter(1,0.2);

  graph->Fit("f1");

In case of predefined functions, such as gaus, exp or polynomials,
root can automatically compute the initial values of parameters,
but not in the general case.

In case of the multifit macro, We compute initial values of
parameters by fitting simple expressions, then we fit a more
complex expression.

Rene Brun



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:26:18 MET