{ "cells": [ { "cell_type": "markdown", "id": "ae14fbf0", "metadata": {}, "source": [ "# LegendreAssoc\n", "Example describing the usage of different kinds of Associate Legendre Polynomials.\n", "\n", "To execute the macro type in:\n", "\n", "```cpp\n", "root[0] .x LegendreAssoc.C\n", "```\n", "\n", "It draws common graphs for first 5\n", "Associate Legendre Polynomials\n", "and Spherical Associate Legendre Polynomials.\n", "Their integrals on the range [-1, 1] are calculated.\n", "\n", "\n", "\n", "\n", "**Author:** Magdalena Slawinska \n", "This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, May 19, 2026 at 08:25 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "a9271b01", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:40.469127Z", "iopub.status.busy": "2026-05-19T20:25:40.469007Z", "iopub.status.idle": "2026-05-19T20:25:40.817280Z", "shell.execute_reply": "2026-05-19T20:25:40.816715Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Drawing associate Legendre Polynomials..\n" ] } ], "source": [ "std::cout <<\"Drawing associate Legendre Polynomials..\" << std::endl;\n", "TCanvas *Canvas = new TCanvas(\"DistCanvas\", \"Associate Legendre polynomials\", 10, 10, 800, 500);\n", "Canvas->Divide(2,1);\n", "TLegend *leg1 = new TLegend(0.5, 0.7, 0.8, 0.89);\n", "TLegend *leg2 = new TLegend(0.5, 0.7, 0.8, 0.89);" ] }, { "cell_type": "markdown", "id": "aa43f5d6", "metadata": {}, "source": [ "-------------------------------------------\n", "drawing the set of Legendre functions" ] }, { "cell_type": "code", "execution_count": 2, "id": "421339bb", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:40.818841Z", "iopub.status.busy": "2026-05-19T20:25:40.818721Z", "iopub.status.idle": "2026-05-19T20:25:41.025563Z", "shell.execute_reply": "2026-05-19T20:25:41.024951Z" } }, "outputs": [], "source": [ "TF1* L[5];\n", "\n", "L[0]= new TF1(\"L_0\", \"ROOT::Math::assoc_legendre(1, 0,x)\", -1, 1);\n", "L[1]= new TF1(\"L_1\", \"ROOT::Math::assoc_legendre(1, 1,x)\", -1, 1);\n", "L[2]= new TF1(\"L_2\", \"ROOT::Math::assoc_legendre(2, 0,x)\", -1, 1);\n", "L[3]= new TF1(\"L_3\", \"ROOT::Math::assoc_legendre(2, 1,x)\", -1, 1);\n", "L[4]= new TF1(\"L_4\", \"ROOT::Math::assoc_legendre(2, 2,x)\", -1, 1);\n", "\n", "TF1* SL[5];\n", "\n", "SL[0]= new TF1(\"SL_0\", \"ROOT::Math::sph_legendre(1, 0,x)\", -TMath::Pi(), TMath::Pi());\n", "SL[1]= new TF1(\"SL_1\", \"ROOT::Math::sph_legendre(1, 1,x)\", -TMath::Pi(), TMath::Pi());\n", "SL[2]= new TF1(\"SL_2\", \"ROOT::Math::sph_legendre(2, 0,x)\", -TMath::Pi(), TMath::Pi());\n", "SL[3]= new TF1(\"SL_3\", \"ROOT::Math::sph_legendre(2, 1,x)\", -TMath::Pi(), TMath::Pi());\n", "SL[4]= new TF1(\"SL_4\", \"ROOT::Math::sph_legendre(2, 2,x)\", -TMath::Pi(), TMath::Pi() );\n", "\n", "Canvas->cd(1);\n", "gPad->SetGrid();\n", "gPad->SetFillColor(kWhite);\n", "L[0]->SetMaximum(3);\n", "L[0]->SetMinimum(-2);\n", "L[0]->SetTitle(\"Associate Legendre Polynomials\");\n", "for (int nu = 0; nu < 5; nu++) {\n", " L[nu]->SetLineStyle(kSolid);\n", " L[nu]->SetLineWidth(2);\n", " L[nu]->SetLineColor(nu+1);\n", "}\n", "\n", "leg1->AddEntry(L[0]->DrawCopy(), \" P^{1}_{0}(x)\", \"l\");\n", "leg1->AddEntry(L[1]->DrawCopy(\"same\"), \" P^{1}_{1}(x)\", \"l\");\n", "leg1->AddEntry(L[2]->DrawCopy(\"same\"), \" P^{2}_{0}(x)\", \"l\");\n", "leg1->AddEntry(L[3]->DrawCopy(\"same\"), \" P^{2}_{1}(x)\", \"l\");\n", "leg1->AddEntry(L[4]->DrawCopy(\"same\"), \" P^{2}_{2}(x)\", \"l\");\n", "leg1->Draw();\n", "\n", "Canvas->cd(2);\n", "gPad->SetGrid();\n", "gPad->SetFillColor(kWhite);\n", "SL[0]->SetMaximum(1);\n", "SL[0]->SetMinimum(-1);\n", "SL[0]->SetTitle(\"Spherical Legendre Polynomials\");\n", "for (int nu = 0; nu < 5; nu++) {\n", " SL[nu]->SetLineStyle(kSolid);\n", " SL[nu]->SetLineWidth(2);\n", " SL[nu]->SetLineColor(nu+1);\n", "}\n", "\n", "leg2->AddEntry(SL[0]->DrawCopy(), \" P^{1}_{0}(x)\", \"l\");\n", "leg2->AddEntry(SL[1]->DrawCopy(\"same\"), \" P^{1}_{1}(x)\", \"l\");\n", "leg2->AddEntry(SL[2]->DrawCopy(\"same\"), \" P^{2}_{0}(x)\", \"l\");\n", "leg2->AddEntry(SL[3]->DrawCopy(\"same\"), \" P^{2}_{1}(x)\", \"l\");\n", "leg2->AddEntry(SL[4]->DrawCopy(\"same\"), \" P^{2}_{2}(x)\", \"l\");\n", "leg2->Draw();" ] }, { "cell_type": "markdown", "id": "e180d539", "metadata": {}, "source": [ "integration" ] }, { "cell_type": "code", "execution_count": 3, "id": "ce319622", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:41.027314Z", "iopub.status.busy": "2026-05-19T20:25:41.027195Z", "iopub.status.idle": "2026-05-19T20:25:41.231025Z", "shell.execute_reply": "2026-05-19T20:25:41.230297Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Calculating integrals of Associate Legendre Polynomials on [-1, 1]\n", "Integral [-1,1] for Associated Legendre Polynomial of Degree 0\t = \t0\n", "Integral [-1,1] for Associated Legendre Polynomial of Degree 1\t = \t1.5708\n", "Integral [-1,1] for Associated Legendre Polynomial of Degree 2\t = \t5.55112e-17\n", "Integral [-1,1] for Associated Legendre Polynomial of Degree 3\t = \t0\n", "Integral [-1,1] for Associated Legendre Polynomial of Degree 4\t = \t4\n" ] } ], "source": [ "std::cout << \"Calculating integrals of Associate Legendre Polynomials on [-1, 1]\" << std::endl;\n", "double integral[5];\n", "for (int nu = 0; nu < 5; nu++) {\n", " integral[nu] = L[nu]->Integral(-1.0, 1.0);\n", " std::cout <<\"Integral [-1,1] for Associated Legendre Polynomial of Degree \" << nu << \"\\t = \\t\" << integral[nu] << std::endl;\n", "}" ] }, { "cell_type": "markdown", "id": "3e79a95f", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 4, "id": "9dce18b5", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:41.232787Z", "iopub.status.busy": "2026-05-19T20:25:41.232662Z", "iopub.status.idle": "2026-05-19T20:25:41.545915Z", "shell.execute_reply": "2026-05-19T20:25:41.544616Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "gROOT->GetListOfCanvases()->Draw()" ] } ], "metadata": { "kernelspec": { "display_name": "ROOT C++", "language": "c++", "name": "root" }, "language_info": { "codemirror_mode": "text/x-c++src", "file_extension": ".C", "mimetype": " text/x-c++src", "name": "c++" } }, "nbformat": 4, "nbformat_minor": 5 }