2012-10-30 35 views
0

式隱式的錯誤是:Matlab的:解決在使用fzero

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的第一個解決方案。謝謝。

+0

這段代碼適用於我,沒有錯誤(我寫了值爲0.0130而不是a和b)。檢查你是否沒有在你的代碼中使用其他變量名,或者沒有清除一些變量... – bla

+0

謝謝,我發現了這個問題。我已經定義了'a'和'b'作爲向量(爲了不確定性目的)並且導致了這個問題。 – Pupil

+0

我複製我的評論作爲解答此問題的答案... – bla

回答

0

此代碼適用於我沒有錯誤(我寫了值0.0130而不是a和b)。檢查你的代碼中沒有使用其他變量名,或者沒有清除一些變量...