polynomial least squares matrix implementation