Eigenvalues and eigenvectors of realistic symmetric matrices (RPM)

Source: Internet
Author: User

 /// <summary>        ///eigenvalues and eigenvectors of realistic symmetric matrices/// </summary>        /// <param name= "Data" >Real symmetric matrices</param>        /// <param name= "num" >Number of dimensions</param>        /// <param name= "Eigenvalue" >reference parameter feature value callbacks</param>        /// <param name= "eigenvector" >reference parameter feature vector callback</param>        /// <returns>is successful</returns>        Private BOOLGeteigenvalueandeigenvector (Double[,] data,intNumref Double[] Eigenvalue,ref Double[,] eigenvector) {            Try            {                Double[,] A =data; //E-Unit standard matrix storage feature vector--------------------------------------------                Double[,] V =New Double[num, num];  for(intIV =0; IV < NUM; iv++)                {                     for(intIv2 =0; Iv2 < num; iv2++)                    {                        if(iv = =iv2) {v[iv, iv2]=2; }                        Else{v[iv, iv2]=2; }                    }                }                //----------------------------------------------                Double[] EIGSV =New Double[Num];//Storing eigenvalue values                 for(intIEIGSV =0; IEIGSV < num; ieigsv++) {EIGSV[IEIGSV]=0; }                DoubleEPSL =0.0001; intMaxt =Ten; intn =num; DoubleTao, T, cn, SN;//Temp Variable                DoubleMaxa//record non-diagonal element maximum value//------------------------------------------------------------------------------------------------                 for(intit =0; it < Maxt; it++) {Maxa=0;  for(intp =0; P < n-1; p++)                    {                         for(intQ = p +1; Q < n; q++)                        {                            if(Math.Abs (A[p, Q]) > Maxa)//record non-diagonal element maximum value{Maxa=Math.Abs (a[p, Q]); }                            if(Math.Abs (A[p, Q]) > EPSL)//non-diagonal elements do not perform Jacobi transformations until 0 o'clock                            {                                //calculate the important elements of the Givens rotation matrix: cos (theta), that is, cn, sin (theta), or SNTao =0.5* (A[Q, Q]-a[p, p])/a[p, Q]; if(Tao >=0)//T is the root of the equation t^2 + 2*t*tao-1 = 0, and the root with the lower absolute value is t{T=-tao + math.sqrt (1+ Tao *Tao); }                                Else{T=-tao-math.sqrt (1+ Tao *Tao); } CN=1/MATH.SQRT (1+ T *t); SN= T *cn; //Givens the rotation matrix to the left multiply a, that is, to update A's p line and Q row                                 for(intj =0; J < N; J + +)                                {                                    DoubleAPJ =A[p, J]; DoubleAQJ =A[q, J]; A[p, J]= CN * APJ-SN *Aqj; A[q, J]= SN * APJ + CN *Aqj; }                                //Givens rotation matrix Right multiply A, that is, update A's P column and q column                                 for(inti =0; I < n; i++)                                {                                    DoubleAIP =a[i, p]; DoubleAiq =A[i, Q]; A[i, p]= CN * AIP-SN *Aiq; A[i, Q]= SN * AIP + CN *Aiq; }                                //update feature vector storage Matrix V, V=j0xj1xj2...xjit, so update only V p, q two columns at a time                                 for(intI2 =0; I2 < n; i2++)                                {                                    DoubleVIP =V[i2, p]; DoubleViq =V[i2, Q]; V[i2, p]= CN * VIP-SN *Viq; V[I2, Q]= SN * VIP + CN *Viq; }                            }                        }                    }                    if(Maxa < EPSL)//non-diagonal elements are less than convergence criteria, end of iteration                    {                         Break; }                }                //-----------------------------------------------------------------------------------------------------                < /c7>//eigenvalues vector sorting                 for(intJ2 =0; J2 < n; j2++) {Eigsv[j2]=a[j2, J2]; //fprintf (FP2, "%f", Eigsv[j2]);                }                //sort eigenvalues vectors from large to small and adjust the order of eigenvectors (direct insertion method)                Double[] tmp =New Double[n];  for(intj =1; J < N; J + +)                {                    inti =J; DoubleA =Eigsv[j];  for(intK =0; K < n; k++) {Tmp[k]=V[k, J]; }                     while(I >0&& Eigsv[i-1] <a) {Eigsv[i]= Eigsv[i-1];  for(intK =0; K < n; k++) {v[k, I]= V[k, I-1]; } I--; } Eigsv[i]=A;  for(intK2 =0; K2 < n; k2++) {v[k2, I]=TMP[K2]; }                }                //---------------------------------------------------------------------------------------------------------- //print eigenvalues and feature vector data callbacks                 for(intIVC =0; IVC < num; Ivc++)                {                     for(intIVC2 =0; IVC2 < num; ivc2++)                    {                        //fprintf (FP2, "%f%s", V[IVC, IVC2], "\ n");MessageBox.Show (V[IVC, IVC2].                        ToString ()); EIGENVECTOR[IVC, IVC2]=V[IVC, IVC2]; }                }                 for(intIeigsvc =0; Ieigsvc < num; Ieigsvc++)                {                    //fprintf (FP4, "%f%s", eigsv[ieigsvc], "\ n");MessageBox.Show (Eigsv[ieigsvc].                    ToString ()); EIGENVALUE[IEIGSVC]=Eigsv[ieigsvc]; }                //----------------------------------------------------------------------------------------------------------                return true; }            Catch            {                return false; }        }

Eigenvalues and eigenvectors of realistic symmetric matrices (RPM)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.