Procedimientos numéricos
Valores y vectores propios (Método de Jacobi)
public class Jacobi {
//el vector d son los valores propios
//Las columnas de la matriz v son los vectores propios
//devuelve el número de iteracciones
static int calcula(double[][] a, int n, double[] d, double[][] v) {
int j,iq,ip,i;
double tresh,theta,tau,t,sm,s,h,g,c;
double[] b=new double[n]; //b=vector(1,n);
double[] z=new double[n]; //z=vector(1,n);
for (ip=0;ip<n;ip++) { //Initialize to the identity matrix.
for (iq=0;iq<n;iq++) v[ip][iq]=0.0;
v[ip][ip]=1.0;
}
for (ip=0;ip<n;ip++) { //Initialize b and d to the diagonal of a.
b[ip]=d[ip]=a[ip][ip];
z[ip]=0.0;
double[] valores=new double[N]; double[] vectores=new double[N][N]; Jacobi.calcula(matrix, N, valores, vectores); ordenar(valores, vectores); System.out.println("valores y vectores propios");
for(int i=0; i<N; i++){
System.out.print(valores[i]+"\t");
}
System.out.println();
for(int i=0; i<N; i++){
System.out.println();
for(int j=0; j<N; j++)
System.out.print(vectores[i][j]+"\t");
}
} private void ordenar(double[] x, double[][] mat){
double aux;
double[] vAux=new double[x.length];
for(int i=0; i<x.length-1; i++){
for(int j=i+1; j<x.length; j++){
if(x[i]>x[j]){
aux=x[j];
for(int k=0; k<x.length; k++)
vAux[k]=mat[k][j];
x[j]=x[i];
for(int k=0; k<x.length; k++)
mat[k][j]=mat[k][i];
x[i]=aux;
for(int k=0; k<x.length; k++)
mat[k][i]=vAux[k];
}
}
}
}
|
Referencias
Press W. H., Teukolsky S. A., Vetterling W. T., Flannery B. P. Numerical Recipes in C, Second edition, Eigensystems. Jacobi Transformations of a Symmetric Matrix, Chapter 11º. pp. 463-469. Cambridge University Press. Código en C adaptado por el autor al lenguaje Java
