Expression of interpolating function

3 次查看(过去 30 天)
How can I get the expression of the polynomial interpolating the function in n linearly spaced nodes in an interval?
I thought about using the polyfit and polyval command but I don't know how to get the polynomial expression

回答(1 个)

John D'Errico
John D'Errico 2019-6-15
编辑:John D'Errico 2019-6-15
A high order interpolating polynomial is a REALLY, REALLY, REALLY bad idea. There, if i said it three times, it must be true. Seriously, it is. Just because they taught you about Lagrange interpolating polynomials, does not mean it was ever a good idea. Even Lagrange does not use them anymore. Ok, I will concede that he is dead. But if he were alive, he would be using splines.
Regardless, your question is trivial to solve. Sigh. ;-)
x = -3:3';
y = exp(-x.^2);
P = polyfit(x,y,6)
P =
-0.012754 7.886e-18 0.19267 7.1945e-17 -0.81204 -3.6035e-16 1
vpa(dot(P,X.^(length(P) - 1: - 1:0)),6)
ans =
- 0.0127544*X^6 + 7.88603e-18*X^5 + 0.192672*X^4 + 7.1945e-17*X^3 - 0.812038*X^2 - 3.60352e-16*X + 1.0
Is it a good idea to use that polynomial? Absolutely not!
fplot(@(x) polyval(P,x),[-3,3])
hold on
plot(x,y,'ro')
Is that really a good approximation to the underlying function? It is an interpolating polyynomial. But do you seriously want to use it, for ANYTHING?

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by