Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First try at implementing evaluation of legendrePolynomial #136

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/legendrePolynomial.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function legendrePolynomial(n)
#Storing the coefficients of the Legendre Polynomial up
# to n degree in a n+1 x n+1 matrix. We need to store all the coefficients
# because the loops are expression of the following recursive relation (Bonnet):
#(n+1)*P_{n+1}(x) = (2n+1)*x*P_{n}(x) - n*P_{n-1}(x)
c = zeros((n+1, n+1))
c[1,1] = 1.0

if n <= 0
return c
end
c[2,2] = 1.0

for i = 2:n
for j=0:i-1
c[i+1,j+1] = (- i + 1) * c[i-1,j+1] / i
end
for j=1:i
c[i+1,j+1] = c[i+1,j+1] + (i+i - 1) * c[i,j] / i
end
end
return c
end