예제 #1
0
파일: qrdec.c 프로젝트: yangmw/fedorov
//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);
}
예제 #2
0
파일: ga_math.c 프로젝트: fvdsn/gally
mat_t *mat_set_view(vec_t eye, vec_t u, vec_t v, vec_t w, mat_t *a){
	mat_t *b = mat_set_trans(vec_neg(eye),mat_new_zero());
	mat_set_row(0,u,a);
	mat_set_row(1,v,a);
	mat_set_row(2,w,a);
	mat_set_row(3,vec_new(0,0,0,1),a);
	mat_set_col(3,vec_new(0,0,0,1),a);
	mat_mult(a,b);
	mat_free(b);
	return a;
}
예제 #3
0
파일: main.c 프로젝트: Flyswat/wmmp
mat make_Y(uint Nv, uint Ns, uint Nc, mat U, double wcr)
{
	uint i;
	mat Y = mat_new(Nv,Ns);
	it_randomize();
	for (i=0; i < Ns; i++) {
		vec x, y, w;
		bvec m;

		x = make_x( Nv );
		m = make_m( Nc );
		w = make_w( U, m );

		y = make_y( x, w, wcr );
		mat_set_col(Y,i,y);

		vec_delete( x );
		vec_delete( w );
		vec_delete( y );
		bvec_delete( m );
	}

	return Y;
}