Generalize for D-degree polynomials LSFitting