How to solve NaN problem
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi, I have a code like
function [ TT] = Base( )
D1=input('Duct1 dia=');
D2=input('Duct2 dia=');
a=input('extend length(a)=');
b=input('extend length(b)=');
s1=pi*D1^2/4;
s2=pi*D2^2/4;
c=340;
q=1.293;
freq=linspace(1,6486,1082);
K=2*pi*freq/340;
Z22=1i*(q*c/s2)*cot(K*a);
Z21=-1i*(q*c/s2)*cot(K*b);
T=zeros(4,6486);
n=1;
A=zeros(1,1082);
B=zeros(1,1082);
C=zeros(1,1082);
D=zeros(1,1082);
E=zeros(1,1082);
F=zeros(1,1082);
G=zeros(1,1082);
H=zeros(1,1082);
for ii=1:1:1082
A(n)=T(1,4*n)+Z21(n)*T(1,4*n-1);
B(n)=T(3,4*n-3)+Z22(n)*T(4,4*n-3);
C(n)=T(3,4*n-2)+Z22(n)*T(4,4*n-2);
D(n)=T(2,4*n)+Z21(n)*T(2,4*n-3);
E(n)=((T(4,4*n)+T(4,4*n-1)*Z21(n))*Z22(n))-(T(3,4*n)+T(3,4*n-1)*Z21(n));
TT(:,2*n-1:2*n)=[T(1,4*n-3)+A(n)*B(n)/E(n),T(1,4*n-2)+A(n)*C(n)/E(n);T(2,4*n-3)+D(n)*B(n)/E(n),T(2,4*n)+D(n)*C(n)/E(n)];
n=n+1;
end
end
but in command window the ans is a NaN matrix, SO how can I solve this? If any body could please suggest me if possible, Thanks
0 Commenti
Risposte (1)
Roger Stafford
il 7 Mag 2013
Modificato: Roger Stafford
il 7 Mag 2013
When you compute TT you are dividing zero by zero at four places where you divide by E(n), hence the NaN. This is because with T all zero, A(n), B(n), C(n), D(n), and E(n) are always all zero. Are you sure you have initialized T properly?
Also why haven't you used n as the index in your for-loop rather than ii?
0 Commenti
Vedere anche
Categorie
Scopri di più su Characters and Strings in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!