# Fitting discrete datapoints with user-defined function

Hello!
Here’s my little macro with the questions included in the beginning:

{

``````/*

This file is supposed to plot a series of discrete measured values of pressure over time
and to calculate a user-defined fitting function which should look like
p(t) = c0 + c1 * (1-exp(-c2*t)).

My questions are:

1) Is the histogramm-mechanism the appropriate way to plot the data, because i seems to me
that all the unfilled time-values (are they empty bins?) are interpreted as zero and therefore
disturb all further calculations perfomed on the dataset?

2) I have searched in the tutorial files for a couple of hours by now, but could not find a way to
implement the user-defined fitting function in the ROOT interpreter mode. All examples seem to
use the compiler mode which i haven't been able to operate up to now. So is there a simple way to
perform user-defined fits in the interpreter mode?

*/

gROOT->Reset();

TH1F *h1 = new TH1F("h1","outgasing",60,0,60);

float time [17] = {0,1,2,3,4,5,7,9,10,12,14,19,24,29,39,49,59}; // timescale in seconds //
float pressure[17]= {1.10E-10,3.00E-9,8.40E-9,1.10E-8,1.50E-8,  // corresponding pressure values //
1.76E-8,2.18E-8,2.54E-8,2.72E-8,2.96E-8,
3.16E-8,3.56E-8,3.86E-8,4.10E-8,4.44E-8,
4.71E-8,4.94E-8};
int x;

for (x=0 ; x<17 ; x++)
{
h1->Fill(time[x],pressure[x]);
}

h1->Draw("AC*");
``````

}

Regards,
Udo

see example in attachement. See more examples in the Users Guide and the tutorials

Rene

void pressure() {
float time [17] = {0,1,2,3,4,5,7,9,10,12,14,19,24,29,39,49,59}; // timescale
in seconds //
float pressure[17]= {1.10E-10,3.00E-9,8.40E-9,1.10E-8,1.50E-8, // correspondi
ng pressure values //
1.76E-8,2.18E-8,2.54E-8,2.72E-8,2.96E-8,
3.16E-8,3.56E-8,3.86E-8,4.10E-8,4.44E-8,
4.71E-8,4.94E-8};
TGraph *gr = new TGraph(17,time,pressure);
gr->SetMarkerStyle(21);
gr->Fit(“pol6”);
gr->Draw(“alp”);
}