#include "header.h" int checksys(gsl_matrix *A) { int i,j; int n=A->size1; float tmp1; float tmp2; printf("n====%d\n",n); for(i=1;isize1; Q=gsl_matrix_alloc (n,n); A0=gsl_matrix_alloc (n,n); v0=gsl_vector_alloc (n); r=gsl_vector_alloc (n); ///////////check symmetric if (!checksys(*A)) { printf("the input matrix is not symmetric!\n"); printf("program stopped!\n"); return 0; } ///////////A is symmetric //////////QR algorithm begin for(count=0;countk) gsl_matrix_set(Q,j,k,gsl_matrix_get(*A,j,k)); // lower trig } } /* Compute A0 = t(Q)*A */ gsl_blas_dgemm (CblasTrans, CblasNoTrans, 1.0, Q, *A, 0.0, A0); gsl_blas_dgemm (CblasNoTrans, CblasNoTrans, 1.0, A0,Q, 0.0, *A); } return 1; } int main(void) { gsl_matrix *A; gsl_matrix *B; gsl_vector *x; float tol; // error int maxite; //maximum iterate int n,m; // dimentions of A; int flag=0; /////////////////// input begins //////////// read in the matrix from the standard input stream. scanf("%d",&n); scanf("%d",&m); A=gsl_matrix_alloc(n,m); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!! B=gsl_matrix_alloc(n,m); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!! gsl_matrix_fscanf (stdin,A); gsl_matrix_memcpy(B,A); /////////////////// call the CG function to solve the equation x=gsl_vector_alloc(n); //!!!!!!!!!!!!!!!!!!!! gsl_vector_set_zero(x); //x=0; tol=TOL; //control the error maxite=MAXITE; //control the iterate flag=QREvals(&A,&x,maxite,tol); ////////////////////compare with build-in function gsl_eigen_symmv_workspace * w = gsl_eigen_symmv_alloc (n); gsl_vector *eval = gsl_vector_alloc (n); gsl_matrix *evec = gsl_matrix_alloc (n, n); gsl_eigen_symmv (B, eval, evec, w); printf("eval by using gsl function:\n"); gsl_vector_fprintf(stdout,eval,"%lf"); /////////////////output begins if(flag==1) { printf("QR Eigenvalues of Matrix A is: \n"); gsl_vector_fprintf(stdout,eval,"%lf"); } //////////////// gsl_vector_free(x); gsl_matrix_free(A); return 0; }