Expression of interpolating function
1 view (last 30 days)
Show older comments
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
0 Comments
Answers (1)
John D'Errico
on 15 Jun 2019
Edited: John D'Errico
on 15 Jun 2019
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?
0 Comments
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!