# Solving a Set of Linear Equations Not Working Correctly

I'm trying to solve the following homogeneous equation:

$$S.B=\tilde{B}.S$$

Where

$$\tilde{B}$$ is a diagonal matrix.

Here is the code:

$$S=\text{LinearSolve}\left[\left( \begin{array}{ccc} c_1 & -c_2 & 0 \\ 0 & c_3 & -c_1 \\ 0 & 0 & c_2 \\ \end{array} \right).\left( \begin{array}{ccc} \lambda _1 & -\lambda _1 & 0 \\ 0 & \lambda _2 & -\lambda _2 \\ 0 & 0 & \lambda _3 \\ \end{array} \right),\left( \begin{array}{ccc} \lambda _1 & 0 & 0 \\ 0 & \lambda _2 & 0 \\ 0 & 0 & \lambda _3 \\ \end{array} \right).\left(\begin{array}{ccc} c_1 & -c_2 & 0 \\ 0 & c_3 & -c_1 \\ 0 & 0 & c_2 \\ \end{array} \right)\right]$$

Where

$$S = \left( \begin{array}{ccc} c_1 & -c_2 & 0 \\ 0 & c_3 & -c_1 \\ 0 & 0 & c_2 \\ \end{array} \right)$$

$$B=\left( \begin{array}{ccc} \lambda _1 & -\lambda _1 & 0 \\ 0 & \lambda _2 & -\lambda _2 \\ 0 & 0 & \lambda _3 \\ \end{array} \right)$$

$$\tilde{B} = \left( \begin{array}{ccc} \lambda _1 & 0 & 0 \\ 0 & \lambda _2 & 0 \\ 0 & 0 & \lambda _3 \\ \end{array} \right)$$

The quantity $$S.B.S^{-1}$$ should be equal to the diagonal matrix $\tilde{B}$

Any help would be great - Thanks!

Here is the raw code:

 S = LinearSolve[( {
{Subscript[c, 1], -Subscript[c, 2], 0},
{0, Subscript[c, 3], -Subscript[c, 1]},
{0, 0, Subscript[c, 2]}
} ).( {
{Subscript[λ, 1], -Subscript[λ, 1], 0},
{0, Subscript[λ, 2], -Subscript[λ, 2]},
{0, 0, Subscript[λ, 3]}
} ), ( {
{Subscript[λ, 1], 0, 0},
{0, Subscript[λ, 2], 0},
{0, 0, Subscript[λ, 3]}
} ).( {
{Subscript[c, 1], -Subscript[c, 2], 0},
{0, Subscript[c, 3], -Subscript[c, 1]},
{0, 0, Subscript[c, 2]}
} )]

• From the docs: "LinearSolve[m,b] finds an x that solves the matrix equation m.x==b." Oct 20, 2016 at 0:10
• How do you copy-past in MMA via Mathematica?
– PiE
Oct 20, 2016 at 0:10
• The code looks "funky" when I paste it...
– PiE
Oct 20, 2016 at 0:11

Your code attempts to solve a matrix equation S.B.x==Bdiag.S - read the docs of LinearSolve.

The matrix equation you want to solve is

S = {{c1, -c2, 0}, {0, c3, -c1}, {0, 0, c2}};
B = {{L1, -L2, 0}, {0, L2, -L2}, {0, 0, L3}};
Bdiag = DiagonalMatrix[{L1, L2, L3}];

Solve[S.B == Bdiag.S, {c1, c2, c3}]


{{c1 -> 0, c2 -> 0, c3 -> 0}}

which gives only a trivial solution. I guess what you really want to do is find the eigenvectors:

Eigenvalues[B]


{L1, L2, L3}

s = Transpose @ Eigenvectors[B]


{{1, L2/(L1 - L2), -(L2^2/((L2 - L3) (-L1 + L3)))}, {0, 1, L2/( L2 - L3)}, {0, 0, 1}}

Inverse[s].B.s // FullSimplify


{{L1, 0, 0}, {0, L2, 0}, {0, 0, L3}}

The last line shows that the equation is indeed satisfied with the solution.

• This looks correct - Thank you! I have one more question - It seems when I use subscripts I get a different answer (an incorrect one). Is that right or am I doing something wrong?
– PiE
Oct 20, 2016 at 0:33
• @PierreMFiorini Subscripts rarely behave like expected. They should be avoided if possible. Oct 20, 2016 at 9:52

For advice on (not) using subscripts, please take a look at these basic syntax issues.

As to your system of equations, there may be solutions for particular values of the $\lambda's$. Let's take another look at the equation(s) you want to solve, not using subscripts (or capital letters for variable names). First, consider these commands

s = {{c1, -c2, 0}, {0, c3, -c1}, {0, 0, c2}};
b = {{λ1, -λ1, 0}, {0, λ2, -λ2},
{0, 0, λ3}};
c = DiagonalMatrix[{λ1, λ2, λ3}];

eqn // ColumnForm


which give us the following rows of the matrix eqn

$\begin{array}{l} \{\text{c1} \text{$\lambda $1},-\text{c1} \text{$\lambda $1}-\text{c2} \text{$\lambda $2},\text{c2} \text{$\lambda $2}\}=\{\text{c1} \text{$\lambda $1},-\text{c2} \text{$\lambda $1},0\} \\ \{0,\text{c3} \text{$\lambda $2},-\text{c3} \text{$\lambda $2}-\text{c1} \text{$\lambda $3}\}=\{0,\text{c3} \text{$\lambda $2},-\text{c1} \text{$\lambda $2}\} \\ \text{True} \\ \end{array}$

The last row is an identity for all values of our variables. Let's apply Thread again, like this

eqs = Union@Flatten[Thread /@ eqn];
eqs // ColumnForm


Now we have the following equations in the list eqs

$\begin{array}{l} \text{True} \\ c2 \lambda2 = 0 \\ -c1 \lambda1-c2 \lambda2 =-c2\lambda1 \\ -c3 \lambda2-c1 \lambda3=-c1\lambda2 \\ \end{array}$

So now we can almost find solutions by hand. However, let's use the Reduce command like this

Reduce[eqs] // ColumnForm


Now we have the following list of possible solutions:

$\begin{array}{c} \text{$\lambda $3}=0\land \text{$\lambda $2}=0\land \text{$\lambda $1}=0 \\ \text{$\lambda $2}=0\land \text{c2}=0\land \text{$\lambda $1}\neq 0\land \text{c1}=0 \\ \text{$\lambda $2}=0\land \text{$\lambda $1}=0\land \text{c1}=0\land \text{$\lambda $3}\neq 0 \\ \text{$\lambda $2}=0\land \text{$\lambda $1} \text{$\lambda $3}\neq 0\land \text{c2}=0\land \text{c1}=0 \\ \text{$\lambda $3}=0\land \text{$\lambda $2}=0\land \text{$\lambda $1}=0\land \text{c2}=0 \\ \text{$\lambda $3}=0\land \text{$\lambda $2}=0\land \text{$\lambda $1}\neq 0\land \text{c1}=\text{c2} \\ \text{$\lambda $1} \text{$\lambda $2}\neq 0\land \text{c3}=0\land \text{c2}=0\land \text{c1}=0 \\ \text{$\lambda $1}=0\land \text{c2}=0\land \text{$\lambda $2}-\text{$\lambda $3}\neq 0\land \text{c1}=\frac{\text{c3} \text{$\lambda $2}}{\text{$\lambda $2}-\text{$\lambda $3}}\land \text{$\lambda $2}\neq 0 \\ \text{$\lambda $2}=0\land \text{$\lambda $1}=0\land \text{c2}=0\land \text{$\lambda $3}\neq 0\land \text{c1}=0 \\ \text{$\lambda $2}=\text{$\lambda $3}\land \text{$\lambda $1}=0\land \text{c3}=0\land \text{c2}=0\land \text{$\lambda $3}\neq 0 \\ \end{array}$

The tent-like $\land$ in the above should be a double-and, like &&. Some of the above solutions may tell us something about our system equations, like what conditions are required for a solution to exit.