Say I have a matrix like $$ M=\left( \begin{array}{c c c} x & xz & w-2x \\ wz^3 & xy & z \\ y^2-z^3 & x+w & z+x^5 \end{array} \right) $$
is it possible to ask Mathematica the rank of $M$, depending on $(x,y,z,w)$ ?
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityI'm not sure how useful it will be (because there are lots of possibilities), but one way to attack this problem is to observe that M loses rank exactly when the determinant goes to zero. So you can use Solve
to investigate. With
M[x_, y_, z_, w_]:={{x, x z, w - 2 x}, {w z^3, x y, z}, {y^2 - z^3, x + w, z + x^5}};
you can try
Solve[Det[M[x, y, z, w]] == 0, {x, y, z, w}]
This gives a very large answer, but maybe there are some insights to be had. Alternatively, you could exploit the fact that the matrix loses rank whenever any of the eigenvalues are zero (this is true because the det is the product of the eigenvalues). So you could instead try:
Solve[Eigenvalues[M[x, y, z, w]] == 0, {x, y, z, w}]
which again gives a fairly large answer.
I'd like to consider this problem from geometric view.
Suppose your original matrix is $m=(r_1,r_2,r_3)^\text{T}$, where $r_i$ are row vectors:
mm = {{x, x z, w - 2 x}, {w z^3, x y, z}, {y^2 - z^3, w + x, x^5 + z}};
So,
The rank-1 condition should be $r_i\times r_j=0 \land r_j\times r_k=0 \land r_k\times r_i=0 $:
rank1Condition = And @@ Flatten[Thread /@ {
Cross[#[[1]], #[[2]]] == 0,
Cross[#[[2]], #[[3]]] == 0,
Cross[#[[3]], #[[1]]] == 0}] &@mm
which can be further reduced by
rank1ConditionReduced = Reduce[rank1Condition, {x, y, z, w}] // ExpandAll;
which is a huge expression:
To verify its validity, we test 5 instances:
AbsoluteTiming[ instance = FindInstance[rank1ConditionReduced, {x, y, z, w}, Complexes, 5];]
{6.508372, Null}
MatrixRank /@ (mm /. instance // N[#, 20] &)
{1, 1, 1, 1, 1}
Similarly we have rank-2 condition $(r_1\times r_2\neq 0\lor r_2\times r_3\neq 0\lor r_3\times r_1\neq 0)\land \text{det}(m)=0$
rank2Condition = And[Or @@ (
And @@ Thread[Cross[#[[1]], #[[2]]] != 0] & /@
Subsets[mm, {2}]),
Det[mm] == 0]
Unfortunately, rank2Condition
takes too long for Reduce
and FindInstance
, maybe some other approach would perform better.
M[x_,y_,z_,w_]:={{x,x z,w-2x},{w z^3,x y,z},{y^2-z^3,x+w,z+x^5}}
MR[x_, y_, z_, w_]:=MatrixRank[M[x,y,z,w]]
For example
MR[1,2,3,4]
With[{x = 0, y = 1, z = 1, w = 0}, MatrixRank[(*the matrix*)]]
). $\endgroup$