/* ================================================================== trivec - Matlab CMEX program Find eigenvectors of tridiagonal quasi-symmetric matrix eigenvectors = trivec(eigenvalues,diag,off_diag); Input: eigenvalues - find vectors for each of these values. diag - the main diagonal of a quasi-symmetric tridiagonal matrix. off_diag- (Optional) the product of the off diagonals. defaults to all ones. Output: eigenvectors - SET TO 0 if routine did not converge. ------------------------------------------------------------------ Uses inverse iteration to find eigenvectors. This is not efficient unless we are looking for less than 25% of the total number of vectors. Calls C routine sinvitC() Author: Robert Bernecky Date : 6/10/94 ================================================================== */ #include #include #include "cmex.h" /* eigenvectors = trivec(eigenvalues,diag,off_diag); */ #define EV prhs[0] #define Dm prhs[1] #define Em prhs[2] #define EVS plhs[0] #define FALSE (0) #define TRUE (1) int sinvitC (int N, double Adiag[], double subDiag[], double eigVal, double *eigVec); /* --------------------------------------------------------------- eigenvectors = trivec(eigenvalues,diag,off_diag); --------------------------------------------------------------- */ void mexFunction (int nlhs, Matrix *plhs [], int nrhs, Matrix *prhs []) { double *pd, *ofd, *offdiag, *eigval; int i, eig_ct, all_ones=FALSE, N, stat; if (nrhs < 2) mex_error("Function trivec must have at least two input arguments"); if (mxGetPi(EV) != NULL) mex_error("First argument of function trivec must be real"); if (((mxGetM(Dm) == 1) && (mxGetN(Dm) == 1)) || (mxGetPi(Dm) != NULL)) mex_error("2nd argument of function trivec must be a real vector"); if (nrhs >= 3) { if (((mxGetM(Em) == 1) && (mxGetN(Em) == 1)) || (mxGetPi(Em) != NULL)) mex_error("3rd argument of function trivec must be a real vector"); } else all_ones= TRUE; eig_ct= (int)(mxGetM(EV) * mxGetN(EV)); N= (int) (mxGetM(Dm) * mxGetN(Dm)); /* size of main diagonal */ pd= offdiag= (double *) mex_calloc(N, sizeof(double)); if (all_ones) for(i=0;i=fabs(U)) { *(++RV4) = XU= U/ *E; *RV1= *E; *RV2= *D - eigVal; *RV3= 0.0; if (i Nth element */ /* ***** Main loop of inverse iteration ***** */ for(i=0;i=5) { for(i=0;i