Array indexes must be positive integers or logical values.

2 vues (au cours des 30 derniers jours)
ljaseon
ljaseon le 12 Mai 2021
Commenté : ljaseon le 12 Mai 2021
this is the code that what i input but
Array indexes must be positive integers or logical values. at the moment SUM= E1*SUM(V(3:IOUT+1,JOUT+2))....
+E1*V(2,JOUT+2)/2+E2*V(IOUT+2,2)/2;
what is the problem?
clear all;format compact;
%Output;
%
% H NT Zo
% -----------------------
% 0.25 700 69.77
% 0.1 500 65.75
% 0.05 500 70.53
% 0.05 700 67.36
% 0.05 1000 65.50
H=0.05;
NT= 100;
A=2.5; B=2.5; D=0.5; W=1.0;
ER=2.35;
EO=8.81E-12;
U=3.0E+8;
NX=A/H;
NY=B/H;
ND=D/H;
NW=W/H;
VD=100.0;
ERR=1.0;
E1=EO;
E2=EO*ERR;
%CALCULATE CHARGE WITH AND WITHOUT DIELECTRIC
L=1:2
E1=EO;
E2=EO*ERR;
%INITIALIZATION
V=zeros(NX+2,NY+2);
%SET POTENTIAL ON INNER CONDUCTOR(FIXED NODES) EQUAL TO VD
V(2:NW+1,ND+2)=VD;
%NOW,CALCULATE THE TOTAL CHARGE ENCLOSED IN A
%RECTANGULAR PATH SURROUNDING THE INNER CONDUCTOR
IOUT=round((NX+NW)/2);
JOUT=round((NY+ND)/2);
%SUM POTENTIAL ON INNER AND OUTER LOOPS
for K=1:2
SUM=0;
SUM= E1*SUM(V(3:IOUT+1,JOUT+2))....
+E1*V(2,JOUT+2)/2+E2*V(IOUT+2,2)/2;
for J=1:JOUT-1
if(J<ND)
SUM=SUM+E2*V(IOUT+2,J+2);
elseif(J==ND)
SUM=SUM+(E1+E2)*V(IOUT+2,J+2)/2;
else
SUM=SUM+E1*V(IOUT+2,J+2);
end
end
if K==1
SV(1)=SUM;
end
IOUT=IOUT-1;
JOUT=JOUT-1;
end
SUM=SUM+2.0*E1*V(IOUT+2,JOUT+2);
SV(2)=SUM;
Q(L)=abs(SV(1)-SV(2));
ERR=ER;
% FINALLY,CALCULATE Zo
Co=4.0*Q(1)/VD;
C1=4.0*Q(2)/VD;
ZO=1.0/(U*sqrt(C0*C1));
disp([H,NT,ZO])

Réponse acceptée

Alan Stevens
Alan Stevens le 12 Mai 2021
Looks like you are using SUM when you want sum. Change to:
SUM= E1*sum(V(3:IOUT+1,JOUT+2))....
Also, in line 59, you should have C0 not Co.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by