TITLE: Sum of two quadratic forms
QUESTION [5 upvotes]: Suppose I have two quadratic forms $Q_i(x)=(x-a_i)^T A_i(x-a_i)+c_i$, $i=1,2$ where $x,a_i \in \Bbb{R}^n$ and $A_i$ are positive-definite $n\times n$ matrices.
Then $Q(x)=Q_1(x)+Q_2(x)$ is also a quadratic form, $Q(x)=(x-a)^T A(x-a)+c$, with $A=A_1+A_2$ (easy to see by considering just the quadratic terms).
How do I find $a$ and, especially, $c$?

REPLY [4 votes]: Let's turn to homogenous coordinates. For example, for $n=2$ you get
\begin{align*}
Q(x) &= (x-a)^T\cdot A\cdot (x-a) + c
\\ &=
\begin{pmatrix}x_1\\x_2\\1\end{pmatrix}^T\cdot\begin{pmatrix}
1 & 0 & 0 \\
0 & 1 & 0 \\
-a_1 & -a_2 & 1
\end{pmatrix}\cdot\begin{pmatrix}
A_{1,1} & A_{1,2} & 0 \\
A_{2,1} & A_{2,2} & 0 \\
0 & 0 & c
\end{pmatrix}\cdot\begin{pmatrix}
1 & 0 & -a_1 \\
0 & 1 & -a_2 \\
0 & 0 & 1
\end{pmatrix}\cdot\begin{pmatrix}x_1\\x_2\\1\end{pmatrix}
\\&=
\begin{pmatrix}x_1\\x_2\\1\end{pmatrix}^T\cdot B
\cdot\begin{pmatrix}x_1\\x_2\\1\end{pmatrix}
\\
B &=\begin{pmatrix}
A_{1,1} & A_{1,2} & -(A_{1,1}a_1 + A_{1,2}a_2) \\
A_{2,1} & A_{2,2} & -(A_{2,1}a_1 + A_{2,2}a_2) \\
-(A_{1,1}a_1 + A_{2,1}a_2) &
-(A_{1,2}a_1 + A_{2,2}a_2) &
A_{1,1}a_1^2 + (A_{1,2}+A_{2,1})a_1a_2 + A_{2,2}a_2^2 + c
\end{pmatrix}
\end{align*}
Now you can simply compute the sum of two or more $Q_i$ by adding their $B_i$ matrices. From the upper left $n\times n$ block you can directly deduce the $A$ matrix of the result, just as you already wrote in your question. From the first $n$ entries of the last column you can then deduce the offset vector $a$, since they form a linear system of equations in its coordinates once you know $A$. Other answers have explicitely formulated its solution this using matrix inversion. When you have both $A$ and $a$, you can use the bottom right element to obtain $c$.