I'm trying to fit a quadratic $a\_0 + a\_1x + a\_2x^2$ by Polynomial Regression:


$$
\begin{pmatrix}
n & \Sigma x\_i & \Sigma x\_i\\
\Sigma x\_i & \Sigma x\_i^2 & \Sigma x\_i^3\\
\Sigma x\_i^2 & \Sigma x\_i^3 & \Sigma x\_i^4\\
\end{pmatrix}
\begin{pmatrix}
a\_0\\
a\_1\\
a\_2\\
\end{pmatrix}=
\begin{pmatrix}
\Sigma y\_i\\
\Sigma x\_iy\_i\\
\Sigma x\_i^2y\_i\\
\end{pmatrix}
$$
by Gaussian Elimination on the augmented matrix:
$$
\left[
\begin{array}{ccc|c}
n & \Sigma x\_i & \Sigma x\_i & \Sigma y\_i\\
\Sigma x\_i & \Sigma x\_i^2 & \Sigma x\_i^3 & \Sigma x\_iy\_i\\
\Sigma x\_i^2 & \Sigma x\_i^3 & \Sigma x\_i^4 & \Sigma x\_i^2y\_i\\
\end{array}
\right]
$$


I'm not a matrix whizz, so how do I solve this using the same method when I know I want the y-intercept of the curve, $a0$, to be 0?



Fitting a quadratic using regression when the y-intercept needs to be 0
If you want $a\_0$ to be $0$, then the curve you are trying to fit has equation $y = a\_1 x + a\_2 x^2$. If you derive the normal equations starting from this equation, you get


$a\_1 \sum x\_i^2 + a\_2 \sum x\_i^3 = \sum x\_i y\_i\\
a\_1 \sum x\_i^3 + a\_2 \sum x\_i^3 = \sum x\_i^2 y\_i$


Or


$\left[\begin{array}{cc|c}
\sum x\_i^2 & \sum x\_i^3 & \sum x\_i y\_i\\
\sum x\_i^3 & \sum x\_i^4 & \sum x\_i^2 y\_i
\end{array}\right]$


**Derivation of Normal Equations**  

$y = a\_1 x + a\_2 x^2$


The error $\epsilon\_i$ in the $i$th term is the difference between the predicted value $y(x\_i)$ and the observed value $y\_i$:  

$\epsilon\_i = y(x\_i) - y\_i = a\_1 x\_i + a\_2 x\_i^2 - y\_i$


The total error is the sum of squares of these errors:  

$E = \displaystyle\sum\_i \epsilon\_i^2 = \displaystyle\sum\_i(a\_1x\_i + a\_2x\_i^2 - y\_i)^2$


To find the values of the parameters $a\_1$ and $a\_2$ that minimize the total error, let $\dfrac{\partial E}{\partial a\_1} = \dfrac{\partial E}{\partial a\_2} = 0$:


$
\dfrac{\partial E}{\partial a\_1} = \sum 2x\_i(a\_1 x\_i + a\_2 x\_i^2 - y\_i) = 0 \Rightarrow a\_1 \sum x\_i^2 + a\_2 \sum x\_i^3 = \sum x\_i y\_i\\
\dfrac{\partial E}{\partial a\_2} = \sum 2x\_i^2(a\_1 x\_i + a\_2 x\_i^2 - y\_i) = 0 \Rightarrow a\_1 \sum x\_i^3 + a\_2 \sum x\_i^4 = \sum x\_i^2 y\_i\\
$


