有关for循环的问题
新手求教,麻烦各位高手了……
A=zeros(n,n);
for i=1:n;
for j=1:n;
if i==1;
A(1,j)=a(1,1)*(c(1,1)+d(1,1)^2/2)+4*c(1,1)*d(1,1)/(j*pi)*(sin(p(1,j)*l(1,1)));
A(1,j)= A(1,j)+d(1,1)^2/(2*j*pi)*sin(2*p(1,j)*l(1,1));
else
A(i,j)=a(1,i)*(c(1,i)+d(1,i)^2/2)+4*c(1,i)*d(1,i)/(j*pi)*(sin(p(1,j)*l(1,i))-sin(p(1,j)*l(1,i-1)));
A(i,j)=A(i,j)+d(1,i)^2/(2*j*pi)*(sin(2*p(1,j)*l(1,i))-sin(2*p(1,j)*l(1,i-1)));
end
end
end
B=zeros(n,n);
for i=1:n;
for j=1:n;
if i==1;
B(1,j)=a(1,1)*d(1,1)/2+2*c(1,1)/(j*pi)*(sin(p(1,j)*l(1,1)));
B(1,j)=B(1,j)+d(1,1)/(2*j*pi)*(sin(2*p(1,j)*l(1,1)));
else
B(i,j)=a(1,i)*d(1,i)/2+2*c(1,i)/(j*pi)*(sin(p(1,j)*l(1,i))-sin(p(1,j)*l(1,i-1)));
B(i,j)=B(i,j)+d(1,i)/(2*j*pi)*(sin(2*p(1,j)*l(1,i)-sin(2*p(1,j)*l(1,i-1))));
end
end
end
以上是AB两个循环,在调试的时候发现A循环只能跑if i=1的循环,而else里的循环却不走,直接跳过。但是B循环却可以整个循环跑完,明明这两个循环
的形式几乎一样,程序没有报错,其他参数(a(1,i),d(1,i)也很正常),新手求教,麻烦各位高手了。