Solving Equation Generated by pchipinterp method

Hi,
I have an array of data which I fitted a curve to using the fit function and pchipinterp method, generating a cfit variable. I know that the line y = (a specific scalar value) will cross the fitted line/function 4 times. How can I solve for those 4 x-coordinates given a specific y-value? Thanks.

回答(1 个)

The simplest way to do this is to use my SLM toolbox.
x = sort(rand(1,20));
y = rand(1,20);
spl = pchip(x,y);
fnplt(spl)
yline(0.3);
What are the x locations where this curve crosses 0.3? There should be 7 such points based on what we see in the figure.
xsol = slmsolve(spl,0.3)
xsol =
Columns 1 through 4
0.0856060691907258 0.179689798032185 0.287680862853776 0.374467025155671
Columns 5 through 7
0.637324302388667 0.644738455928051 0.984815754063193
You can download my SLM toolbox from the File Exchange, here:

类别

帮助中心File Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by