#include #include #include #include /* =============== Main functions body ====================*/ int sympowerit(double *E, int n, double *T, int amax, double tol, int maxiter, int verbose) { /* PURPOSE: Estimate eigenvectos of a symmetric matrix using the power method. CALLING SEQUENCE: info = sympowerit(*E, n, *T, amax, tol, maxiter); INPUTS: E symmetric matrix from XX^T/X^TX of centered data matrix type: *double n elements in X first dimension type: int type: *double T workspace for scores (m, amax) type: *double amax maximum number of principal components type: int tol convergence limit type: double maxiter maximum number of iteraitons type: int verbose the amount of debug output */ int iter, a, j; int info = 0; double sumsq, l2norm, *y,*x, sgn, diff, alpha; double lambda = 0.0; if (verbose>1) verbose=1; /* Allocate space for working vector and eigenvector */ y = (double *) malloc(n*sizeof(double)); x = (double *) malloc(n*sizeof(double)); /* Loop over all components to be estimated*/ for (a=0; a<=amax-1; a++){ /* Reset work-/eigen-vector*/ for (j=0; j= maxiter){ if (verbose == 1){ printf("\nComp: %d\n", a); printf("Max iter reached.\n"); printf("Error: %.2E\n", sumsq); } info = 1; break; } } /* Calculate T */ for (j=0; j