# Linear Regression to quadratic function

What is the optimal linear regression (w and w/o y-intercept) for a quadratic curve w.r.t. mean square error.

Mathematically speaking:

Given,

$$y = x^2$$

for

$$x = [-a,a]$$.

What is the best approximation for straight line equations of the form.

$$y = \alpha x$$

and

$$y = \alpha x + \beta$$.

cftool in MATLAB can solve it numerically, but I had rather have a closed form analytical solution if it exists.

-
Since $y=\alpha x$ is a subset of $y=\alpha x+\beta$ (set $\beta=0$), you would naturally choose this unless you had a good reason to specify that the line must pass through the origin. – Daryl Mar 9 '13 at 9:43
I need it to pass through the origin – aiao Mar 9 '13 at 9:44
I don't have the time to verify, but because your actual function is even $(x^2)$ and the approximation is the odd function $y=\alpha x+\beta$, you should always find that $\alpha=0$. I cannot verify that claim at the moment however. – Daryl Mar 9 '13 at 9:50

How do you measure error? Do you want to do a least squares fit? Then you have to minimize

$$\int_{-a}^a(x^2-(\alpha x+\beta))^2dx$$

which can easily be done by solving the below system for $\alpha$ and $\beta$

$$\frac{\partial}{\partial \alpha}\int_{-a}^a(x^2-(\alpha x+\beta))^2dx=0$$ $$\frac{\partial}{\partial \beta}\int_{-a}^a(x^2-(\alpha x+\beta))^2dx=0.$$

-
lower limit of integral should be $-a$ :) – Aang Mar 9 '13 at 10:26
Of course, ;-) otherwise the answer is REALLY easy. – Fixed Point Mar 9 '13 at 10:45

It would be the line $y=\alpha x$ such that $$\int_{-a}^a\big|x^2-\alpha x\big|dx$$ is minimum

-