I'd like to propose the following elegant alternative: determine the coefficients of the associated Laguerre polynomial of order n, by determining the coefficients of the characteristic polynomial of its companion matrix:
function [c] = Laguerre_coeff(n, alpha)
i = 1:n;
a = (2*i-1) + alpha;
b = sqrt( i(1:n-1) .* ((1:n-1) + alpha) );
CM = diag(a) + diag(b,1) + diag(b,-1);
This now properly returns the zero'th order polynomial. The help is better. There is a default for alpha. Preallocation is now used to speed it up. This now looks like a 5 rating to me.
The help is acceptable, but not what I'd call great. It never carefully defines the inputs, although it does give an example of use of the function, so you can figure out which order they must appear.
Based on the help, I was planning on giving this a rating of 4, until I tripped over a bug. The help states:
% Given nonnegative integer n and alpha >= -1
The zero'th order Laguerre polynomial (for any value of alpha) is well defined.
L_0(x,alpha) = 1
and since zero is a non-negative integer, the help suggests that LaguerreGen can provide that polynomial. In fact, an error results.
>> LaguerreGen(0,0)
??? Subscripted assignment dimension mismatch.
Error in ==> LaguerreGen at 33
L(2,:)=[zeros(1, n-1), -1, (alpha+1)];
The higher order polynomials are computable, and the code is indeed efficient. I checked a few polynomials up to about order 10, and the coefficients were accurate.
I was a little surprised that no default was supplied for alpha. I.e., when alpha == 0 (or is not supplied) a generalized Laguerre should reduce to a standard Laguerre.