(33S) Legendre Polynomials
|
05-18-2022, 04:02 PM
Post: #2
|
|||
|
|||
RE: (33S) Legendre Polynomials
Or then we use Horner's method to avoid exponentiation, e.g. for \(n = 5\):
\( \begin{align} u &= \frac{x - 1}{2} \\ \\ P_5(x) &= 1 + u \cdot \left(30 + u \cdot \left(210 + u \cdot \left(560 + u \cdot \left(630 + u \cdot 252 \right) \right) \right) \right) \\ \end{align} \) It's easy to see that: \( \begin{align} \binom{n}{k-1} &= \binom{n}{k} \frac{k}{n-k+1} \\ \\ \binom {n+k-1}{k-1} &= \binom {n+k}{k} \frac{k}{n + k} \\ \end{align} \) This leads to a recursive formula to calculate the coefficient from \(k \to k-1\): \( \begin{align} \binom{n}{k-1} \binom {n+k-1}{k-1} = \binom {n}{k}\binom {n+k}{k} \frac{k}{n-k+1} \frac{k}{n + k} \end{align} \) It is used to calculate the next coefficient from the previous one. Note: All of these coefficients are integers. Therefore, the order of operation is important. We also try to keep the intermediate results small. Python Code: from math import comb Example \( P_5(0.3) \) 5 ENTER 0.3 XEQ "LP" 0.34538625 Programs In case of the HP-42S and HP-15C (and other models as well) RCL-arithmetic could be used. Also I tried to avoid stack acrobatics to keep the code similar. Feel free to optimize the program for your favourite model. HP-42S Code: 00 { 52-Byte Prgm } HP-15C Code: 000 { } Some models use a specific register I for loops. HP-11C Code: 01-42,21,11 # f LBL A For models that don't have a function to compute binomial coefficients, we can use factorial instead: \( \begin{align} \binom{2n}{n} = \frac{(2n)!}{(n!)^2} \end{align} \) HP-67 Code: 001: 31 25 11 # f LBL A |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
(33S) Legendre Polynomials - Eddie W. Shore - 05-18-2022, 02:59 AM
RE: (33S) Legendre Polynomials - Thomas Klemm - 05-18-2022 04:02 PM
RE: (33S) Legendre Polynomials - John Keith - 05-18-2022, 05:11 PM
RE: (33S) Legendre Polynomials - Albert Chan - 05-18-2022, 08:34 PM
RE: (33S) Legendre Polynomials - Thomas Klemm - 05-18-2022, 07:34 PM
RE: (33S) Legendre Polynomials - Thomas Klemm - 05-18-2022, 11:13 PM
RE: (33S) Legendre Polynomials - Thomas Klemm - 05-20-2022, 04:10 PM
RE: (33S) Legendre Polynomials - Albert Chan - 05-20-2022, 05:51 PM
RE: (33S) Legendre Polynomials - Thomas Klemm - 05-20-2022, 08:08 PM
|
User(s) browsing this thread: 1 Guest(s)