Legendre polynomials in the reverse direction

Click For Summary
SUMMARY

The discussion centers on calculating Legendre Polynomials using recursion, specifically focusing on deriving Pl-1 from Pl and Pl+1. The user confirmed that solving for Pl-1 is the correct approach for reverse calculation and opted against using the Rodrigues formula for initial values, instead utilizing the results from the forward recursion. The user encountered issues with debugging their Fortran program, which is designed to compute these polynomials, and sought assistance in identifying potential errors in their implementation.

PREREQUISITES
  • Understanding of Legendre Polynomials and their properties
  • Familiarity with recursion in programming
  • Proficiency in Fortran programming language
  • Knowledge of numerical methods for polynomial evaluation
NEXT STEPS
  • Study the properties and applications of Legendre Polynomials in numerical analysis
  • Learn advanced debugging techniques in Fortran to troubleshoot complex programs
  • Explore alternative methods for calculating polynomial values, such as using Chebyshev polynomials
  • Investigate the Rodrigues formula for generating orthogonal polynomials and its applications
USEFUL FOR

Mathematicians, computational scientists, and software developers working on numerical methods and polynomial calculations, particularly those using Fortran for scientific computing.

ognik
Messages
626
Reaction score
2
I have just written a program to calculate Legendre Polynomials, finding for Pl+1 using the recursion (l+1)Pl+1 + lPl-1 - (2l+1).x.Pl=0 That is working fine.
The next section of the problem is to investigate the recursive polynomial in the reverse direction. I would solve this for Pl-1 in terms of Pl and Pl+1 - could someone please confirm if that is the correct way to 'reverse'? Also I would use the Rodriques formula to get the 2 starting values of Pn and Pn-1, it's a complex formula, is there a better way to get those starting values? Thanks for all help.
 
Physics news on Phys.org
Hi again - I found enough to convince me that solving for Pl-1 is the correct way to calculate in the reverse direction. I also decided against using the Rodriguez formula, since I work out Pl and Pl+1 in the forward program, I can just use those as starting values for the reverse direction. All seemed good. However what I expect in the reverse direction, is to get P(x) for l=1, which should be always x. I figured that the last 2 P values correspond to L_input and L_input - 1, so loop down from L_input - 2 down to l=1 - see program code below.
I have spent hours with the debugger and pouring over the code, can't spot the bug or mistake in approach. Help please?
Code:
program LegendreDual
   implicit none
   integer, parameter   ::   rep=60
   integer, parameter   ::   dp = selected_real_kind(15, 307)
   real(kind=dp)     ::   X,P,P_minus,P_plus,saveP
   integer         ::   j, L_input
   character(len=rep )   ::   stars=REPEAT('*',rep)
   !----- header ----   
   print *, " "
   print *, 'Program LegendreDual starts'
   print *, stars 
   !----- Initialise ----   
   print *, " "
   print *,'Enter  l, X (l .LT.  0 to stop)'
   read *, L_input, X
   print *, " "
  while (L_input.GE.0) do
       print 20, 'L input','X Input','P'
     If (L_input.EQ.0) then
     P=0
  else if (L_input.EQ.1) then
       P=X
  else
     P_minus=1
  P=X
  Do j=1, L_input-1,+1           ! loop for fwd recursion
     P_plus=(((2*j)+1)*X*P)-(j*P_minus)
     P_plus=P_plus/(j+1)
         saveP=P
     P_minus=P                 ! roll values
     P=P_plus
       end do
     Print 50, L_input, X, P   
  P=saveP                   ! P from fwd; we can use P_plus and P
!-----------------------               ! to start the backward recursion
      Do j=L_input-2,1,-1               ! loop for reverse recursion,
     P_minus=(((2*j)+1)*X*P)-((j+1)*P_plus)   ! using P(n+1) and P just found
     P_minus=P_minus/j
     P=P_minus                   ! roll values
     P_plus=P
       end do     
  end if
  Print 50, j, X, P             ! only print once if l=0 or 1
     print *, stars  
     print *, " "
     print *,'Enter  l, X (l .LT.  0 to stop)'
     read *, L_input, X
  end do
   print *, " "
!--- admin ----
   print *, 'User selected end'
   print *, stars  
20   format (3X, A, 3X, A, 18X,A)
50   format (3X, I3, 5X, F10.5, 5X, F25.5)
end program LegendreDual
 
Please feel free to close or delete this thread and sorry for any inconvenience
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
1
Views
2K
  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K