00001
00002
00003
00004 #include "TMath.h"
00005 #include "TCanvas.h"
00006 #include "TF1.h"
00007 #include "TLegend.h"
00008
00009 void mathLaplace(){
00010 TCanvas *c1=new TCanvas("c1", "TMath::LaplaceDist",600,800);
00011 c1->Divide(1, 2);
00012 TVirtualPad *pad1 = c1->cd(1);
00013 pad1->SetGrid();
00014 TF1 *flaplace = new TF1("flaplace", "TMath::LaplaceDist(x, [0], [1])", -10, 10);
00015 flaplace->SetParameters(0, 1);
00016 TF1 *f1 = flaplace->DrawCopy();
00017 f1->SetLineColor(kRed);
00018 f1->SetLineWidth(1);
00019 flaplace->SetParameters(0, 2);
00020 TF1 *f2 = flaplace->DrawCopy("same");
00021 f2->SetLineColor(kGreen);
00022 f2->SetLineWidth(1);
00023 flaplace->SetParameters(2, 1);
00024 TF1 *f3 = flaplace->DrawCopy("same");
00025 f3->SetLineColor(kBlue);
00026 f3->SetLineWidth(1);
00027 flaplace->SetParameters(2, 2);
00028 TF1 *f4 = flaplace->DrawCopy("same");
00029 f4->SetLineColor(kMagenta);
00030 f4->SetLineWidth(1);
00031 TLegend *legend1 = new TLegend(.7,.7,.9,.9);
00032 legend1->AddEntry(f1,"alpha=0 beta=1","l");
00033 legend1->AddEntry(f2,"alpha=0 beta=2","l");
00034 legend1->AddEntry(f3,"alpha=2 beta=1","l");
00035 legend1->AddEntry(f4,"alpha=2 beta=2","l");
00036 legend1->Draw();
00037
00038 TVirtualPad *pad2 = c1->cd(2);
00039 pad2->SetGrid();
00040 TF1 *flaplacei=new TF1("flaplacei", "TMath::LaplaceDistI(x, [0], [1])", -10, 10);
00041 flaplacei->SetParameters(0, 1);
00042 TF1 *g1=flaplacei->DrawCopy();
00043 g1->SetLineColor(kRed);
00044 g1->SetLineWidth(1);
00045 flaplacei->SetParameters(0, 2);
00046 TF1 *g2=flaplacei->DrawCopy("same");
00047 g2->SetLineColor(kGreen);
00048 g2->SetLineWidth(1);
00049 flaplacei->SetParameters(2, 1);
00050 TF1 *g3=flaplacei->DrawCopy("same");
00051 g3->SetLineColor(kBlue);
00052 g3->SetLineWidth(1);
00053 flaplacei->SetParameters(2, 2);
00054 TF1 *g4=flaplacei->DrawCopy("same");
00055 g4->SetLineColor(kMagenta);
00056 g4->SetLineWidth(1);
00057
00058 TLegend *legend2 = new TLegend(.7,.15,0.9,.35);
00059 legend2->AddEntry(f1,"alpha=0 beta=1","l");
00060 legend2->AddEntry(f2,"alpha=0 beta=2","l");
00061 legend2->AddEntry(f3,"alpha=2 beta=1","l");
00062 legend2->AddEntry(f4,"alpha=2 beta=2","l");
00063 legend2->Draw();
00064 c1->cd();
00065 }