Find x for known y from fit
Show older comments
Hi all
I would like to find values of x when y values are known using fzero. Assuming I have the following data:
x = [1 3 6 8 14 19 20 22];
y = [0.3 0.5 0.8 0.85 1 1.05 1.5 1.9];
xf=linspace(0,22,300)
yf=interp1(x,y,xf,'spline');
plot(x,y,'LineStyle','none','Color','k', 'MarkerSize',4 ,'Marker','square');
hold on
plot(xf,yf,'-r')
To find for example the value of x at yy=1.5 I used:
xdatax=fzero(@(xi)interp1(x,y,xi,'spline')-yy,5)
it works and it gives 3. But changing the value of yy (e.g.yy=1.5) gives xdata=-5.04 which is worong!!!
Does anyone know why it gives wrong results for some yy values? I appreciate your help and thanks..
Adam
1 Comment
Adam
on 4 Oct 2017
Edited: Walter Roberson
on 4 Oct 2017
Accepted Answer
More Answers (0)
Categories
Find more on Spline Postprocessing 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!