I have gps trackings that I know they fall into a certain pattern - a line with a known angle. How do I find the line that minimizes the distances of the points from it but is in the correct angle?
Unfortunately, I can't post an image for example.
I have gps trackings that I know they fall into a certain pattern - a line with a known angle. How do I find the line that minimizes the distances of the points from it but is in the correct angle?
Unfortunately, I can't post an image for example.
On
Consider your data as points $(x_i,y_i)$ and you have $n$ data points, then you want to find $\beta_1 ,\beta_2$ such that $y\simeq\beta_1+\beta_2x$.
$$
X\beta= \begin{bmatrix}
1 & x_1 \\
1 & x_2 \\
1 & x_3 \\
\vdots & \vdots\\
1 & x_n\\
\end{bmatrix}
\begin{bmatrix}
\beta_1\\
\beta_2\\
\end{bmatrix}=\begin{bmatrix}
y_1\\
y_2\\
\vdots\\
y_n
\end{bmatrix}=y
$$
If you have received lots of data from gps your $X$ matrix is tall and a pseudoinverse can be found as:
$$ X^+=(X^TX)^{-1}X^T $$
And then you can find the solution:
$$ \beta=X^+y $$
It's MATLAB code is
beta=X\y;
See here for more information.
If $\beta_2$ is known and you want to find $\beta_1$ such that, $y-\beta_2x\simeq\beta_1$ then
$$ X\beta= \begin{bmatrix} 1 \\ 1 \\ 1 \\ \vdots\\ 1 \\ \end{bmatrix} \begin{bmatrix} \beta_1\\ \end{bmatrix}=\begin{bmatrix} y_1-\beta_2x_1\\ y_2-\beta_2x_2\\ \vdots\\ y_n-\beta_2x_n \end{bmatrix} $$
$$ X^+=(X^TX)^{-1}X^T=(\begin{bmatrix} 1 & 1 & 1 & \cdots& 1 \end{bmatrix} \begin{bmatrix} 1 \\ 1 \\ 1 \\ \vdots\\ 1 \\ \end{bmatrix})^{-1} \begin{bmatrix} 1 & 1 & 1 & \cdots& 1 \end{bmatrix} $$ And the answer will be:
$$ \beta_1=X^+y=\frac{1}{n}\begin{bmatrix} 1 & 1 & 1 & \cdots& 1 \end{bmatrix}\begin{bmatrix} y_1-\beta_2x_1\\ y_2-\beta_2x_2\\ \vdots\\ y_n-\beta_2x_n \end{bmatrix}$$ $$ \beta_1=\frac{1}{n}\sum_{k=1}^n (y_i-\beta_2x_i) $$
If I well understand, you have a set of $n$ points $(x_1,y_1),(x_2,y_2),...,(x_k,y_k),..., (x_n,y_n)$ and you want to fit a straight line $y=ax+b$ which coefficient $a$ is known.
This is a regression problem of the kind $Y(x)=b$ where $Y(x)=y(x)-ax$
Hense $$b\simeq \frac{1}{n}\sum_{k=1}^n (y_k-ax_k)$$
In this particular case ($a$ known), the adjusted value of $b$ is the same if we consider the orthogonal distances.