Lagrangian Interpolation
|
03-09-2015, 09:36 AM
Post: #9
|
|||
|
|||
RE: Lagrangian Interpolation
(03-09-2015 03:30 AM)bshoring Wrote: I have checked and rechecked the program listing and can't find any errors. Am I entering the numbers wrong ? No. That's the problem with this formula: \(\ell_j(x) = \ell(x)\frac{w_j}{x-x_j}\) This leads to a division by 0 if \(x=x_j\). The reasoning is that you usually don't want to evaluate the interpolation at the known points. You could try a value very close to 1 instead. But I think your point is valid and it made me wonder if we could just use the Lagrange polynomials as Namir did but still unroll the loops. Thus the weights are now calculated in lines 017-031: \(w_1=\frac{y_1}{(x_1-x_2)(x_3-x_1)}\) \(w_2=\frac{y_2}{(x_2-x_3)(x_1-x_2)}\) \(w_3=\frac{y_3}{(x_3-x_1)(x_2-x_3)}\) Memory Map \( \begin{matrix} I & : & x \\ R_0 & : & x_1 \\ R_1 & : & x_2 \\ R_2 & : & x_3 \\ R_3 & : & w_1 \\ R_4 & : & w_2 \\ R_5 & : & w_3 \\ \end{matrix} \) By factoring the sum I was able to calculate it using only the stack in lines 035-057: \((x-x_2)(x-x_3)w_1+(x-x_1)(x-x_3)w_2+(x-x_1)(x-x_2)w_3=((x-x_2)w_1+(x-x_1)w_2)(x-x_3)+(x-x_1)(x-x_2)w_3\) Code: 001 31 25 11 : LBL A It made the program even a little shorter. Cheers Thomas |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)