1
$\begingroup$

I want to fit the polynomial function

$f(x) = \alpha_0 +\alpha_1 x +\alpha_2 x^2 $

using given data such that the errors $y_c-f(x_c)$ are minimized (least squares).

Obtained is the experimental data shown below.

$c $|-2 -1 0 1 2

$x_c|$-2 -1 0 1 2

$y_c|$ 0 0 1 0 0

I want to find $\alpha_0$ , $\alpha_1$ and $ \alpha_2 $.

The least squares solution is formulated as $x^* = (A^TA)^{-1}A^Tb $

I have used

$A = \begin{bmatrix} 1&-2&(-2)^2\\1&-1&(-1)^2\\1&0&0\\1&1&1\\1&2&(2)^2 \end{bmatrix}$, $b = \begin{bmatrix} 0\\0\\1\\0\\0 \end{bmatrix}$

and I get as answer

$\begin{bmatrix} \alpha_0\\\alpha_1\\\alpha_2 \end{bmatrix} = \begin{bmatrix} 0.4857\\0\\-0.1429 \end{bmatrix}$

which is wrong (I've plotted it).

I really hope someone can help me out.

$\endgroup$
7
  • $\begingroup$ Your formula for the least square solution looks like the formula for a $\texttt{linear}$ regression. $\endgroup$ Jul 27, 2015 at 15:42
  • $\begingroup$ @calculus : That's correct: this is linear regression. There is a commonplace mistake among those who haven't studied this, that it's called "linear" because one is fitting a line. That is an error. Fitting polynomials in this way is linear regression. ${}\qquad{}$ $\endgroup$ Jul 27, 2015 at 15:45
  • $\begingroup$ @calculus : See this answer: Why is polynomial regression considered a kind of linear regression? ${}\qquad{}$ $\endgroup$ Jul 27, 2015 at 15:48
  • $\begingroup$ Thanks, I didn't know that. So according to Wiki: Polynomial regression models are usually fit using the method of least squares and is a form of linear regression. But what is then wrong here? Can you please show me how I should tackle this problem then because I want to plot it with the right coefficients? $\endgroup$
    – Steve
    Jul 27, 2015 at 15:49
  • $\begingroup$ @steve See the answer of sepideh. Do you have a different plot ? $\endgroup$ Jul 27, 2015 at 15:53

2 Answers 2

1
$\begingroup$

I have tested your answer by matlab and plotted the points and the 2-d polynomial on a figure in matlab and got the answer:
enter image description here
it seems to be right. The best 2-d polynomial fitting five points will be your answer. why do you think it's wrong?
here's the code I used in matlab:

A=[1 -2 4;1 -1 1;1 0 0;1 1 1;1 2 4]
B=[0;0;1;0;0]
C=((A'*A)^(-1))*A'*B
syms x
f=[1 x x^2]*C
ezplot(f)
hold on
d=[-2;-1;0;1;2]
e=[0;0;1;0;0]
plot(d,e,'r*')
$\endgroup$
0
$\begingroup$

Your method is correct and your numerical answer is correct. Apparently your only mistake is to think you made a mistake. Your $x$ values are in an arithmetic progression: $-2,-1,0,1,2$. Your $y$ values are symmetic about the middle: $0,0,1,0,0$. The largest $y$ value is the one in the middle. Therefore one expects a parabola opening downward, symmetric about the $y$-axis. So you want $\alpha_1=0$ and $\alpha_2<0$, and since the average $y$ value is positive you should see $\alpha_0>0$. And that's just what you've got. The least-squares fit is $$ y = \frac{17}{35} - \frac 1 7 x^2. $$

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .