How can I find roots of my interpolated functions?

1 次查看(过去 30 天)
Dear community,
I want to use 'fzero' to find the root of my equation. but unfortunately it doesn't work. it gives me this error:
Error using fzero (line 169) FUN must be a function, a valid string expression, or an inline function object
Error in anchoring (line 49) x = fzero(fun,x0)
The related part of my MATLAB code is:
theta_00 = 0:1e-6:3.5;
y_1 = interp1(theta_0, dtheta,theta_00, 'spline');
y_2 = interp1(theta_0, dtheta, theta_00, 'spline');
fun = y_1 - y_2;
x0 = [0 3.5];
x = fzero(fun,x0)
y_1 is belongs to some experimental data but y_2 has a function. I interpolate both of them. Here I do not know why am I getting this error. how can I find these crossing point?
Thanks

回答(1 个)

Moj
Moj 2014-12-12
yes I modified it as a
fun = @(theta_0)(y_1 - y_2);
but it still doesn't work I get this error:
Error using fzero (line 274) The function values at the interval endpoints must differ in sign
by looking at the figure it is clear that the fun has opposite sign at first and final point. by the way I examine a smaller interval but it again has the same error.
how can I solve this?
  2 个评论
Mohammad Abouali
Mohammad Abouali 2014-12-12
1) Don't comment to with new answer. There is "Comment on this Answer" button that you can use.
2) check the comment that below the answer that I provided to see what is going wrong.
Moj
Moj 2014-12-12
sorry sir, I know this, but I just made a mistake.
thanks

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by