Exemplo n.º 1
0
/*SUBROUTINE Eigen*/
void Eigen2(int size, double *Freq, double ***D) {
	//DECLARE LOCAL VARIABLES
	int i, j, n;
	void Householder2(double ***a, int n, double *d, double *e);
	void QL2(double *d, double *e, int size, double ***a);
	double *e, *d;
	double swap, trial;


  //ALLOCATE MEMORY
	e = (double*) calloc(size, sizeof(double));
	d = (double*) calloc(size, sizeof(double));


  //CALL SUBROUTINES
	Householder2(D, size, d, e);
	QL2(d, e, size, D);


	//ORDER EIGENVALUES FROM LARGEST TO SMALLEST
	for(i=0;i<size;i++) {
		swap = d[i];
		n = i;
		for(j=i+1;j<size;j++) {
			trial = d[j];
			if(swap<trial) {swap=trial;n=j;}
		}
		if(n!=i) {
			d[n] = d[i];
			d[i] = swap;
/*#if defined EIGENVECTOR*/
			for(j=0;j<size;j++) {
				swap = D[j][i][0];
				D[j][i][0] = D[j][n][0];
				D[j][n][0] = swap;
				swap = D[j][i][1];
				D[j][i][1] = D[j][n][1];
				D[j][n][1] = swap;
			}
/*#endif*/
		}
		Freq[i] = d[i];
	}


	//FREE DYNAMIC ARRAYS
	free(e);
	free(d);

	return;
}
Exemplo n.º 2
0
/* ========================================================= */
static void Eigen( int N,  double **C, double *diag, double **Q, double *rgtmp)
/* 
 * Calculating eigenvalues and vectors. 
 * Input: 
 *  N: dimension.
 *  C: symmetric (1:N)xN-matrix, solely used to copy data to Q
 *  niter: number of maximal iterations for QL-Algorithm. 
 *  rgtmp: N+1-dimensional vector for temporal use. 
 * Output: 
 *  diag: N eigenvalues. 
 *  Q: Columns are normalized eigenvectors.
 */
{
	int i, j;
	
	if (rgtmp == NULL){ /* was OK in former versions */
		//FATAL("cmaes_t:Eigen(): input parameter double *rgtmp must be non-NULL", 0,0,0);
		fprintf(stderr,"cmaes_t:Eigen(): input parameter double *rgtmp must be non-NULL");
		exit(1);
	}
	
	/* copy C to Q */
	if (C != Q) {
		for (i=0; i < N; ++i)
			for (j = 0; j <= i; ++j)
				Q[i][j] = Q[j][i] = C[i][j];
	}
	
	#if 0
	Householder( N, Q, diag, rgtmp);
	QLalgo( N, diag, Q, 30*N, rgtmp+1);
	#else
	Householder2( N, Q, diag, rgtmp);
	QLalgo2( N, diag, rgtmp, Q);
	#endif
}