Linear Algebra and the C Language/a0dj


Code study: eigs_mR();

I want to calculate the eigenvalues ​​of the matrix M.

  • I use the QR decomposition of M.
  • Then I calculate RQ.
  • RQ becomes the new value of M.
  • And I start a cycle again.


To avoid modifying M, I copy it into T. Then I apply the algorithm seen above 1000 times.

c_mR(M,T);

 for(i=0;i<1000;i++)
     { 
       QR_mR(T,Q,R);  
        mul_mR(R,Q,T);
     }

Finally, I find the eigenvalues ​​on the diagonal of T.

     
  for(rc=R1;rc<=r;rc++)
     { 
	   EValue[rc][C1] = T[rc][rc];
     }
/* ------------------------------------ */
/* ------------------------------------ */
double **eigs_mR(
double **A,
double **EValue
)
{
int r = rsize_R(A);

double **T = i_mR(r,r);
double **Q = i_mR(r,r);
double **  = i_mR(r,r);
int i;
int rc;

 c_mR(A,T);
 
 for(i=0;i<LOOP_EIGSUV;i++)
     { 
	   QR_mR(T,Q,R);  
        mul_mR(R,Q,T);
     }
     
  for(rc=R1;rc<=r;rc++)
     { 
	   EValue[rc][C1] = T[rc][rc];
     }
     
  f_mR(T);
  f_mR(Q);
  f_mR(R); 
  
  return(EValue);    
}
/* ------------------------------------ */
/* ------------------------------------ */