Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Legendre polynomials in the reverse direction

  1. Apr 1, 2015 #1
    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.
  2. jcsd
  3. Apr 2, 2015 #2
    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 (Text):

    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
      else if (L_input.EQ.1) then
      Do j=1, L_input-1,+1           ! loop for fwd recursion
         P_minus=P                 ! roll values
           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=P_minus                   ! roll values
           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
  4. Apr 10, 2015 #3
    Please feel free to close or delete this thread and sorry for any inconvenience
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Discussions: Legendre polynomials in the reverse direction