LegendrePolynomial Subroutine

public subroutine LegendrePolynomial(N, x, lAtX, dLdxAtX)

Arguments

TypeIntentOptionalAttributesName
integer :: N
real(kind=real64) :: x
real(kind=real64) :: lAtX
real(kind=real64) :: dLdxAtX

Called by

proc~~legendrepolynomial~~CalledByGraph proc~legendrepolynomial LegendrePolynomial proc~legendregauss LegendreGauss proc~legendregauss->proc~legendrepolynomial proc~legendrequadrature LegendreQuadrature proc~legendrequadrature->proc~legendregauss proc~init_lagrange_t Init_Lagrange_t proc~init_lagrange_t->proc~legendrequadrature proc~init_lagrange~2 Init_Lagrange proc~init_lagrange~2->proc~legendrequadrature proc~init_lagrange Init_Lagrange proc~init_lagrange->proc~legendrequadrature

Contents

Source Code


Source Code

  subroutine LegendrePolynomial(N,x,lAtX,dLdxAtX)
    implicit none
    integer     :: N
    real(real64)    :: x
    real(real64)    :: lAtX,dLdxAtX
    ! Local
    real(real64) :: lNm1,lNm2,dlNm1,dlNm2
    integer  :: i

    if(N == 0) then

      lAtX = 1.0_real64
      dLdxAtX = 0.0_real64

    elseif(N == 1) then

      lAtX = x
      dLdxAtX = 1.0_real64

    else

      lnM2 = 1.0_real64
      lnM1 = x
      dlnM2 = 0.0_real64
      dlnM1 = 1.0_real64

      do i = 2,N

        lAtX = ((2.0_real64*real(i,real64)-1.0_real64)*x*lnM1- &
                (real(i,real64)-1.0_real64)*lnM2)/(real(i,real64))

        dldxAtX = dlnM2+(2.0_real64*real(i,real64)-1.0_real64)*lnM1
        lnM2 = lnM1
        lnM1 = lAtX
        dlnM2 = dlnM1
        dlnM1 = dldxAtX

      enddo

    endif

  endsubroutine LegendrePolynomial