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

Matlab:使用fzero求解隐式方程时出错,matlab,optimization,implicit,equation,Matlab,Optimization,Implicit,Equation,方程式为: 其中,a和b为常数,均等于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)

方程式为:

其中,
a
b
为常数,均等于
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.

我想得到θ的第一个解。谢谢

这段代码对我来说没有错误(我写的值是0.0130,而不是a和b)。检查代码中是否未使用其他变量名,或是否未清除某些变量

这段代码对我来说没有错误(我写的值是0.0130,而不是a和b)。检查代码中没有使用其他变量名,或者没有清除某些变量…谢谢,我发现了问题。我将
a
b
定义为向量(出于不确定性目的),这就是问题的根源。我复制了我的评论作为答案,以回答这个问题。。。