function [C] = MMblock(A,B)
%
% Przykladowe uzycie 
% A=rand(100,100);
% B=rand(100,100);
% C=MMblock(A,B);
% Macierze musza byc kwadratowe
% Opuszczenie ; powoduje wypisywanie wynik?w linii
%  tic; C=MMblock(A,B); toc %zmierz czas i wypisz
%
  sza = size(A);
  szb = size(B);
  if(sza(1)!=szb(1) || sza(2)!=szb(2))
    disp('Nie odpowiednie rozmiary macierzy');
    return
  endif
  n = sza(1);
  if(n==2)
    C(1,1)=A(1,1)*B(1,1)+A(1,2)*B(2,1);
    C(1,2)=A(1,1)*B(1,2)+A(1,2)*B(2,2);
    C(2,1)=A(2,1)*B(1,1)+A(2,2)*B(2,1);
    C(2,2)=A(2,1)*B(1,2)+A(2,2)*B(2,2);
    return
  endif
  nhalf = n/2;
%  C(1,1)=A(1,1)*B(1,1)+A(1,2)*B(2,1)
  C(1:nhalf,1:nhalf) = MMblock(A(1:nhalf,1:nhalf),B(1:nhalf,1:nhalf))+...
    MMblock(A(1:nhalf,nhalf+1:n),B(nhalf+1:n,1:nhalf));
%  C(1,2)=A(1,1)*B(1,2)+A(1,2)*B(2,2)
  C(1:nhalf,nhalf+1:n) = MMblock(A(1:nhalf,1:nhalf),B(1:nhalf,nhalf+1:n))+...
    MMblock(A(1:nhalf,nhalf+1:n),B(nhalf+1:n,nhalf+1:n));
%  C(2,1)=A(2,1)*B(1,1)+A(2,2)*B(2,1)
  C(nhalf+1:n,1:nhalf) = MMblock(A(nhalf+1:n,1:nhalf),B(1:nhalf,1:nhalf))+...
    MMblock(A(nhalf+1:n,nhalf+1:n),B(nhalf+1:n,1:nhalf));
%  C(2,2)=A(2,1)*B(1,2)+A(2,2)*B(2,2)
  C(nhalf+1:n,nhalf+1:n) = MMblock(A(nhalf+1:n,1:nhalf),B(1:nhalf,nhalf+1:n))+...
    MMblock(A(nhalf+1:n,nhalf+1:n),B(nhalf+1:n,nhalf+1:n));
  return
endfunction
