lagrange_interpolation.py

Created by vnap0v

Created on December 19, 2025

3.34 KB

Linear and polynomial interpolation using Lagrange polynomial

try from wikipedia using info from:

Linear interpolation

(x0,y0) (x1,y1) succesive data points

                   y1 - y0
y = y0 + (x - x0) ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
                   x1 - x0

Lagrange polynomial

xi, yi : data points
 
         n  ⎛         x - xj     ⎞
p(x) =   ∑  ⎜    ∏   ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯    ⎟ yi
        i=0 ⎝  0≤j≤n  xi - xj    ⎠
                j≠i

Lagrange polynomial in second barycentric form

xj, yj: data points, wj: barymetric weight
 
wj =  ∏  (xj - xm)⁻¹  
     m≠j
 
          k  ⎛    wj      ⎞
          ∑  ⎜ ⎯⎯⎯⎯⎯⎯⎯ yj  ⎟ 
         j=0 ⎝  x - xj    ⎠
p(x) = ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
          k  ⎛    wj   ⎞
          ∑  ⎜ ⎯⎯⎯⎯⎯⎯⎯  ⎟ 
         j=0 ⎝  x - xj ⎠


During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.