user2638891
user2638891

Reputation: 1

MATLAB: evaluation of a piecewise polynomial (pchip) with ppval

I am trying to do a pchip interpolation in MATLAB. The interpolation works fine, but when I use the ppval function to check the curve (for plotting) I get an error message, and I cannot figure out what the problem is.

I have previously used the pchip function in this way: yi = pchip(x,y,xi), and that worked ok. However, I now want only the coefficients (pp.coefs). The problem is that they seem to make no sense when I try to check them with the ppval function.

This is an example:

x  = [1.4771 1.9031 2.3802 2.9031 3.3979];
y  = [6.1727 5.1242 3.4537 1.8528 0]; 
pp = pchip(x,y);
xs = linspace(x(1),x(end),200);
yy = ppval(pp.coefs,xs);

Error using unmkpp (line 19)
The input array does not seem to describe a pp function.

Error in ppval (line 63)
[b,c,l,k,dd]=unmkpp(pp);`

Can anyone help me figure out where I am doing something wrong? Thanks!

Upvotes: 0

Views: 2059

Answers (1)

Schorsch
Schorsch

Reputation: 7915

Do not just pass the coefficients to ppval but the entire structure that is returned by pchip.
This should work:

pp = pchip(x,y);
xs = linspace(x(1),x(end),200);
yy = ppval(pp,xs);

Upvotes: 1

Related Questions