% 1 
A = [2 -1 3;0 4 5; -2 1 4]
B = [8 -3 -5; 0 1 2; 4 -7 6]
C = [0 -2 3; 1 7 4; 3 5 9];
a = 4
b = -7


% the matrices below should all compute to 0

aa = A+(B+C) - ( (A+B) + C )

bb = (A*B)*C - A*(B*C)

cc = (a+b)*C - a*C - b*C

dd = a*(B-C) - a*B + a*C


% number 3

aa = (A')' - A

bb = (A+B)' - A' - B'

cc = (3*C)' - 3*C'

dd = (A*B)' - B'*A'

% number 5, these should all be zero

aa = trace(A') - trace(A)

bb = trace(3*A) - 3*trace(A)

cc = trace(A+B) - trace(A)-trace(B)

dd = trace(A*B) - trace(B*A)

% number 11, these should all be *essentially zero*

A = rand(2)
B = rand(2)
C = rand(2)

aa = inv(A*B) - inv(B)*inv(A)

bb = inv(A*B*C) - inv(C)*inv(B)*inv(A)


% T1

A = [1 2 -3 0; 1 1 -2 1; 2 1 3 4; -3 2 2 -8];
A^2
A^3
A^10

% T4

A = [0 1/2 1/3; 1/4 0 1/5; 1/6 1/7 0];
for i = 1:100; 
		A^i
end

% these powers all approach the zero matrix

% T6

A = [ 0 0 0 0; 1 0 0 0; 2 1 0 0 ; -3 2 2 0];
B = [0 0 0 0; 1 0 0 0; 2 1 0 0; 0 2 0 0];

i = 1;
while i < 100; 
		i = i+1;
		disp(A^i)
		if max(max(A^i)) == 0;
				disp(['index of nilptency is ', num2str(i)])
				i = 100;
		end

end


% T7
disp('Starting T7')

a = 2;
A = [a 1; 0 a]; 
t = pi/4;
B = [cos(t) sin(t); -sin(t) cos(t)];

for i = 1:100; 
		disp(A^i)
		pause
		if max(max(A^i)) == 0;
				disp(['index of nilptency is ', num2str(i)])
				return
		end
end

