Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
318 views
in Technique[技术] by (71.8m points)

python - scipy interpolate barycentric lagrange

I have been reading about different ways to interpolate, for example- this article. It recommends using barycentric_lagrange instead of lagrange because it is more stable, runs in O(n) instead of O(n^2). This is all well and good, but I'd like to know how it is different than lagrange by itself. What I am looking for is a qualitative explanation of the difference between barycentric and traditional lagrange. I've tried looking at mathematical papers about it, but the math is not easy to follow.

Are the "weights" just a way of weighting points close to the points that you are interpolating? That would be great if it was that simple.

question from:https://stackoverflow.com/questions/65910918/scipy-interpolate-barycentric-lagrange

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I found through some experimentation that barycenctric lagrange does not "weight" points like I had hoped. It is still very unstable if your input arrays are large (i.e. it still tries to construct the nth degree polynomial). Barycentric has stability improvements for when the values are large. Lagrange is good if your x and y are close to 0. So x = [20000, 20001, 20002] will be much less stable than [0, 1, 2]. The weights in barycentric, therefore, are simply a way of scaling your values to 0. So the lagrange interpolation as follows:

x_scaled = x - x[0]
y_scaled = y - y[0]
polynomial = scipy.lagrange(x_scaled, y_scaled)
interp_y = polynomial(interp_x - x[0]) + y[0]

is the same as:

interp_y = scipy.barycentric_interpolate(x, y, interp_x)

So obviously the second one is much easier to implement in code, and they give the same result.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...