% This computes kron(A,B)*kron(C,D), kron(AC,BD), and compares the two.
% David Bloore, August 2011

pause on;

n=input('n?');

A=toeplitz([2 -1 zeros(1,n-2)]);

B=A;
B(1,1)=1;
B(n,n)=1;

C=A;
C(1,n)=-1;
C(n,1)=-1;

D=A;
D(1,1)=1;

E=kron(A,B);
F=kron(C,D);
G=A*C;
H=B*D;
I=E*F;
J=kron(G,H);

display('Our 4 Matrices are:');
display(A);
display(B);
display(C);
display(D);

display('Press any key to continue');
pause;
display('');

display('The Kronecker Product of');
display(A);
display('and');
display(B);
display('is E=kron(A,B)');
display(E);

display('Press any key to continue');
pause;
display('');

display('The Kronecker Product of');
display(C);
display('and');
display(D);
display('is F=kron(C,D)');
display(F);

display('Press any key to continue');
pause;
display('');

display('The Product of');
display(E);
display('and');
display(F);
display('is I=E*F');
display(I);

display('Press any key to continue');
pause;
display('');

display('The Product of');
display(A);
display('and');
display(C);
display('is G=A*C');
display(G);

display('Press any key to continue');
pause;
display('');

display('The Product of');
display(B);
display('and');
display(D);
display('is H=B*D');
display(H);

display('Press any key to continue');
pause;
display('');

display('The Kronecker Product of');
display(G);
display('and');
display(H);
display('is J=kron(G,H)');
display(J);

display('Press any key to continue');
pause;
display('');

if I==J
    display('As we can see');
    display(I);
    display('equals');
    display(J);
else
    display('As we can see');
    display(I);
    display('does not equal');
    display(J);
end