PDA

查看完整版本 : [MATLAB基础] 关于for循环得问题。急!!


applle_new
2010-04-27, 20:38
更改一下,为了方便,我把源代码附上:

N=input('\N Enter the amount of nodes:N=');
M=input('\M Enter the amount of lines:M=');

B1=input('\B1 Enter the details of transmation line:B1=');
%first column stands for one termination
%second column stands for the other termination
%third column stands for the impendance of transmation line
%fourth column stands for the admittance between transmation line and
%ground
%fifth column stands for the ratio of transformer k
%on the sixth column, '1' represents P is on the high-voltage side;'0'
%represents P is on the low-voltage side

X=input('\X Enter the number of node and the impedance between them:X=');

%h=input('\h Enter the harmonics:h=');

Y1=zeros(N);

%***********set up harmonic frequency**********%
h1=[];h2=[];
for n=0:3
if n==0
h1=[h1,6*n+1];
else
h1=[h1,6*n+1];
h2=[h2,6*n-1];
end
end
h3=[h1,h2];
k=sort(h3);
%***********************************************%

for a=1:7 %**********the main 'for loop' for the total calculation**********%

%**********Y-MATRIX**********%
for i=1:N
if X(i,2)~=0;
p=X(i,1);
Y1(p,p)=1./X(i,2);
end

end

for i=1:M
if B1(i,6)==0
p=B1(i,1);q=B1(i,2);
else
p=B1(i,2);q=B1(i,1);
end
Y1(p,q)=Y1(p,q)-1./(B1(i,3)*B1(i,5));
Y1(q,p)=Y1(p,q);
Y1(q,q)=Y1(q,q)+1./(B1(i,3)*B1(i,5)^2)+B1(i,4)./2;
Y1(p,p)=Y1(p,p)+1./B1(i,3)+B1(i,4)./2;

end

G=real(Y1);B0=imag(Y1);
Y=G+j*k(1,a)*B0;
B=imag(Y);

disp('The Y-matrix is:');
disp(Y);

disp('G is:');
disp(G);

disp('B is:');
disp(B);
disp(k(1,a));


a=a+1;


end

输入变量为:N=5;M=5;B1=[1 2 0.105i 0 1.05 0;
2 3 0.024+0.065i 0.032i 1 0;
2 4 0.03+0.08i 0.04i 1 0;
3 4 0.018+0.05i 0.026i 1 0;
4 5 0.184i 0 0.96 1];
X=[1 0;2 0;3 0;4 0;5 0]

想得到得理想结果是:G一直不变;B值为k倍(k=1,5,7,11,13,17,19)
结果按照这个程序得到得结果为:G随a倍递增,B值没有找到规律。

想请各位帮帮忙!十分感谢!在线等~~