Why is det(A) sometimes =/= det(A') for random square matrices
Show older comments
Hello,
I have been sitting on this for a few hours now.
A few months ago, during a practice session, we were asked to show proof that
det(A) == det(A')
with A being a random 3x3 matrix, or in general nxn matrix. The task asks for 3x3, but it should be the same as long as it is a square matrix.
Back then I didn't loop this for several repetitions, and just got the right answer when checking first time. Later on I decided to just repeat it several times, expecting to get the same answer every time. For reasons I don't understand, this is not the case, and I don't understand why that is the case.
I used the following code to test this "quickly":
% Preallocating and Setting Reps
NReps=1000;
Sol=zeros(1,NReps);
Result_Zero=zeros(1,NReps);
Result_One=zeros(1,NReps);
% Calcing
for k=1:1:NReps
for j=1:1:NReps
NR6.A=randi([-100,100],[3,3]);
NR6.detA=det(NR6.A);
NR6.detAtransp=det(NR6.A');
Sol(j)=isequal(NR6.detA,NR6.detAtransp);
end
Result_Zero(k)=nnz(Sol(:)==0);
Result_One(k)=nnz(Sol(:)==1); % this is what should happen, but it does ony do so in ~50%
end % of all cases. I have no clue why, or why it is not a 100% either way
x=1:1:NReps; % at least, instead of this.
clc; close all
% Evaluation
hold on
plot(x,Result_Zero,'-r')
plot(x,Result_One,'-b')
legend('Result: 1 (red)','Result: 0 (blue)','Location','east') % for some reason, my matlab instance doesn't actually display the
% color next to the text in the legend unless I export the figure into
% f.e. word. No clue why that happens.
As I understand it, I should not get any "red" cases, i.e. where
Result_One(k)=nnz(Sol(:)==1);
is all I get.

Now, pretty obviously this is not the case, and I don't know if this is just me not knowing something about matrix calculations, or doing something wrong in-code. Doing a bit of digging, I couldn't find any reason why this behaviour happens.
I can't find any problems with this code myself, and in my opinion this should work perfectly.
What am I missing?
Thank you & stay healthy,
C.A.
Accepted Answer
More Answers (0)
Categories
Find more on Linear Algebra in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!