# Solving symbolic equation from determinant numerically

In this problem: Intersection of conics using matrix representation , a situation arises where there are two matrices (for example:) $$Q_1 = \begin{bmatrix}1 & 0 & 0\\0 & -1 & 0\\0 & 0 & -2\end{bmatrix}$$ $$Q_2 = \begin{bmatrix}1/2 & 0 & 0\\0 & -1 & 0\\0 & 0 & -1\end{bmatrix}$$

and we must set $$det(\lambda Q_1 + \mu Q_2) = 0$$

Expanding this equation by hand is straight forward - we can group terms, rearrange, recognize the form, and solve: $$(\lambda + \frac{\mu}{2})(-\lambda-\mu)(-2\lambda-\mu) = 0$$

(Note that the expression is not always this "nice" - i.e. when there are less zero terms in the matrices).

However, I am trying to write code to do this. Even simplifying and setting $\lambda=1$, the determinant computation still involves a symbolic variable ($\mu$). Without resorting to a big symbolic manipulation library, is there a different way to solve this procedurally?

-
David, if you prefer to expand an answer to the point of literally destroying the original, post another answer instead. –  Asaf Karagila Mar 4 '13 at 16:40
@AsafKaragila My apologies. I thought it was just expanding the point of xavierm02's post. Is there a way to access my edit that is "under review" so I can post it as a new answer? –  David Doria Mar 4 '13 at 16:50
Sure, math.stackexchange.com/review/suggested-edits/50290 (if you display it as Markdown it should give you the code itself) –  Asaf Karagila Mar 4 '13 at 17:22

$\det(Q_1 + \mu Q_2) = \sum\limits_{k=0}^3a_k\mu^k$

$P=\sum\limits_{k=0}^3a_kX^k\in\mathbb{R}_3[X]$

You need to find the roots of $P$.

Since the polynomial is of degree $3$ or less, you can solve it using a general formula http://en.wikipedia.org/wiki/Cubic_function

-
The determinant expression is a cubic function in $\mu$. That is $\det(Q_1 + \mu Q_2) = \sum\limits_{k=0}^3a_k\mu^k$
If we write the matrix $$Q_1 + \mu Q_2 = \begin{bmatrix}a & b & c\\d & e & f\\g & h & i\end{bmatrix}$$ we can write $$det(Q_1 + \mu Q_2) = aei + bfg + cdh - ceg - bdi - afh$$ Now, each of $a,b,c,d,e,f,g,h,i$ have the form $\alpha + \beta \mu$, and we will refer to these $\alpha$ and $\beta$ as subscripts of the variables. For example, $aei = (a_\alpha + a_\beta\mu)(e_\alpha + e_\beta\mu)(i_\alpha + i_\beta\mu)$. Expanding this, we get $$aei = a_\alpha e_\alpha i_\alpha + a_\alpha e_\alpha i_\beta \mu +\\ a_\alpha e_\beta i_\alpha \mu + a_\alpha e_\beta i_\beta \mu^2 +\\ a_\beta e_\alpha i_\alpha \mu + a_\beta e_\alpha i_\beta \mu^2 +\\ a_\beta e_\beta i_\alpha \mu^2 + a_\beta e_\beta i_\beta \mu^3\\ = a_\alpha e_\alpha i_\alpha +\\ (a_\alpha e_\alpha i_\beta + a_\alpha e_\beta i_\alpha + a_\beta e_\alpha i_\alpha)\mu + \\ (a_\alpha e_\beta i_\beta + a_\beta e_\alpha i_\beta + a_\beta e_\beta i_\alpha) \mu^2 + \\ a_\beta e_\beta i_\beta \mu^3$$ Following this pattern, we can compute the coefficients $a_k$