//Brief: QR decomposition void qrdec(mat *A, mat* R){ double proj = 0; double norm = 0; // Allocates pointers of type *vec //vec *coli = (vec*)malloc(sizeof(vec)); //vec *colj = (vec*)malloc(sizeof(vec)); vec* coli = vec_new(A->row); vec* colj = vec_new(A->row); for(int i=0; i<A->col; i++){ mat_get_col(coli, A, i); norm = vec_norm(coli); mat_set(R, i, i, norm); vec_scale(coli, 1.0/norm); mat_set_col(A, coli, i); for(int j=i+1; j<A->col; j++){ mat_get_col(colj, A, j); proj = vec_dot(coli,colj); vec_add(colj,coli,-proj); mat_set_col(A, colj, j); mat_set(R, i, j, proj); } } // Free pointers vec_free(coli); vec_free(colj); }
void print_dist(mat Y, mat Y_attack, double wcr) { uint i; for (i=0; i < mat_width(Y); i++) { vec y = mat_get_col(Y,i), ya = mat_get_col(Y_attack,i); printf("%f, %f;\n", wcr,vec_norm(ya,1.0)/vec_norm(y,1.0)); vec_delete( y ); vec_delete( ya ); } }
mat_t *mat_mult2(const mat_t*a, mat_t*b){ int i = 4; int j = 4; mat_t *m = mat_new_zero(); while(i--){ j = 4; while(j--){ M_IJ(m,i,j) = vec_wdot( mat_get_row(i,a), mat_get_col(j,b) ); } } mat_cpy(b,m); mat_free(m); return b; }