ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Legendre.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_math
3 /// Example of first few Legendre Polynomials
4 ///
5 /// Draws a graph.
6 ///
7 /// \macro_image
8 /// \macro_code
9 ///
10 /// \author Lorenzo Moneta
11 
12 #if defined(__CINT__) && !defined(__MAKECINT__)
13 {
14  gSystem->CompileMacro("Legendre.C", "k");
15  Legendre();
16 }
17 #else
18 
19 #include "TMath.h"
20 #include "TF1.h"
21 #include "TCanvas.h"
22 
23 #include <Riostream.h>
24 #include "TLegend.h"
25 #include "TLegendEntry.h"
26 
27 #include "Math/IFunction.h"
28 #include <cmath>
29 #include "TSystem.h"
30 
31 
32 void Legendre()
33 {
34  gSystem->Load("libMathMore");
35 
36  TCanvas *Canvas = new TCanvas("DistCanvas", "Legendre polynomials example", 10, 10, 750, 600);
37  Canvas->SetFillColor(17);
38  Canvas->SetGrid();
39  Canvas->SetFrameFillColor(19);
40  TLegend *leg = new TLegend(0.5, 0.7, 0.4, 0.89);
41 //drawing the set of Legendre functions
42  TF1* L[5];
43  for(int nu = 0; nu <= 4; nu++)
44  {
45  L[nu]= new TF1("L_0", "ROOT::Math::legendre([0],x)", -1, 1);
46  L[nu]->SetParameters(nu, 0.0);
47  L[nu]->SetLineStyle(1);
48  L[nu]->SetLineWidth(2);
49  L[nu]->SetLineColor(nu+1);
50  }
51  L[0]->SetMaximum(1);
52  L[0]->SetMinimum(-1);
53  L[0]->SetTitle("Legendre polynomials");
54  leg->AddEntry(L[0]->DrawCopy(), " L_{0}(x)", "l");
55  leg->AddEntry(L[1]->DrawCopy("same"), " L_{1}(x)", "l");
56  leg->AddEntry(L[2]->DrawCopy("same"), " L_{2}(x)", "l");
57  leg->AddEntry(L[3]->DrawCopy("same"), " L_{3}(x)", "l");
58  leg->AddEntry(L[4]->DrawCopy("same"), " L_{4}(x)", "l");
59  leg->Draw();
60 
61  Canvas->cd();
62 }
63 #endif
virtual void SetLineWidth(Width_t lwidth)
Definition: TAttLine.h:57
virtual void SetParameters(const Double_t *params)
Definition: TF1.h:432
This class displays a legend box (TPaveText) containing several legend entries.
Definition: TLegend.h:35
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:1766
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:3090
virtual void SetGrid(Int_t valuex=1, Int_t valuey=1)
Definition: TPad.h:326
virtual int CompileMacro(const char *filename, Option_t *opt="", const char *library_name="", const char *build_dir="", UInt_t dirmode=0)
This method compiles and loads a shared library containing the code from the file "filename"...
Definition: TSystem.cxx:2736
virtual void SetLineColor(Color_t lcolor)
Definition: TAttLine.h:54
R__EXTERN TSystem * gSystem
Definition: TSystem.h:545
virtual void SetFillColor(Color_t fcolor)
Definition: TAttFill.h:50
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:3077
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:3227
The Canvas class.
Definition: TCanvas.h:48
TLegendEntry * AddEntry(const TObject *obj, const char *label="", Option_t *option="lpf")
Add a new entry to this legend.
Definition: TLegend.cxx:280
virtual void SetLineStyle(Style_t lstyle)
Definition: TAttLine.h:56
1-Dim function class
Definition: TF1.h:149
void SetFrameFillColor(Color_t color=1)
Definition: TAttPad.h:83