필터 지우기
필터 지우기

Find x for known y from fit

조회 수: 2 (최근 30일)
Adam
Adam 2017년 10월 4일
답변: Walter Roberson 2017년 10월 4일
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
Adam
Adam 2017년 10월 4일
편집: Walter Roberson 2017년 10월 4일
Correction:
xdatax=fzero(@(xi)interp1(x,y,xi,'spline')-yy,5)
must be
xdatax=fzero(@(xf)interp1(x,y,xf,'spline')-yy,5)

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2017년 10월 4일
-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개)

카테고리

Help CenterFile Exchange에서 Spline Postprocessing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by