Pong

June 1st 2015, GPS Smoothing Example Continued

May 27th 2015 GPS Smoothing Example | | June 2nd 2015 GPS Smoothing Example Continued

The next step is to implement a Weighted Least Squares solver (WLS solver for short), which takes the measurements $p_i$ at time points $t_i$ with according weights $w_i$ as input and outputs the coefficients $c_0, c_1$ and $c_2$ of the fitted curve.

We use the WLS solver module of libmini for that purpose:

An example application of the module:

WLS_Point p1={-1,1,1};
WLS_Point p2={0,1,1};
WLS_Point p3={1,3,1};

miniWLS wls;
wls.push_back(p1);
wls.push_back(p2);
wls.push_back(p3);

wls.quadratic_fit();
vec3 c=wls.coefficients();

std::cout << "coefficients: " << c << std::endl;

This code snippet fits a quadratic polynomial $f(t)=c_0+c_1t+c_2t^2$ to the points (−1,1), (0,1) and (1,3) with the weights 1, 1 and 1.

The corresponding coefficients are

$c_0 = 1$
$c_1 = 1$
$c_2 = 1$

Let’s check:

$f(-1) = 1+1\cdot-1+1\cdot-1^2 = 1$
$f(0) = 1+1\cdot0+1\cdot0^2 = 1$
$f(1) = 1+1\cdot1+1\cdot1^2 = 3$

Fits!

May 27th 2015 GPS Smoothing Example | | June 2nd 2015 GPS Smoothing Example Continued

Options: