for (SiteWithPolynomial site : sites) {
List<SiteWithPolynomial> nearestSites =
nearestSiteMap.get(site);
RealVector vector = new ArrayRealVector(SITES_FOR_APPROX);
RealMatrix matrix = new Array2DRowRealMatrix(
SITES_FOR_APPROX, DefaultPolynomial.NUM_COEFFS);
for (int row = 0; row < SITES_FOR_APPROX; row++) {
SiteWithPolynomial nearSite = nearestSites.get(row);
DefaultPolynomial.populateMatrix(matrix, row, nearSite.pos.x, nearSite.pos.z);
vector.setEntry(row, nearSite.pos.y);
}
QRDecomposition qr = new QRDecomposition(matrix);
RealVector solution = qr.getSolver().solve(vector);