Lagrangian Interpolation
03-09-2015, 09:36 AM
Post: #9
 Thomas Klemm Senior Member Posts: 1,447 Joined: Dec 2013
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 002        01  : 1 003        84  : R/S 004     33 00  : STO 0 005     35 52  : x<>y 006     33 03  : STO 3 007        02  : 2 008        84  : R/S 009     33 01  : STO 1 010     35 52  : x<>y 011     33 04  : STO 4 012        03  : 3 013        84  : R/S 014     33 02  : STO 2 015     35 52  : x<>Y 016     33 05  : STO 5 017     34 00  : RCL 0 018     34 01  : RCL 1 019        51  : - 020  33 81 03  : STO/ 3 021  33 81 04  : STO/ 4 022     34 01  : RCL 1 023     34 02  : RCL 2 024        51  : - 025  33 81 04  : STO/ 4 026  33 81 05  : STO/ 5 027     34 02  : RCL 2 028     34 00  : RCL 0 029        51  : - 030  33 81 05  : STO/ 5 031  33 81 03  : STO/ 3 032        84  : R/S 033  31 25 12  : LBL B 034     35 33  : ST I 035     34 04  : RCL 4 036     35 34  : RC I 037     34 00  : RCL 0 038        51  : - 039        71  : * 040     34 05  : RCL 5 041     35 82  : LST x 042        71  : * 043     35 34  : RC I 044     34 01  : RCL 1 045        51  : - 046        71  : * 047     35 52  : x<>y 048     34 03  : RCL 3 049     35 82  : LST x 050        71  : * 051        61  : + 052     35 34  : RC I 053     34 02  : RCL 2 054        51  : - 055        71  : * 056        61  : + 057        42  : CHS 058     35 22  : RTN

It made the program even a little shorter.

Cheers
Thomas
 « Next Oldest | Next Newest »

 Messages In This Thread Lagrangian Interpolation - Namir - 12-18-2013, 06:04 AM RE: Lagrangian Interpolation - bshoring - 03-05-2015, 05:17 AM RE: Lagrangian Interpolation - PedroLeiva - 03-05-2015, 09:33 PM RE: Lagrangian Interpolation - bshoring - 03-07-2015, 11:49 PM RE: Lagrangian Interpolation - PedroLeiva - 03-09-2015, 03:37 AM RE: Lagrangian Interpolation - Thomas Klemm - 03-08-2015, 06:02 AM RE: Lagrangian Interpolation - Thomas Klemm - 03-08-2015, 07:58 PM RE: Lagrangian Interpolation - bshoring - 03-09-2015, 03:30 AM RE: Lagrangian Interpolation - Thomas Klemm - 03-09-2015 09:36 AM RE: Lagrangian Interpolation - bshoring - 03-09-2015, 09:50 PM RE: Lagrangian Interpolation - Thomas Klemm - 03-11-2015, 08:04 AM RE: Lagrangian Interpolation - bshoring - 03-13-2015, 05:33 AM RE: Lagrangian Interpolation - Newton Polynomial - bshoring - 04-04-2015, 07:40 PM RE: Lagrangian Interpolation - Thomas Klemm - 03-09-2019, 07:08 PM RE: Lagrangian Interpolation - PedroLeiva - 03-14-2019, 03:55 PM RE: Lagrangian Interpolation - Thomas Klemm - 03-14-2019, 05:56 PM RE: Lagrangian Interpolation - PedroLeiva - 03-14-2019, 07:22 PM RE: Lagrangian Interpolation - Thomas Klemm - 03-14-2019, 07:58 PM RE: Lagrangian Interpolation - PedroLeiva - 03-14-2019, 08:12 PM

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