简体   繁体   中英

Matlab: Getting the Coefficients of Piecewise Cubic Hermite Interpolating Polynomial

I want to fit a curve to some data. I used a PCHIP interpolation because of getting the best results. Moreover, I want to get the coefficients for the 6 intervals with the ppval-function . But there pops up an error like these:

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

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

Error in SA (line 8)
v = ppval(p,xdata)

This is my code:

clear all
xdata = [0; 3.5; 6.8; 7.6; 8.2; 30; 34.2];
ydata = [0; 50; 400000; 2000000; 25000000; 100000000;100000000]
xq1 = 0:0.01:35;

p = pchip(xdata,ydata, xq1);
s = spline(xdata,ydata,xq1);
v = ppval(p,xdata)
plot(xdata,ydata,'o',xq1,p,'-',xq1,s,'-.');
legend('Datenpunkte','pchip','spline','Location','SouthEast');

Can you help me?

Best regards Dominik

pchip has two working modes:

  • Calculating the piecewise polynomial coefficients: pp = pchip(x,y) :

    returns a piecewise polynomial structure for use with ppval

  • Interpolating at specified points: p = pchip(x,y,xq) :

    is the same as p = ppval(pchip(x,y),xq)

    returns a vector of interpolated values p corresponding to the query points in xq

So, you are using the second mode, which is not suited for use with ppval .

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