# [SOLVED]Method of least square: initial position & velocity

#### mathmari

##### Well-known member
MHB Site Helper
Hey!! A point is moving linearly with constant velocity $v$ and the movement is $x=a+vt$.
The below information is given: Find the initial position $a$ and the velocity using the method of least square.

Could you give me a hint how we use this method here? Couldn't we use the data of the matrix and get a $2\times 2$ linear system? #### Klaas van Aarsen

##### MHB Seeker
Staff member
A point is moving linearly with constant velocity $v$ and the movement is $x=a+vt$.
The below information is given:

Find the initial position $a$ and the velocity using the method of least square.

Could you give me a hint how we use this method here?
Hey mathmari !!

The method of least squares is that we minimize the sum of the squared deviations $\sum\limits_{i=1}^n (x_i - x(t_i))^2$, isn't it? We should be able to find formulas for it somewhere, either in matrix form or in formula form.
Or we can derive those formulas ourselves.
Or we can use a tool like Excel to do it for us. Couldn't we use the data of the matrix and get a $2\times 2$ linear system?
Which $2\times 2$ linear system do you mean? #### mathmari

##### Well-known member
MHB Site Helper
The method of least squares is that we minimize the sum of the squared deviations $\sum\limits_{i=1}^n (x_i - x(t_i))^2$, isn't it? We should be able to find formulas for it somewhere, either in matrix form or in formula form.
Or we can derive those formulas ourselves.
Or we can use a tool like Excel to do it for us. Ah I think now I have an idea how we have to apply the method in this case.

From the matrix we have the exact values of $x_i$'s and from the formula of the movement we get an approximation $x(t_i)$, or not?

So we get \begin{align*}\sum\limits_{i=1}^5 (x_i - x(t_i))^2&=(x_1 - x(t_1))^2+(x_2 - x(t_2))^2+(x_3 - x(t_3))^2+(x_4 - x(t_4))^2+(x_5 - x(t_5))^2 \\ & =(-11 - [a-2v])^2+(-5 - [a-v])^2+(1 - a)^2+(5 - [a+v])^2+(10 - [a+2v])^2\end{align*} #### HallsofIvy

##### Well-known member
MHB Math Helper
What do you mean by "the initial position"? I would think that would be x(0) but the table itself tells you that x(0)= 1. There is no calculation at all required for that!

#### Klaas van Aarsen

##### MHB Seeker
Staff member
Ah I think now I have an idea how we have to apply the method in this case.

From the matrix we have the exact values of $x_i$'s and from the formula of the movement we get an approximation $x(t_i)$, or not?

So we get \begin{align*}\sum\limits_{i=1}^5 (x_i - x(t_i))^2&=(x_1 - x(t_1))^2+(x_2 - x(t_2))^2+(x_3 - x(t_3))^2+(x_4 - x(t_4))^2+(x_5 - x(t_5))^2 \\ & =(-11 - [a-2v])^2+(-5 - [a-v])^2+(1 - a)^2+(5 - [a+v])^2+(10 - [a+2v])^2\end{align*}
Yep.
We can minimize that with respect to $a$ and $v$ can't we? What do you mean by "the initial position"? I would think that would be x(0) but the table itself tells you that x(0)= 1. There is no calculation at all required for that!
The value of $x(0)$ given in the table is a measurement.
The approximation of $a$ is the approximation of $x(0)$ based on a linear least square interpolation.
The question asks for $a$, which should be a more accurate version of the position at time $t=0$.

#### mathmari

##### Well-known member
MHB Site Helper
Yep.
We can minimize that with respect to $a$ and $v$ can't we? For that we use the gradient, don't we? \begin{align*}S(a,v)=&(-11 - [a-2v])^2+(-5 - [a-v])^2+(1 - a)^2+(5 - [a+v])^2+(10 - [a+2v])^2 \\ =&11^2 +22[a-2v]+ [a-2v]^2+5^2 +10[a-v]+ [a-v]^2+1 -2a+ a^2+5^2 -10[a+v]+ [a+v]^2\\ & +10^2 -20[a+2v]+ [a+2v]^2 \\ =&121 +22a-44v+ a^2-4av+4v^2+25 +10a-10v+ a^2-2av+v^2+1 -2a+ a^2\\ &+25 -10a-10v+ a^2+2av+v^2+100 -20a-40v+ a^2+4av+4v^2 \\ =& 5a^2+10v^2-104v+272 \end{align*}

The partial derivatives are:
\begin{align*} & \frac{\partial{S}}{\partial{a}}= 10a \\ & \frac{\partial{S}}{\partial{v}} = 20v-104 \end{align*}

We set these partial derivatives equal to zero and we get \begin{align*} & \frac{\partial{S}}{\partial{a}}= 0 \Rightarrow 10a=0 \Rightarrow a=0 \\ & \frac{\partial{S}}{\partial{v}} = 0 \Rightarrow 20v-104=0 \Rightarrow v=\frac{104}{20} \Rightarrow v=5.2 \end{align*}

Is everything correct? #### Klaas van Aarsen

##### MHB Seeker
Staff member
We set these partial derivatives equal to zero and we get \begin{align*} & \frac{\partial{S}}{\partial{a}}= 0 \Rightarrow 10a=0 \Rightarrow a=0 \\ & \frac{\partial{S}}{\partial{v}} = 0 \Rightarrow 20v-104=0 \Rightarrow v=\frac{104}{20} \Rightarrow v=5.2 \end{align*}

Is everything correct?
The answer is correct so I think the intermediate steps are correct as well. #### mathmari

##### Well-known member
MHB Site Helper
The answer is correct so I think the intermediate steps are correct as well. How did you get the correct answer? Is there also an other method we can use? Or is there an online tool? Staff member

#### mathmari

##### Well-known member
MHB Site Helper
I entered the data in Excel and used the [M]LINEST[/M] array function to get the result. Ahh! Interesting! Thank you!!  