简体   繁体   English

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

[英]Matlab: Error in solving implicit equation using fzero

Equation is: 等式是:

在此处输入图片说明

where, a and b are constants and both equal to 0.0130 其中, ab是常数,并且都等于0.0130

This is the code I am using: 这是我正在使用的代码:

% 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

This is the error I get: 这是我得到的错误:

??? 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.

I would like to get the first solution of \\theta. 我想得到\\ theta的第一个解决方案。 Thanks. 谢谢。

This code works for me with no errors (I wrote the value 0.0130 instead of a and b). 此代码的工作对我来说没有任何错误(我写的,而不是一个值0.0130和b)。 Check that you're not using some other variable name in your code, or not clearing some variables... 检查您是否在代码中未使用其他变量名,或未清除某些变量...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM