Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Legendre.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_math
3/// \notebook
4/// Example of first few Legendre Polynomials.
5///
6/// Draws a graph.
7///
8/// \macro_image
9/// \macro_code
10///
11/// \author Lorenzo Moneta
12
13
14#include "TMath.h"
15#include "TF1.h"
16#include "TCanvas.h"
17
18#include "TLegend.h"
19#include "TLegendEntry.h"
20
21#include "Math/IFunction.h"
22#include "TSystem.h"
23
24#include <cmath>
25
26void Legendre()
27{
28 TCanvas *Canvas = new TCanvas("DistCanvas", "Legendre polynomials example", 10, 10, 750, 600);
29 Canvas->SetGrid();
30 TLegend *leg = new TLegend(0.5, 0.7, 0.4, 0.89);
31 //drawing the set of Legendre functions
32 TF1* L[5];
33 for(int nu = 0; nu <= 4; nu++)
34 {
35 L[nu]= new TF1("L_0", "ROOT::Math::legendre([0],x)", -1, 1);
36 L[nu]->SetParameters(nu, 0.0);
37 L[nu]->SetLineStyle(kSolid);
38 L[nu]->SetLineWidth(2);
39 L[nu]->SetLineColor(nu+1);
40 }
41 L[0]->SetMaximum(1);
42 L[0]->SetMinimum(-1);
43 L[0]->SetTitle("Legendre polynomials");
44 leg->AddEntry(L[0]->DrawCopy(), " L_{0}(x)", "l");
45 leg->AddEntry(L[1]->DrawCopy("same"), " L_{1}(x)", "l");
46 leg->AddEntry(L[2]->DrawCopy("same"), " L_{2}(x)", "l");
47 leg->AddEntry(L[3]->DrawCopy("same"), " L_{3}(x)", "l");
48 leg->AddEntry(L[4]->DrawCopy("same"), " L_{4}(x)", "l");
49 leg->Draw();
50
51 Canvas->cd();
52}
@ kSolid
Definition TAttLine.h:54
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
The Canvas class.
Definition TCanvas.h:23
TVirtualPad * cd(Int_t subpadnumber=0) override
Set current canvas & pad.
Definition TCanvas.cxx:729
1-Dim function class
Definition TF1.h:182
This class displays a legend box (TPaveText) containing several legend entries.
Definition TLegend.h:23
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition TObject.cxx:292
void SetGrid(Int_t valuex=1, Int_t valuey=1) override
Definition TPad.h:341
leg
Definition legend1.C:34
RooArgList L(Args_t &&... args)
Definition RooArgList.h:156