#include "header.h" int main(void) { char matrixfile[maxfile]; //to storage the input matrix file name char vectorfile[maxfile]; //to storage the input vector file name FILE *fin; // to read matrix and vector from the file gsl_vector_float *b; gsl_vector_float *x; gsl_matrix_float *A; gsl_vector_float *z; int Matrixn; // matrix has n columns int Matrixm; // matrix has m rows int Vectorn; // the row of the vectors scanf("%s",matrixfile); scanf("%s",vectorfile); fin=fopen(matrixfile,"r"); fscanf(fin,"%d",&Matrixm); fscanf(fin,"%d",&Matrixn); A=gsl_matrix_float_alloc(Matrixm,Matrixn); gsl_matrix_float_fscanf(fin,A); fin=fopen(vectorfile,"r"); fscanf(fin,"%d",&Vectorn); x=gsl_vector_float_calloc(Vectorn); z=gsl_vector_float_calloc(Vectorn); //used to check gsl_vector_float_set_all(z,0.0); gsl_vector_float_set_all(x,0.0); b=gsl_vector_float_alloc(Vectorn); gsl_vector_float_fscanf(fin,b); //gsl_vector_float_fprintf(stdout,x,"%lf"); //gsl_matrix_float_fprintf(stdout,A,"%lf"); //printf("the value of Matrixmis %d\n",Matrixm); CG(A,b,x,Matrixm); printf("the following is x\n"); gsl_vector_float_fprintf(stdout,x,"%lf"); printf("********************************\n"); printf("the following is the check part, the first part is b, the second part is A*x. the should be equal\n\n"); gsl_vector_float_fprintf(stdout,b,"%lf"); // print b; gsl_blas_sgemv(CblasNoTrans,1.0,A,x,0.0,z);//get z=Ax, store it in z. printf("********************************\n"); gsl_vector_float_fprintf(stdout,z,"%lf"); return 0; }