www.pudn.com > Algorithm.rar > matrix_mul.m, change:2007-11-26,size:719b


%三种不同的算法在实现矩阵相乘时的时间复杂度比较,以及与Matlab自带的矩阵 
%相乘的比较 
clear,clc 
n=[4,8,16,32,64,128]; 
for i=2:7 
    A=rand(n(i-1)); 
    B=rand(n(i-1)); 
    tic,C=imatrix(A,B,n(i-1));T1(i-1)=toc;  
    tic,C=iclass(A,B,n(i-1));T2(i-1)=toc; 
    tic,C=istrassen(A,B,n(i-1));T3(i-1)=toc; 
    tic,C=matlabmatrix(A,B);T4(i-1)=toc; 
end 
p1=polyfit(n,T1,3); 
p2=polyfit(n,T2,3); 
n2=1:1:130; 
T21=polyval(p1,n2); 
T22=polyval(p2,n2); 
subplot(2,2,1); plot(n,T1,'O',n2,T21),title('直接求解,O(n^3)') 
subplot(2,2,2); plot(n,T2,'*',n2,T22),title('分治法求解,O(n^3)') 
subplot(2,2,3); plot(n,T3,'-+'),title('Strassen求解,O(n^2^.^8^1)') 
subplot(2,2,4); plot(n,T4,'-x'),title('Matlab自带,O(n^2^.^3^7^6)')