Matlab:使用fzero求解隐式方程时出错

时间:2012-10-30 19:02:07

标签: matlab optimization implicit equation

等式是:

enter image description here

其中,ab是常量,都等于0.0130

这是我正在使用的代码:

% Solving the equation for zero.
f = @(theta) ((a+b).*theta)./((theta.^2)-(a.*b)) - tan(theta);  % Notice the dots (.)

% Now plot it to get an idea of where the zeros are.
theta = 0:1:100;
for i=1:length(theta)
    hold on
    plot(theta(i),f(theta(i)),'-o')  % Look for the zeros
end

% Now find the roots.
cnt = 1;
for ii = [0,2,50]  % This vector has the guesses.
    rt(cnt) = fzero(f,ii); % Pass each guess to FZERO.
    cnt = cnt + 1;
end

这是我得到的错误:

??? Operands to the || and && operators must be convertible to
logical scalar values.

Error in ==> fzero at 323
    elseif ~isfinite(fx) || ~isreal(fx)

Error in ==> HW4 at 52
    rt(cnt) = fzero(f,ii); % Pass each guess to FZERO.

我想获得\ theta的第一个解决方案。谢谢。

1 个答案:

答案 0 :(得分:0)

这段代码对我没有任何错误(我写了0.0130而不是a和b)。检查您的代码中是否没有使用其他变量名,或者不清除某些变量......