02-22-2020, 06:02 PM
The following program returns the value of the nth Laguerre polynomial L_n(x) at x. To use the program, n (which must be an integer) should be on level 2, and x should be on level 1. If x is an integer, the result will be an integer or a rational number.
The formula given on the Wikipedia page is very slow to compute in practice because many intermediate terms have non-integer values. Instead the coefficients of the nth polynomial are computed and fed to the built-in PEVAL command which is quite fast.
The formula given on the Wikipedia page is very slow to compute in practice because many intermediate terms have non-integer values. Instead the coefficients of the nth polynomial are computed and fed to the built-in PEVAL command which is quite fast.
Code:
\<< SWAP I\->R \-> x n
\<<
IF n 1. >
THEN { 1 -1 } 2. n
FOR k 0 SWAP + 0 + 2.
\<< k NSUB + 1. - R\->I * SWAP -
\>> DOSUBS
NEXT DUP HEAD SWAP REVLIST AXL x PEVAL SWAP /
ELSE n 1. SAME { x NEG 1 + } { 1 } IFTE
END
\>>
\>>