问题
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:
'spline'
refers to cubic spline. Be absolutely certain that is the interpolation technique that you want. Rerun your code withxi=linspace(0,6,100);
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