Find x for known y from fit
4 views (last 30 days)
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
Accepted Answer
Walter Roberson
on 4 Oct 2017
-5.04 is a valid answer considering that you did not constrain the search range. Perhaps you want
xdatax = fzero(@(xf)interp1(x,y,xf,'spline')-yy,[min(x) max(x)])
Note that this will give an error if y(1)-yy is the same sign as y(end)-yy
Also, there are values such as 0.9 that occur multiple times; your code does not define which of the values will be located.
With spline fit, you are going to get "overcorrections". If, for example, you have a line that angles up to the right and it has a peak, then the spline will typically have its peak a little higher, because splines do not have sharp angles. This can result in false matches.
I suggest you reconsider your algorithm. The false matches you can get cannot be justified unless you know that the underlying physical process happens to have a spline response (for example your measurements happen to be along the edge of some bent wood.)
0 Comments
More Answers (0)
See Also
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!