Esempio n. 1
0
void eigen_decomposition(const double A[n][n], double V[n][n], double d[n]) {
  double e[n];
  memcpy((double*)V, (const double*)A, n*n*sizeof(double));

  tred2(V, d, e);
  tql2(V, d, e);
}
Esempio n. 2
0
int principal_stresses(StressTensor* stress, double d[3], double V[3][3])
{

	int i,j;
	double e[3];
	void tred2(int n, double d[3], double e[3], double V[3][3]);
	void tql2 (int n, double d[3], double e[3], double V[3][3]);

	for (i = 0; i < 3; i++) {
		for (j = 0; j < 3; j++) {
			V[i][j] = (*stress)[i][j];
		}
	}

	// Tridiagonalize.
	tred2(3, d, e, V);
   
	// Diagonalize.
	tql2(3, d, e, V);

	/* fprintf(stderr,"eig 1: %e eigV: %e %e %e\n",d[0],V[0][0],V[1][0],V[2][0]); */
	/* fprintf(stderr,"eig 2: %e eigV: %e %e %e\n",d[1],V[0][1],V[1][1],V[2][1]); */
	/* fprintf(stderr,"eig 3: %e eigV: %e %e %e\n",d[2],V[0][2],V[1][2],V[2][2]); */
	return(1);
}
Esempio n. 3
0
void eigen_decomposition(double A[n][n], double V[n][n], double d[n]) {
  double e[n];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      V[i][j] = A[i][j];
    }
  }
  tred2(V, d, e);
  tql2(V, d, e);
}
Esempio n. 4
0
void eigen_decomposition(float A[n][n], float V[n][n], float d[n]) {
  float e[n];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      V[i][j] = A[i][j];
    }
  }
  tred2(V, d, e);
  tql2(V, d, e);
}
Esempio n. 5
0
File: math.c Progetto: acados/acados
void acados_eigen_decomposition(int dim, double *A, double *V, double *d, double *e)
{
	int i, j;

    for (i=0; i<dim; i++)
        for (j=0; j<dim; j++)
			V[i*dim+j] = A[i*dim+j];

    tred2(dim, V, d, e);
    tql2(dim, V, d, e);

	return;
}
Esempio n. 6
0
File: math.c Progetto: acados/acados
void eigen_decomposition(int dim, double *A, double *V, double *d)
{
	int i, j;

    for (i=0; i<dim; i++)
        for (j=0; j<dim; j++)
			V[i*dim+j] = A[i*dim+j];

    double *e = (double *) calloc(dim, sizeof(double));

    tred2(dim, V, d, e);
    tql2(dim, V, d, e);

	free(e);

	return;
}
bool EigenvalueDecomposition::decompose(const MatrixFloat &a){
    
    n = a.getNumCols();
    eigenvectors.resize(n,n);
    realEigenvalues.resize(n);
    complexEigenvalues.resize(n);
    
    issymmetric = true;
    for(int j = 0; (j < n) & issymmetric; j++) {
        for(int i = 0; (i < n) & issymmetric; i++) {
            issymmetric = (a[i][j] == a[j][i]);
        }
    }
    
    if (issymmetric) {
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                eigenvectors[i][j] = a[i][j];
            }
        }
        
        // Tridiagonalize.
        tred2();
        
        // Diagonalize.
        tql2();
        
    } else {
        h.resize(n,n);
        ort.resize(n);
        
        for(int j = 0; j < n; j++) {
            for(int i = 0; i < n; i++) {
                h[i][j] = a[i][j];
            }
        }
        
        // Reduce to Hessenberg form.
        orthes();
        
        // Reduce Hessenberg to real Schur form.
        hqr2();
    }
    
    return true;
}
Esempio n. 8
0
///////////////////////////////////////////////////////////////////////////////
//
//	Computes m_eigenValues and eigenvectors of a real, symmetric
//	matrix. 
//
//	A matrix can be decomposed as A = U*D*U', where the eigenvalue matrix D is
//	diagonal and the eigenvector matrix U is orthogonal. That is,
//	the diagonal values of D are the m_eigenValues, and
//	U*U' = I, where I is the identity matrix.  The columns of U 
//	represent the eigenvectors in the sense that A*U = V*U.
//   
//	(Adapted from JAMA, a Java Matrix Library, developed by jointly 
//	by the Mathworks and NIST; see  http://math.nist.gov/javanumerics/jama).
//
//  Modified by: Donovan Parks, August 2007 ([email protected])
///////////////////////////////////////////////////////////////////////////////
EigDecomp::EigDecomp(double* A, double* U, double* D, double* E, int rows) 
{
  m_rows = rows;
  m_U = U;
  m_D = D;
	m_E = E;

	for(int j = 0; j < m_rows; ++j)
	{
		for(int i = 0; i < m_rows; ++i)
		{
			m_U[i+j*m_rows] = A[i+j*m_rows];
		}
	}

	// Tridiagonalize.
	tred2();

	// Diagonalize.
	tql2();
}
Esempio n. 9
0
void eigen_decomposition(double A[n][n], double V[n][n], double d[n]) {
    double e[n];
    double da[3];
    double dt, dat;
    double vet[3];
    int i, j;
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            V[i][j] = A[i][j];
        }
    }
    tred2(V, d, e);
    tql2(V, d, e);
    
    /* Sort the eigen values and vectors by abs eigen value */
    da[0]=absd(d[0]); da[1]=absd(d[1]); da[2]=absd(d[2]);
    if((da[0]>=da[1])&&(da[0]>da[2]))
    {
        dt=d[2];   dat=da[2];    vet[0]=V[0][2];    vet[1]=V[1][2];    vet[2]=V[2][2];
        d[2]=d[0]; da[2]=da[0];  V[0][2] = V[0][0]; V[1][2] = V[1][0]; V[2][2] = V[2][0];
        d[0]=dt;   da[0]=dat;    V[0][0] = vet[0];  V[1][0] = vet[1];  V[2][0] = vet[2]; 
    }
    else if((da[1]>=da[0])&&(da[1]>da[2]))  
    {
        dt=d[2];   dat=da[2];    vet[0]=V[0][2];    vet[1]=V[1][2];    vet[2]=V[2][2];
        d[2]=d[1]; da[2]=da[1];  V[0][2] = V[0][1]; V[1][2] = V[1][1]; V[2][2] = V[2][1];
        d[1]=dt;   da[1]=dat;    V[0][1] = vet[0];  V[1][1] = vet[1];  V[2][1] = vet[2]; 
    }
    if(da[0]>da[1])
    {
        dt=d[1];   dat=da[1];    vet[0]=V[0][1];    vet[1]=V[1][1];    vet[2]=V[2][1];
        d[1]=d[0]; da[1]=da[0];  V[0][1] = V[0][0]; V[1][1] = V[1][0]; V[2][1] = V[2][0];
        d[0]=dt;   da[0]=dat;    V[0][0] = vet[0];  V[1][0] = vet[1];  V[2][0] = vet[2]; 
    }

    
}
Esempio n. 10
0
VOID eispack_rs P9C(int, nm,
                    int, n,
                    double *, a,
                    double *, w,
                    int, matz,
                    double *, z,
                    double *, fv1,
                    double *, fv2,
                    int *, ierr)
{
    /* this subroutine calls the recommended sequence of */
    /* subroutines from the eigensystem subroutine package (eispack) */
    /* to find the eigenvalues and eigenvectors (if desired) */
    /* of a real symmetric matrix. */

    /* on input */

    /*    nm  must be set to the row dimension of the two-dimensional */
    /*    array parameters as declared in the calling program */
    /*    dimension statement. */

    /*    n  is the order of the matrix  a. */

    /*    a  contains the real symmetric matrix. */

    /*    matz  is an integer variable set equal to zero if */
    /*    only eigenvalues are desired.  otherwise it is set to */
    /*    any non-zero integer for both eigenvalues and eigenvectors. */

    /* on output */

    /*    w  contains the eigenvalues in ascending order. */

    /*    z  contains the eigenvectors if matz is not zero. */

    /*    ierr  is an integer output variable set equal to an error */
    /*       completion code described in the documentation for tqlrat */
    /*       and tql2.  the normal completion code is zero. */

    /*    fv1  and  fv2  are temporary storage arrays. */

    /* questions and comments should be directed to burton s. garbow, */
    /* mathematics and computer science div, argonne national laboratory */

    /* this version dated august 1983. */

    /* ------------------------------------------------------------------ */

    if (n <= nm) {
        goto L10;
    }
    *ierr = n * 10;
    goto L50;

L10:
    if (matz != 0) {
        goto L20;
    }
    /* .......... find eigenvalues only .......... */
    tred1(nm, n, a, w, fv1, fv2);
    /*  tqlrat encounters catastrophic underflow on the Vax */
    /* call  tqlrat(n,w,fv2,ierr) */
    tql1(n, w, fv1, ierr);
    goto L50;
    /* .......... find both eigenvalues and eigenvectors .......... */
L20:
    tred2(nm, n, a, w, fv1, z);
    tql2(nm, n, w, fv1, z, ierr);
L50:
    return;
}
Esempio n. 11
0
VOID eispack_ch P12C(int, nm,
                     int, n,
                     double *, ar,
                     double *, ai,
                     double *, w,
                     int, matz,
                     double *, zr,
                     double *, zi,
                     double *, fv1,
                     double *, fv2,
                     double *, fm1,
                     int *, ierr)
{
    /* Local variables */
    int i, j;

    /* this subroutine calls the recommended sequence of */
    /* subroutines from the eigensystem subroutine package (eispack) */
    /* to find the eigenvalues and eigenvectors (if desired) */
    /* of a complex hermitian matrix. */

    /* on input */

    /*    nm  must be set to the row dimension of the two-dimensional */
    /*    array parameters as declared in the calling program */
    /*    dimension statement. */

    /*    n  is the order of the matrix  a=(ar,ai). */

    /*    ar  and  ai  contain the real and imaginary parts, */
    /*    respectively, of the complex hermitian matrix. */

    /*    matz  is an integer variable set equal to zero if */
    /*    only eigenvalues are desired.  otherwise it is set to */
    /*    any non-zero integer for both eigenvalues and eigenvectors. */

    /* on output */

    /*    w  contains the eigenvalues in ascending order. */

    /*    zr  and  zi  contain the real and imaginary parts, */
    /*    respectively, of the eigenvectors if matz is not zero. */

    /*    ierr  is an integer output variable set equal to an error */
    /*       completion code described in the documentation for tqlrat */
    /*       and tql2.  the normal completion code is zero. */

    /*    fv1, fv2, and  fm1  are temporary storage arrays. */

    /* questions and comments should be directed to burton s. garbow, */
    /* mathematics and computer science div, argonne national laboratory */

    /* this version dated august 1983. */

    /* ------------------------------------------------------------------ */

    if (n <= nm) {
        goto L10;
    }
    *ierr = n * 10;
    goto L50;

L10:
    htridi(nm, n, ar, ai, w, fv1, fv2, fm1);
    if (matz != 0) {
        goto L20;
    }
    /* .......... find eigenvalues only .......... */
    tqlrat(n, w, fv2, ierr);
    goto L50;
    /* .......... find both eigenvalues and eigenvectors .......... */
L20:
    for (i = 0; i < n; ++i) {
        for (j = 0; j < n; ++j) {
            zr[j + i * nm] = 0.0;
        }
        zr[i + i * nm] = 1.0;
    }

    tql2(nm, n, w, fv1, zr, ierr);
    if (*ierr != 0) {
        goto L50;
    }
    htribk(nm, n, ar, ai, fm1, n, zr, zi);
L50:
    return;
}
Esempio n. 12
0
void EigenValues(const SymmetricMatrix& A, DiagonalMatrix& D, Matrix& Z)
{ DiagonalMatrix E; tred2(A, D, E, Z); tql2(D, E, Z); }