简体   繁体   中英

Lagrange interpolation with Python doing something weird

Does anyone know why it's returning such crazy numbers?

from scipy.interpolate import lagrange

x = [2458723, 2458724, 2458725, 2458727, 2458728, 2458729]
y = [-2000, -900, 1000, 400, -4700, -1900]

poly = lagrange(x, y)

x0 = list(np.linspace(min(x), max(x), num=10))
y0 = poly(x0)
print(y0)

output: [-2.88230376e+18 -6.91752903e+18 -3.45876451e+18 -8.07045053e+18 -2.30584301e+18 -2.88230376e+18 -5.76460752e+18 -4.03522527e+18 -2.88230376e+18 -4.03522527e+18]

The implementation may be making assumptions about the domain. Try shifting your domain closer to x=0

from scipy.interpolate import lagrange
import numpy as np

x = np.array([2458723, 2458724, 2458725, 2458727, 2458728, 2458729])
y = np.array([-2000, -900, 1000, 400, -4700, -1900])

poly = lagrange(x - x.min(), y)

x0 = np.linspace(x.min(), x.max(), num=10)
y0 = poly(x0 - x0.min())
print(y0)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM