-1

编码

conf=ones(103,1);  
f=conf;  
for k=1:103  
    f(k:k+1)=1i;  
    conf=f.*conf;  
    p(k,:)=conf;  
end

现在我实际上想在矩阵中记录每次迭代的结果p。这样我就可以稍后在我的程序中使用这个产品结果。
最终p矩阵可能像

[i i 1 1 1 1 1...
i -1 i 1 1 1 1.....
i -i -1 i 1 1 1.....
so on]
.

4

1 回答 1

0

It looks like you did all the hard fixes already. I think what you want is:

conf=ones(103,1);  
f=conf;  
for k=1:102         % <--- reduced this because otherwise f(k:k+1) attempts to 
                    %      index beyond the size of f
    f(k:k+1)=1i;  
    conf=f.*conf;  
    p(k,:)=conf;  
end
p(103,:)=1i;

I would check the results for a smaller array. For instance if I run the following smaller version of the above (as a test)

conf=ones(5,1);  
f=conf;  
for k=1:4 
    f(k:k+1)=1i;  
    conf=f.*conf;  
    p(k,:)=conf;  
end
p(5,:)=1i;

I get

>> real(p)

ans =

     0     0     1     1     1
    -1    -1     0     1     1
     0     0    -1     0     1
     1     1     0    -1     0
     0     0     0     0     0

and

>> imag(p)

ans =

     1     1     0     0     0
     0     0     1     0     0
    -1    -1     0     1     0
     0     0    -1     0     1
     1     1     1     1     1
于 2013-09-14T18:44:11.207 回答