Fortran Implementing Generalized Laguerre Polynomials in Fortran

Click For Summary
The discussion revolves around implementing a Fortran subroutine to calculate generalized Laguerre polynomials using a specific mathematical formula. The implementation appears to be functional, but the results do not align with those from Mathematica, raising concerns about potential errors. Key questions include the possibility of numerical inaccuracies and the effectiveness of using recursive relations for such calculations. Participants highlight the use of the gamma function, which serves as a generalization of factorials, and question the handling of input and output arrays, specifically why the arrays "r" and "u" are not indexed and the absence of squaring "r". Clarifications on the origin of the (l+k)! term are also sought, indicating a need for deeper understanding of the mathematical formulation and its implementation in code.
d4n1el
Messages
2
Reaction score
1
Hi!
Im trying to do some rather easy QM-calculations in Fortran.
To do that i need a routine that calculates the generalized Laguerre polynomials.

I just did the simplest implementation of the equation:
L^l_n(x)=\sum_{k=0}^n\frac{(n+l)!(-x^2)^k}{(n-k)!k!}

I implemented this in the following way:
Code:
      SUBROUTINE LAGUERRE(n,l,r,u,arraylength)
      Implicit none
      INTEGER, INTENT(IN) :: arraylength,n
      real(kind=kind(0.d0)), INTENT(IN) :: l
      REAL(kind=kind(0.d0)), INTENT(IN),DIMENSION(arraylength) :: r
      REAL(kind=kind(0.d0)), INTENT(OUT),DIMENSION(arraylength) :: u
      REAL(kind=kind(0.d0)), DIMENSION(arraylength) :: temp
      Integer :: m
   
      temp=0.d0
      do m=0,n
         temp=temp+gamma(real(n)+l+1.0)*(-r)**m/
     +        (gamma(real(n)-real(m)+1.0)*gamma(l+real(m)+1.0)
     +        *gamma(real(m)+1.0))
      end do
      u=temp
      END SUBROUTINE LAGUERRE

The code is running and i do get results, but when i compare them with the results given in for example Mathematica, they seems quite strange.
So my questions are: Do you see some obvious mistakes? Do you think there are possibilities for numerical errors? (In such a case, do you have any advices on improvments?)

When i have been googling around, it looks like a lot of the numerical implementations are using recursive relations. What are the pro's and con's for doing this kind of calculation in such a manner?
 
Technology news on Phys.org
What is gamma? Is it an array, a function, a subroutine?
 
SteamKing said:
What is gamma? Is it an array, a function, a subroutine?
It looks like he's using it for factorial so it must the special function gamma (which reduces to factorial for integer values of the argument : gamma(n+1) = n! ).I just did the simplest implementation of the equation:
L^l_n(x)=\sum_{k=0}^n\frac{(n+l)!(-x^2)^k}{(n-k)!k!}

I implemented this in the following way:
Code:
      SUBROUTINE LAGUERRE(n,l,r,u,arraylength)
      Implicit none
      INTEGER, INTENT(IN) :: arraylength,n
      real(kind=kind(0.d0)), INTENT(IN) :: l
      REAL(kind=kind(0.d0)), INTENT(IN),DIMENSION(arraylength) :: r
      REAL(kind=kind(0.d0)), INTENT(OUT),DIMENSION(arraylength) :: u
      REAL(kind=kind(0.d0)), DIMENSION(arraylength) :: temp
      Integer :: m
   
      temp=0.d0
      do m=0,n
         temp=temp+gamma(real(n)+l+1.0)*(-r)**m/
     +        (gamma(real(n)-real(m)+1.0)*gamma(l+real(m)+1.0)
     +        *gamma(real(m)+1.0))
      end do
      u=temp
      END SUBROUTINE LAGUERRE

Do you see some obvious mistakes?

Why are "r" and "u" declared as arrays yet you don't index them like arrays?

Where did the (l+k)! term come from?
Why isn't "r" squared.
 
Last edited:
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 20 ·
Replies
20
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 54 ·
2
Replies
54
Views
5K