1

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.

  • 1
    Welcome to Mathematics Stack Exchange! I would suggest you to explain a little bit how you would try to solve it, at least your thoughts about it, so other people could help you better. Good luck! – iadvd Jul 29 '15 at 08:01

2 Answers2

2

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.

JJacquelin
  • 66,221
  • 3
  • 37
  • 87
1

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) $$

SMA.D
  • 1,467
  • 12
  • 27
  • 1
    If I well understand the question of user3316066, the parameter $\beta_2$ is known and given as an initial input. So, the regression is of lower case (no need to optimise and compute another value for $\beta_2$). – JJacquelin Jul 29 '15 at 08:28
  • Edited to work with both assumptions – SMA.D Jul 29 '15 at 08:48
  • 1
    Thank you for this excellent explanation. It's the best that I found after searching the net for about 15 minutes. – Carlo Wood May 14 '18 at 19:06