{ // Header gROOT->Reset(); gROOT->SetStyle("Plain"); #include "Riostream.h"; // Arrays Int_t lines = 23; Double_t x[lines], y0[lines], y1[lines]; Double_t xErr[lines], y0Err[lines], y1Err[lines]; Double_t xError = 0.1, y0Error = 0.001, y1Error = 0.001; // Daten einlesen ifstream in; in.open("nicht-lin_neu.txt"); Int_t n=0; while (1) { in >> x[n] >> y0[n] >> y1[n]; x[n]=x[n]*1000; xErr[n]=xError*1000; y0[n] = (y0[n]/2) - (y1[n]/2); y0Err[n] = sqrt( (y0Error**2)/4 + (y1Error**2)/4 ); cout << x[n] << " <--> " << y0[n] << " <--> " << y1[n] << endl; if(!in.good()) break; n++; } in.close(); cout << "n = " << n << endl; // Canvas & Style c1 = new TCanvas("c1","Canvas",1); c1->SetGrid(); gStyle->SetOptFit(); // Graphen gr = new TGraphErrors(n,x,y0,xErr,y0Err); gr->SetTitle("Resonanzkurve linearer Schwingkreises"); gr->GetYaxis()->SetTitle("U / U_{treib}"); gr->GetXaxis()->SetTitle("f / Hz"); gr->GetYaxis()->CenterTitle(1); gr->SetMarkerStyle(1); //Funktionen //TF1 *fitfunc = new TF1("fitfunc", "10 * [0] / (sqrt( ([0] - x**2)**2 + ([1]**2) * (x**2) ) )",1.5e5,3e5); TF1 *fitfunc = new TF1("fitfunc", "[0]+10*[1]/(sqrt(([1]-x**2)**2+[2]**2*x**2))",1.5e5,3e5); fitfunc->SetParameters(-5,2.344e8,1500); //fitfunc->SetParameters(-5,9e8,0.2); //fitfunc->SetParameters(-0.04,1.95e9,1.55e6); //fitfunc->SetParameters(-0.5,1.165e9,5e3); //fitfunc->SetParameters(2.344e6,3000); //fitfunc->SetParLimits(0,-10,-1); //fitfunc->SetParLimits(1,1e5,1e10); //fitfunc->SetParLimits(1,9e8,9e8); //fitfunc->SetParLimits(2,1e3,1e8); //fitfunc->SetParLimits(2,0,0.5); gr->Fit("fitfunc","R"); gr->Draw("AP"); Double_t chi_red = fitfunc->GetChisquare() / fitfunc->GetNDF(); cout << "Chi-Square = " << chi_red << endl; }