A=input('Enter Matrix A: ')
B=input('Enter Matrix B: ')
C=input('Enter Matrix C: ')
n=length(A);
Con=cell(1,n); Obs=Con.';
Con{1}=B; Obs{1}=C;
for m = 2: n
Con{m} = A*Con{m-1};
Obs{m} = Obs{m-1}*A;
end
Con=cell2mat(Con); Obs=cell2mat(Obs);
analyzeIt(Con,"controllable",n)
analyzeIt(Obs,"observable",n)
function analyzeIt(Q,msg,n)
[a,b]=size(Q);
threshold=1e-8; %non-singularity tolerance
if (a==b && rcond(Q)>threshold) || (a~=b && rank(Q)==n)
disp("The system is "+msg)
else
disp("The system is not "+msg)
end
end