Here we use the Bonnet recurrence relation of legendary polynomials, i.e. —
This can be implemented using Python, proceeding as follows:
We define Legendre polynomials as a function named P (n, x), where n is called the order of the polynomial and x is the evaluation point. Basic cases: if n is 0, then the value of the polynomial is always 1, and this is x when the order is 1. These are the initial values needed for the repetition relation.
For other values of n, the function is defined recursively, directly from the Bonnet recursion. Thus, P (n, x) recursively returns the Legendre polynomial values (a function effectively defined with other base cases of the same function.)
Below is a Python implementation —
Output: b >
The value of the polynomial at given point is: 305.0
Now we can also plot Legendre polynomials (say 1st to 4th order) using matplotlib.