Mathematica - Determinant
Posted on April 4, 2021
Tags: mathematica
AArrow[{p_, q_}, label_:""] := {Inset[Style[label,Purple],Midpoint[{p,q}]], Arrow[{p,q}]};
vec2[p_] := Graphics@AArrow[{ConstantArray[0,Length[p]],p}];
vec2[p_,q_] := Which[ ArrayQ[q] == False, Graphics@AArrow[{ConstantArray[0,Length[p]],p},q],
ArrayQ[q] == True, Graphics@AArrow[{p,q},""] ]
vec2[p_,q_,label_] := Graphics@AArrow[{p,q},label];
vec[p_] := Which[ Length[p] == 2, vec2[p],
Length[p] == 3, vec2[p] /. Graphics -> Graphics3D ];
vec[p_,q_] := Which[ Length[p] == 2, vec2[p,q],
Length[p] == 3, vec2[p,q] /. Graphics -> Graphics3D ];
vec[p_,q_,label_] := Which[ Length[p] == 2,vec2[p,q,label],
Length[q] == 3,vec2[p,q,label] /. Graphics -> Graphics3D];
sty[c__:Red] := (# /. Arrow[x__] -> {c, Arrow[x]})&
(* sty[Red]@vec[{3,5}]*)
matrix[expr_] := expr /. List[p__]-> MatrixForm[List[p]]
cout[x__] := TeXForm[Row[{x}]];
pnt[x_] := Graphics3D@Point[x];
(* polynomial *)
(* helper functions *)
vars[n_, m_] := Flatten@Transpose[Outer[Symbol@StringJoin[##] &, CharacterRange["A", "Z"][[;; m]], ToString /@ Range[n]]]
polyvar[v_] := Flatten[{1,vars[v-1,1]}];
(* Give a list of coefficents and it will generate a polynomial with variables *)
poly[coef_] := Transpose[coef].polyvar[Length@coef];
poly@Thread[{{1,2,3}}];
T := Transpose;
Dim = Dimensions;
Ones[n_] := ConstantArray[1,n]
addCol[x_] := MapThread[Append, {#, x}] &
(* addCol[ConstantArray[1,2]]@{{1,3},{3,4}} // matrix*)
addRow[x_] := Append[#,x]&- Determinant of 1 = means energy is conserved = area is conserved
- Determinant of -1 = means energy is inverted
- Determinant of trivial matrix = \(\Pi\)MainDiagonal - \(\Pi\)MinDiagonal
basisX = {0,1};
basisY = {1,0};
rotation = {{0,1},{1,0}};
rotmat[x_] = {{Cos[x],Sin[x]},{-Sin[x],Cos[x]}};
Inactive[Det][matrix@{{a,b},{c,d}}] == Det[{{a,b},{c,d}}]
rotmat[Pi] // matrix
rotmat[Pi/4] // matrixSVD[matrix@rotmat[Pi]] == matrix /@ SingularValueDecomposition[rotmat[Pi]] - Notice how the middle matrix of the SVD is a diagonal matrix and when you multiply the diagonal you get the determinant.