Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
Legendre.C File Reference

Detailed Description

View in nbviewer Open in SWAN
Example of first few Legendre Polynomials

Draws a graph.

#include "TMath.h"
#include "TF1.h"
#include "TCanvas.h"
#include <Riostream.h>
#include "TLegend.h"
#include "TLegendEntry.h"
#include "Math/IFunction.h"
#include <cmath>
#include "TSystem.h"
void Legendre()
{
TCanvas *Canvas = new TCanvas("DistCanvas", "Legendre polynomials example", 10, 10, 750, 600);
Canvas->SetGrid();
TLegend *leg = new TLegend(0.5, 0.7, 0.4, 0.89);
//drawing the set of Legendre functions
TF1* L[5];
for(int nu = 0; nu <= 4; nu++)
{
L[nu]= new TF1("L_0", "ROOT::Math::legendre([0],x)", -1, 1);
L[nu]->SetParameters(nu, 0.0);
L[nu]->SetLineStyle(1);
L[nu]->SetLineWidth(2);
L[nu]->SetLineColor(nu+1);
}
L[0]->SetMaximum(1);
L[0]->SetMinimum(-1);
L[0]->SetTitle("Legendre polynomials");
leg->AddEntry(L[0]->DrawCopy(), " L_{0}(x)", "l");
leg->AddEntry(L[1]->DrawCopy("same"), " L_{1}(x)", "l");
leg->AddEntry(L[2]->DrawCopy("same"), " L_{2}(x)", "l");
leg->AddEntry(L[3]->DrawCopy("same"), " L_{3}(x)", "l");
leg->AddEntry(L[4]->DrawCopy("same"), " L_{4}(x)", "l");
leg->Draw();
Canvas->cd();
}
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:719
1-Dim function class
Definition TF1.h:233
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:280
void SetGrid(Int_t valuex=1, Int_t valuey=1) override
Definition TPad.h:335
leg
Definition legend1.C:34
Author
Lorenzo Moneta

Definition in file Legendre.C.