Matlab Spline Interpolation Find X from Y

女生的网名这么多〃 提交于 2019-12-12 18:14:43

问题


I need to find the value of x when y = 0.

This is my code:

x=[2,3,4,5,6]; 
y=[10,8,4,1,-2]; 
xi=linspace(2,6,100); 
yi=interp1(x,y,xi,'spline'); 
plot(x,y,'o',xi,yi,'-') 
xlabel('x')
 ylabel('y') 
title('Data')

I tried using fzero, but I couldn't figure out the proper syntax.

I do not have a function f(x) to use, only the points given.


回答1:


A couple of things to note:

  1. 'spline' refers to cubic spline. Be absolutely certain that is the interpolation technique that you want. Rerun your code with xi=linspace(0,6,100);
  2. The fzero function can be called on the interpolation function:

    fzero(@(xi)interp1(x,y,xi,'spline'),5)
    


来源:https://stackoverflow.com/questions/13319263/matlab-spline-interpolation-find-x-from-y

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!