Fast Auxiliary Space Preconditioning  1.8.4 Feb/15/2016
eigen.c
Go to the documentation of this file.
1 
6 #include <math.h>
7 
8 #include "fasp.h"
9 #include "fasp_functs.h"
10 
11 /*---------------------------------*/
12 /*-- Public Functions --*/
13 /*---------------------------------*/
14 
30  const REAL tol,
31  const INT maxit)
32 {
33  REAL eigenvalue=0.0, temp=1.0;
34 
35  dvector x, y;
36  fasp_dvec_alloc(A->row, &x);
37  fasp_dvec_rand(A->row,&x);
39  fasp_dvec_alloc(A->row, &y);
40 
41  REAL L2_norm_y;
42  unsigned INT i;
43 
44  for (i=0; i<maxit; i++) {
45  // y = Ax;
46  fasp_blas_dcsr_mxv(A, x.val, y.val);
47 
48  // y/||y||
49  L2_norm_y = fasp_blas_dvec_norm2(&y);
50  fasp_blas_array_ax(A->row, 1.0/L2_norm_y, y.val);
51 
52  // eigenvalue = y'Ay;
53  eigenvalue = fasp_blas_dcsr_vmv(A, y.val, y.val);
54 
55  // convergence test
56  if ((ABS(eigenvalue - temp)/ABS(temp))<tol) goto FINISHED;
57 
58  //
59  fasp_dvec_cp(&y, &x);
60  temp = eigenvalue;
61  }
62 
63  FINISHED:
64  fasp_dvec_free(&x);
65  fasp_dvec_free(&y);
66 
67  return eigenvalue;
68 }
69 
70 /*---------------------------------*/
71 /*-- End of File --*/
72 /*---------------------------------*/
#define REAL
Definition: fasp.h:67
void fasp_dvec_free(dvector *u)
Free vector data space of REAL type.
Definition: vec.c:139
void fasp_dvec_cp(dvector *x, dvector *y)
Copy dvector x to dvector y.
Definition: vec.c:345
REAL * val
actual vector entries
Definition: fasp.h:348
REAL fasp_dcsr_eig(dCSRmat *A, const REAL tol, const INT maxit)
Approximate the largest eigenvalue of A by the power method.
Definition: eigen.c:29
Vector with n entries of REAL type.
Definition: fasp.h:342
#define INT
Definition: fasp.h:64
REAL fasp_blas_dvec_norm2(dvector *x)
L2 norm of dvector x.
Definition: blas_vec.c:265
void fasp_dvec_rand(const INT n, dvector *x)
Generate random REAL vector in the range from 0 to 1.
Definition: vec.c:203
Main header file for FASP.
INT row
row number of matrix A, m
Definition: fasp.h:151
Sparse matrix of REAL type in CSR format.
Definition: fasp.h:148
#define ABS(a)
Definition: fasp.h:74
void fasp_blas_array_ax(const INT n, const REAL a, REAL *x)
x = a*x
Definition: blas_array.c:35
void fasp_dvec_alloc(const INT m, dvector *u)
Create dvector data space of REAL type.
Definition: vec.c:99
REAL fasp_blas_dcsr_vmv(dCSRmat *A, REAL *x, REAL *y)
vector-Matrix-vector multiplication alpha = y'*A*x
Definition: blas_csr.c:704
void fasp_blas_dcsr_mxv(dCSRmat *A, REAL *x, REAL *y)
Matrix-vector multiplication y = A*x.
Definition: blas_csr.c:225