
function C=mult_matrices(A,B)
   n=size(A,1);
   C=zeros(n,n);
   for i=1:n
     for j=1:n
       for k=1:n
       C(i,j)= C(i,j)+A(i,k)*B(k,j);
       end
     end
   end
endfunction

function C=strassen(A,B)
   n=size(A,1);    
   n2=n/2;
   if (n2==4)
     C=A*B;   
     return;
   end
// Decomposition en sous blocs
   A11=A(1:n2,1:n2);     A12=A(1:n2,n2+1:n);
   A21=A(n2+1:n,1:n2);   A22=A(n2+1:n,n2+1:n);
 
   B11=B(1:n2,1:n2);     B12=B(1:n2,n2+1:n);
   B21=B(n2+1:n,1:n2);   B22=B(n2+1:n,n2+1:n);

// Evaluation recurrente de 7 produits matriciels 
   M1=strassen((A11+A22),(B11+B22));
   M2=strassen((A21+A22),B11);       
   M3=strassen(A11,(B12-B22));
   M4=strassen(A22,(B21-B11));       
   M5=strassen((A11+A12),B22);
   M6=strassen((A21-A11),(B11+B12)); 
   M7=strassen((A12-A22),(B21+B22));

   C=[(M1+M4-M5+M7),(M3+M5);(M2+M4),(M1-M2+M3+M6)];
endfunction


A=rand(256,256); 
B=A';
clear C
timer();C=mult_matrices(A,B);t1=timer()
clear C
timer();C=strassen(A,B);t2=timer()
clear C
timer(); C=A*B; t3= timer()
printf("\n Temps pour la boucle : %f, l algorithme de Strassen : %f", t1,t2)
printf("\n       pour * de Scilab : %f\n", t3)


