%%cpp -d #include "TGraphErrors.h" #include "TF1.h" #include "TRandom.h" #include "TCanvas.h" #include "TLegend.h" #include "TMath.h" void makePoints(int n, double *x, double *y, double *e, int p); %%cpp -d void makePoints(int n, double *x, double *y, double *e, int p) { int i; TRandom r; if (p==2) { for (i=0; iSetGrid(); makePoints(n, x, y, e, 3); TGraphErrors *gre3 = new TGraphErrors(n, x, y, nullptr, e); gre3->Draw("a*"); gre3->Fit("pol3"); TF1 *f3 = gre3->GetFunction("pol3"); f3->SetLineWidth(1); makePoints(n, x, y, e, 2); TGraphErrors *gre2=new TGraphErrors(n, x, y, nullptr, e); gre2->Draw("*same"); gre2->SetMarkerColor(kBlue); gre2->SetLineColor(kBlue); TF1 *f2 = new TF1("f2", "sin(x) ++ sin(2*x)", -2, 2); gre2->Fit(f2); f2 = gre2->GetFunction("f2"); f2->SetLineColor(kBlue); f2->SetLineWidth(1); makePoints(n, x, y, e, 4); TGraphErrors *gre4=new TGraphErrors(n, x, y, nullptr, e); gre4->Draw("*same"); gre4->SetMarkerColor(kRed); gre4->SetLineColor(kRed); gre4->Fit("1 ++ exp(-x)"); TF1 *f4 = gre4->GetFunction("1 ++ exp(-x)"); f4->SetName("f4"); f4->SetLineColor(kRed); f4->SetLineWidth(1); TLegend *leg = new TLegend(0.3, 0.7, 0.65, 0.9); leg->AddEntry(gre3, " -7 + 2*x*x + x*x*x", "p"); leg->AddEntry(gre2, "sin(x) + sin(2*x)", "p"); leg->AddEntry(gre4, "-2 + exp(-x)", "p"); leg->Draw(); %jsroot on gROOT->GetListOfCanvases()->Draw()