Polynom NewtonBinomial::expandPolynom(
    double y, unsigned int degree)
{
    Combination combination;

    Polynom polynom;
    polynom.getCoefs().resize(degree + 1);

    for (size_t k=0;k<=degree;k++) {
        polynom.getCoefs()[k] = 
            combination.binomialCoefficient(k, degree)
            * pow(y, degree-k);
    }

    return polynom;
}
Esempio n. 2
0
Polynom CubicSpline::polynomFit(double t, 
    double pos1, double vel1,
    double pos2, double vel2) const
{
    if (t <= 0.00001) {
        throw std::logic_error(
            "CubicSpline invalid spline interval");
    }
    double t2 = t*t;
    double t3 = t2*t;
    Polynom p;
    p.getCoefs().resize(4);
    p.getCoefs()[0] = pos1;
    p.getCoefs()[1] = vel1;
    p.getCoefs()[3] = (vel2 - vel1 - 2.0*(pos2-pos1-vel1*t)/t)/t2;
    p.getCoefs()[2] = (pos2 - pos1 - vel1*t - p.getCoefs()[3]*t3)/t2;

    return p;
}