Logo ROOT   6.07/09
Reference Guide
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 <Riostream.h>
19 #include "TLegend.h"
20 #include "TLegendEntry.h"
21 
22 #include "Math/IFunction.h"
23 #include <cmath>
24 #include "TSystem.h"
25 
26 
27 void Legendre()
28 {
29  gSystem->Load("libMathMore");
30 
31  TCanvas *Canvas = new TCanvas("DistCanvas", "Legendre polynomials example", 10, 10, 750, 600);
32  Canvas->SetGrid();
33  TLegend *leg = new TLegend(0.5, 0.7, 0.4, 0.89);
34  //drawing the set of Legendre functions
35  TF1* L[5];
36  for(int nu = 0; nu <= 4; nu++)
37  {
38  L[nu]= new TF1("L_0", "ROOT::Math::legendre([0],x)", -1, 1);
39  L[nu]->SetParameters(nu, 0.0);
40  L[nu]->SetLineStyle(1);
41  L[nu]->SetLineWidth(2);
42  L[nu]->SetLineColor(nu+1);
43  }
44  L[0]->SetMaximum(1);
45  L[0]->SetMinimum(-1);
46  L[0]->SetTitle("Legendre polynomials");
47  leg->AddEntry(L[0]->DrawCopy(), " L_{0}(x)", "l");
48  leg->AddEntry(L[1]->DrawCopy("same"), " L_{1}(x)", "l");
49  leg->AddEntry(L[2]->DrawCopy("same"), " L_{2}(x)", "l");
50  leg->AddEntry(L[3]->DrawCopy("same"), " L_{3}(x)", "l");
51  leg->AddEntry(L[4]->DrawCopy("same"), " L_{4}(x)", "l");
52  leg->Draw();
53 
54  Canvas->cd();
55 }
56 
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition: TAttLine.h:49
virtual void SetParameters(const Double_t *params)
Definition: TF1.h:439
This class displays a legend box (TPaveText) containing several legend entries.
Definition: TLegend.h:27
RooArgList L(const RooAbsArg &v1)
virtual void Draw(Option_t *option="")
Draw this legend with its current attributes.
Definition: TLegend.cxx:373
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:659
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition: TSystem.cxx:1818
virtual void SetMinimum(Double_t minimum=-1111)
Set the minimum value along Y for this function In case the function is already drawn, set also the minimum in the helper histogram.
Definition: TF1.cxx:3125
virtual void SetGrid(Int_t valuex=1, Int_t valuey=1)
Definition: TPad.h:318
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:46
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
virtual void SetMaximum(Double_t maximum=-1111)
Set the maximum value along Y for this function In case the function is already drawn, set also the maximum in the helper histogram.
Definition: TF1.cxx:3112
virtual void SetTitle(const char *title="")
Set function title if title has the form "fffffff;xxxx;yyyy", it is assumed that the function title i...
Definition: TF1.cxx:3262
The Canvas class.
Definition: TCanvas.h:41
TLegendEntry * AddEntry(const TObject *obj, const char *label="", Option_t *option="lpf")
Add a new entry to this legend.
Definition: TLegend.cxx:280
leg
Definition: legend1.C:34
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition: TAttLine.h:48
1-Dim function class
Definition: TF1.h:149