www.pudn.com > Algorithm.rar > istrassen.m, change:2007-11-24,size:722b


%此程序是用Strassen算法思想实现两个规模为2^k*2^k的矩阵相乘 
function C=istrassen(A,B,n) 
if n==1 
    C=A*B;   
elseif rem(n,2)==0 
    A11=A(1:n/2,1:n/2); 
    A12=A(1:n/2,n/2+1:n); 
    A21=A(n/2+1:n,1:n/2); 
    A22=A(n/2+1:n,n/2+1:n); 
    B11=B(1:n/2,1:n/2); 
    B12=B(1:n/2,n/2+1:n); 
    B21=B(n/2+1:n,1:n/2); 
    B22=B(n/2+1:n,n/2+1:n); 
    m1=istrassen(A11,B12-B22,n/2); 
    m2=istrassen(A11+A12,B22,(n/2)); 
    m3=istrassen((A21+A22),B11,(n/2)); 
    m4=istrassen(A22,(B21-B11),(n/2)); 
    m5=istrassen((A11+A22),(B11+B22),(n/2)); 
    m6=istrassen((A12-A22),(B21+B22),(n/2)); 
    m7=istrassen((A11-A21),(B11+B12),(n/2)); 
    C=[m5+m4-m2+m6,m1+m2;m3+m4,m5+m1-m3-m7]; 
else  
    error('Dead Cycle!') 
end