0
$\begingroup$

I am working on a program that tracks a flying object through space and predicts the future position of said object. I was given some equations to use, but some of them do not look right, mainly the equation I was given for finding slope:

slope = (N * sum(t*GCx) - sum(t) * sum(GCx)) / (N * sum(t^2) - sum(t) * sum(t))

I would have thought the slope equation to use in the algorithm would have been

sum for all points((t-average t)*(GCx-average GCx))/sum for all points (t-average t)^2

So which is it and why the difference? Bare in mind that this will be applied to y and z coordinates later as well. t is time.

$\endgroup$
  • 1
    $\begingroup$ We have no idea what all of the symbols in your formulas are. You'll need to be more specific. $\endgroup$ – Wolfgang Bangerth Jan 11 '16 at 19:30
  • $\begingroup$ GCx stands for gimbal centered coordinate x (the x coordinate relative to the gimbal being the origin). I am not sure what N stands for (number of samples taken?) t is time. t^2 means t squared, sum for all points means take this and sum it up with all instances of it. kind of like how to find the average, you find the sum of all instances of GCx and divide by N. $\endgroup$ – cluemein Jan 11 '16 at 20:29
  • $\begingroup$ Why don't you just make a simple kalman filter for this? It may prove to be more robust, especially if the flying object is maneuvering. $\endgroup$ – spektr Jan 11 '16 at 22:28
  • $\begingroup$ I have to use certain specifications given to me, but I think the specs are either wrong or I'm not understanding them properly. The equation I was given was supposed to have been written by a mathematician, but they did a poor job explaining it.. $\endgroup$ – cluemein Jan 11 '16 at 22:31
  • $\begingroup$ They never said or properly explained what t is (other than state its time). Here is what they say for t, and part of the instructions: "Calculate least squares regression on last N points with latest t = 0. T represents time reported with latest track point ". This clarify it a bit more? $\endgroup$ – cluemein Jan 11 '16 at 22:34
3
$\begingroup$

Given you are trying to find a path $f(t) = a + b t$ for each 3D component of an object to define its trajectory, you can formulate a Least Square problem to find the values for $a$ and $b$ based on $N$ pieces of data.

The goal of the least square problem is to minimize the following cost function with respect to $a$ and $b$:

$$J = \frac{1}{2} \sum_{i=1}^{N} ( a + b t_i - y_i )^2$$

given you are provided data pairs $(t_i,y_i) \forall i \in [1,N]$ and that $y_i$ represents the object's coordinate in which ever dimension you are fitting for (because the cost function above is used for each dimension independently).

When you take the derivative of the cost function with respect to $a$ and $b$ and set the two resulting equations equal to 0, you should get the following:

$$aN + b\sum_{i=1}^N t_i = \sum_{i=1}^N y_i$$ $$a\sum_{i=1}^N t_i + b\sum_{i=1}^N (t_i)^2 = \sum_{i=1}^N y_i t_i$$

Solving these equations gives you:

$$ a = \frac{(\sum_{i=1}^N (t_i)^2) (\sum_{i=1}^N y_i) - (\sum_{i=1}^N t_i) (\sum_{i=1}^N y_i t_i)}{N\sum_{i=1}^N (t_i)^2 - (\sum_{i=1}^N t_i)^2}$$

$$ b = \frac{N\sum_{i=1}^N y_i t_i - (\sum_{i=1}^N t_i)(\sum_{i=1}^N y_i)}{N\sum_{i=1}^N (t_i)^2 - (\sum_{i=1}^N t_i)^2}$$

Since $b$ is equivalent to your slope, you can see this equation I derived fits what you were given. This shows you just need to solve this like a typical Least Square problem. If you find a difference between the equations given and the alternate you mentioned, it's because the alternate isn't found using the Least Square approach.

$\endgroup$
  • $\begingroup$ Its been a while since I took math class, could you clarify what some of the letters and symbols mean? I know the sideways M means the sum of, with the bottom number being the start, and the top being the last number (I think.) $\endgroup$ – cluemein Jan 12 '16 at 13:40
  • $\begingroup$ @cluemein Yes, you are right about the summation part. The part under the cost function, talking about the data pairs you are provided, basically just says there are N data pairs, where (t_{i},y_{i}) is the ith data pair. Do you understand the rest of the math then? $\endgroup$ – spektr Jan 12 '16 at 14:31
  • $\begingroup$ I think so. The subcase i indicates that its the t of that i, or the y of that i. Am right? $\endgroup$ – cluemein Jan 12 '16 at 15:20
  • $\begingroup$ @cluemein yes, you are correct! $\endgroup$ – spektr Jan 12 '16 at 15:27
  • $\begingroup$ Going to be a beast to code, but I think I get it. I'm doing this in C. Going to imagine quite a few "for" blocks I imagine.... $\endgroup$ – cluemein Jan 12 '16 at 19:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.