/** * Compute the matrix R with the method Gram Schmidt * @attribute n, number of rows and columns of Q, A and R. * @attribute Q, matrix Q. * @attribute A, matrix A. * @attribute R, matrix R. */ void matrixR(int n, double **Q, double **A, double **R) { double **QTrans; createMatrix(&QTrans, n, n); transposedMatrix(n, n, Q, QTrans); multiplicationMatrix(n, n, QTrans, A, R); destroyMatrix(&QTrans, n, n); }
Table_quadruplet least_squares_approximation(Table_triplet points, Booleen uniformConf) { int i, j; Table_quadruplet res; res.nb = points.nb; ALLOUER(res.table, points.nb); Table_flottant steps = steps_computation(points, uniformConf); double ** B; ALLOUER(B, points.nb); for(i = 0; i < points.nb; i++) ALLOUER(B[i], points.nb); B[0][0] = B[points.nb - 1][points.nb - 1] = 1; for(i = 1; i < points.nb; i++) B[0][i] = 0; for(i = 0; i < points.nb; i++) { for(j = 1; j < points.nb - 1; j++) { B[j][i] = bernsteinPolynomial(i, points.nb - 1, steps.table[j]); } } for(i = 0; i < points.nb - 1; i++) B[points.nb - 1][i] = 0; double ** BT = transposedMatrix(B, points.nb); Grille_flottant Aprime; Aprime.nb_lignes = Aprime.nb_colonnes = points.nb; Aprime.grille = matrix_matrix_mult(B, BT, points.nb); for(i = 0; i < points.nb; i++) free(BT[i]); free(BT); double * pointsX, * pointsY, * pointsZ; ALLOUER(pointsX, points.nb); ALLOUER(pointsY, points.nb); ALLOUER(pointsZ, points.nb); split_x_y_z(points, pointsX, pointsY, pointsZ); Table_flottant BprimeX, BprimeY, BprimeZ; BprimeX.nb = BprimeY.nb = BprimeZ.nb = points.nb; BprimeX.table = matrix_vector_mult(B, pointsX, points.nb); BprimeY.table = matrix_vector_mult(B, pointsY, points.nb); BprimeZ.table = matrix_vector_mult(B, pointsZ, points.nb); free(pointsX); free(pointsY); free(pointsZ); for(i = 0; i < points.nb; i++) free(B[i]); free(B); Table_flottant resX, resY, resZ; resX.nb = resY.nb = resZ.nb = points.nb; ALLOUER(resX.table, points.nb); ALLOUER(resY.table, points.nb); ALLOUER(resZ.table, points.nb); resolution_systeme_lineaire(&Aprime, &BprimeX, &resX); resolution_systeme_lineaire(&Aprime, &BprimeY, &resY); resolution_systeme_lineaire(&Aprime, &BprimeZ, &resZ); for(i = 0; i < points.nb; i++) { res.table[i].x = resX.table[i]; res.table[i].y = resY.table[i]; res.table[i].z = resZ.table[i]; res.table[i].h = 1; } free(BprimeX.table); free(BprimeY.table); free(BprimeZ.table); free(resX.table); free(resY.table); free(resZ.table); for(i = 0; i < Aprime.nb_lignes; i++) free(Aprime.grille[i]); free(Aprime.grille); return res; }