Post Reply 
(HP49/50) Laguerre Polynomials
02-22-2020, 06:02 PM
Post: #1
(HP49/50) Laguerre Polynomials
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.

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
  \>>
\>>
Find all posts by this user
Quote this message in a reply
02-28-2020, 08:53 PM
Post: #2
RE: (HP49/50) Laguerre Polynomials
A new version of the above program which is shorter and faster, but requires the ListExt and GoferLists libraries. The command COXF is the ConvOffs transform, the first program here.

Code:

\<< \-> n x
  \<< n LSEQ DUP COXF DUP * SWAP 1 :: * Scanl 1 n I\->R 2. MOD
{ NEG } IFT -1 n 1 + LMSEQ * * DUP Last SWAP AXL x PEVAL SWAP /
  \>>
\>>
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)