Clear Filters
Clear Filters

Why does fnplt show different values than ppval calculates for pchip function?

2 views (last 30 days)
I am looking to find the intersection point between two sets of data, but I'm finding that when I 1. fit each with a pchip, 2. use fncmb to subtract them, and then 3. use fnzeros to find the zero point, I'm getting a different result than what the point should be based on the fnplt of the combined function... I'm confused as to why there is a difference between what fnplt shows me, and the values ppval gives for the function.
I have the following data:
x = [0.0010; 0.0050; 0.0100; 0.0500; 0.1000; 0.5000; 1.0000; 1.5000; 2.0000; 3.0000];
y1 = 1.0e-03 * [0.180347; 0.130286; 0.081914; 0.015325; 0.006223; 0.000902; 0.000688; 0.000651; 0.000639; 0.000623];
y2 = 1.0e-05 * [0.721000; 0.723900; 0.728900; 0.742800; 0.750200; 0.768300; 0.770900; 0.771000000000000; 0.770800; 0.770800];
I fit pchips to get a function for each of these data:
f1=pchip(x,y1);
f2=pchip(x,y2);
I combine them:
fminus = fncmb(f2,'-',f1);
I solve for the zero point to get the intersection x value between the two datasets (which is what I'm after):
fnzeros(fminus)
This gives me the result of 0.083967272859043 (The x value of where these datasets intersect - great! This is what I need).
However... when I plotted the function to double check this result using fnplt, the 0 crossing point looks to be around 0.0867476.
fnplt(fminus)
When I plug values into ppval, sure enough, it says the value closest to 0 is the solution fnzeros gave me:
ppval(fminus, 0.083967272859043);
ppval(fminus, 0.0867476);
But then why does fnplt show me something slightly different for this same function? When I plot the same result using fplot based on the ppval values, it agrees with the calculation by fnzeros (which means fnzeros is going about it the same way as ppval).
fplot(@(x) ppval(fminus,x), [x(1) x(end)])
So, what is difference between how fnplt and ppval (and thus fnzeros, etc) calculate values based on my piecewise fit?
Thanks!

Accepted Answer

Stephen Jue
Stephen Jue on 1 Sep 2016
The difference between these functions is that "fnzeros" first converts the input function into B-form ( ref ) before calculating the zeros. Similarly, it seems that using "fplot" on "ppval" interpolates the piecewise polynomial into a smoother spline, giving a different zero than the raw piecewise polynomial spline from "fnplt".
Refer to this doc for an overview of the difference between ppform and B-form splines: Types of Splines: ppform and B-form
This doc gives an overview of how ppform splines can be used: Constructing and Working with ppform Splines. Standard practice for plotting seems to be to use "plot" in conjunction with "fnval".

More Answers (0)

Community Treasure Hunt

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

Start Hunting!