フィルターのクリア

four summation containing loop

4 ビュー (過去 30 日間)
jana nassereddine
jana nassereddine 2021 年 5 月 1 日
コメント済み: jana nassereddine 2021 年 5 月 2 日
hey, I wrote this code for 4 summation in matlab, and i still have one problem in " n= n+ Term5*G" where n give NAN answer and I can't figure out why!!!
the code is:
clear,
f12=[]; n=0;
x= [0; 4]; y= [0; 2]; H=[0; 2]; E=[0; 3];
for l=1:2
for k=1:2
for j=1:2
for i=1:2
Term1= (y(j)-H(k))*(x(i)^2+E(l)^2)^0.5 ;
Term2= atan((y(j)-H(k))/(x(i)^2+E(l)^2)^0.5);
Term3= -0.25*(x(i)^2+E(l)^2-(y(j)-H(k))^2) ;
Term4= log(x(i)^2+E(l)^2+(y(j)-H(k))^2);
Term5= (-1)^(i+j+k+l);
G= (1/(2*pi))*(Term1*Term2+Term3*Term4);
n= n+ Term5*G;
end
end
end
end
f12 = (1/(x(2)-x(1))*(y(2)-y(1)))*n;

採用された回答

Jan
Jan 2021 年 5 月 1 日
編集済み: Jan 2021 年 5 月 1 日
Use the debugger to stop the code, when a NaN occurs:
dbstop naninf
Then run your code again. It stops in the first iteration, l=k=j=i=1 in:
Term2 = atan((y(j) - H(k)) / (x(i)^2 + E(l)^2)^0.5)
% ^^^^^^^^^^^^^^^^ This is zero
By the way, sqrt(x) is faster than x^0.5 .
  1 件のコメント
jana nassereddine
jana nassereddine 2021 年 5 月 2 日
thank you so much

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by