# How do I invert my matrix?

I have the following matrix $$M$$: $$\begin{bmatrix} P & p & 0 & 0 \\ pe_1 & Pe_1 & \sqrt{P^2 - p^2}q_1 & \sqrt{P^2 - p^2}r_1 \\ pe_2 & Pe_2 & \sqrt{P^2 - p^2}q_2 & \sqrt{P^2 - p^2}r_2 \\ pe_3 & Pe_3 & \sqrt{P^2 - p^2}q_3 & \sqrt{P^2 - p^2}r_3 \end{bmatrix}$$ with $$P$$, $$p$$ two real numbers such that $$\lvert P\rvert > \lvert p\rvert$$ and $$(\mathbf{e}, \mathbf{q}, \mathbf{r})$$ that forms an orthonormal triad in Euclidean space.

I want to invert the matrix $$M$$.

I tried the following, but got nothing:

Assuming[
RealAbs[P] > RealAbs[p] &&
(Indexed[e, 1])^2 + (Indexed[e, 2])^2 + (Indexed[e, 3])^2 == 1 &&
(Indexed[q, 1])^2 + (Indexed[q, 2])^2 + (Indexed[q, 3])^2 == 1 &&
(Indexed[r, 1])^2 + (Indexed[r, 2])^2 + (Indexed[r, 3])^2 == 1 &&
Indexed[e, 1]*Indexed[q, 1] + Indexed[e, 2]*Indexed[q, 2] +
Indexed[e, 3]*Indexed[q, 3] == 0 &&
Indexed[e, 1]*Indexed[r, 1] + Indexed[e, 2]*Indexed[r, 2] +
Indexed[e, 3]*Indexed[r, 3] == 0 &&
Indexed[q, 1]*Indexed[r, 1] + Indexed[q, 2]*Indexed[r, 2] +
Indexed[q, 3]*Indexed[r, 3] == 0,
inverse[M]]


I also tried

PseudoInverse[M]


but I got a message saying that a very large output was generated and I'm unable to see the output.

Could you please explain how to invert $$M$$ with Mathematica?

• Mathematica uses capital letters for built-in functions, so try Inverse[M] instead of inverse[M] in your first code block. Or better: Simplify[Inverse[M]], since your assumptions will not do anything if you don't use Simplify or some related function. However, I don't expect the inverse to reduce to something small and readable in this case. You can try Simplify[Det[M]*Inverse[M]] and see if that gives a somewhat more compact result. Nov 17, 2020 at 8:22
• The first two columns of M aren't linear independent(except P/p->Infinity||p/P->Infinity , that's why Det[M]==0 and the inverse doesn't exist! Nov 17, 2020 at 8:24
• @UlrichNeumann Well spotted. Nov 17, 2020 at 8:28
• Where is the code of M? we need post the Mathematica code. Nov 17, 2020 at 8:58
• @Ulrich Neumann, Sjoerd Smit: It is not true that the first two columns are linearly dependent. It was not well spotted, but miss-spotted ;-). Nov 17, 2020 at 10:23

Since $$(\vec{e},\vec{q},\vec{r})$$ is an orthonormal triad, and assuming it is right-handed, we should use the identities $$\vec{e}=\vec{q}\times\vec{r}\,$$; $$\hspace{5mm}\vec{e}\cdot(\vec{q}\times\vec{r})=1$$, etc. In particular we have that

ve = Table[Indexed[e, n], {n, 3}];
vq = Table[Indexed[q, n], {n, 3}];
vr = Table[Indexed[r, n], {n, 3}];

ve.Cross[vr, vq] == 1


$$e_3 (q_2 r_1-q_1 r_2)+e_2 (q_1 r_3-q_3 r_1)+e_1 (q_3 r_2-q_2 r_3) = 1$$

Now write the matrix expression, but use the symbol s instead of the square root term.

(*s=Sqrt[P^2-p^2];*)
m = {{P, p, 0, 0},
{p Indexed[e, 1], P Indexed[e, 1], s Indexed[q, 1], s Indexed[r, 1]},
{p Indexed[e, 2], P Indexed[e, 2], s Indexed[q, 2], s Indexed[r, 2]},
{p Indexed[e, 3], P Indexed[e, 3], s Indexed[q, 3], s Indexed[r, 3]}};
m // MatrixForm


$$\left( \begin{array}{cccc} P & p & 0 & 0 \\ p e_1 & P e_1 & s q_1 & s r_1 \\ p e_2 & P e_2 & s q_2 & s r_2 \\ p e_3 & P e_3 & s q_3 & s r_3 \\ \end{array} \right)$$

Now look at the matrix inverse. After a first look, we know to include a factor of P^2-p^2, like this

Simplify[(P^2 - p^2) Inverse[m]]


All of those denominators should look familiar. They are nothing butve.Cross[vr, vq], which we know is 1, and similar expressions. The numerators are also components of cross products. Each cross product is another element of the triad. Sadly, it is only by inspection that we can write

minv = {
1/(P^2 - p^2) {P, -p Indexed[e, 1], -p Indexed[e, 2], -p Indexed[e, 3]},
1/(P^2 - p^2) {-p, P Indexed[e, 1], P Indexed[e, 2], P Indexed[e, 3]},
{0, Indexed[q, 1]/s, Indexed[q, 2]/s, Indexed[q, 3]/s},
{0, Indexed[r, 1]/s, Indexed[r, 2]/s, Indexed[r, 3]/s}};

minv//MatrixForm


$$\left( \begin{array}{cccc} \frac{P}{P^2-p^2} & -\frac{p e_1}{P^2-p^2} & -\frac{p e_2}{P^2-p^2} & -\frac{p e_3}{P^2-p^2} \\ -\frac{p}{P^2-p^2} & \frac{P e_1}{P^2-p^2} & \frac{P e_2}{P^2-p^2} & \frac{P e_3}{P^2-p^2} \\ 0 & \frac{q_1}{s} & \frac{q_2}{s} & \frac{q_3}{s} \\ 0 & \frac{r_1}{s} & \frac{r_2}{s} & \frac{r_3}{s} \\ \end{array} \right)$$

### Verification

We can verify that minv is the (right) inverse of m like this

Assuming[
ve.ve == 1 && vq.vq == 1 && vr.vr == 1 &&
ve.vq == 0 &&
ve.vr == 0 && vq.vr == 0,
Simplify@Inverse[m.minv]] // MatrixForm


$$\left( \begin{array}{cccc} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \\ \end{array} \right)$$

Given

m =
{{P, p, 0, 0},
{p Indexed[e, 1], P Indexed[e, 1], s Indexed[q, 1], s Indexed[r, 1]},
{p Indexed[e, 2], P Indexed[e, 2], s Indexed[q, 2], s Indexed[r, 2]},
{p Indexed[e, 3], P Indexed[e, 3], s Indexed[q, 3], s Indexed[r, 3]}}


and simply changing inverse to Inverse and adding Simplify:

im = Inverse[m] // Simplify


I get

Then evaluating

im.m // Simplify


gives

{{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}}


So it seems to me that your problem is that you made the simple error of writing inverse instead of Inverse and all those assumptions aren't needed.