コード例 #1
0
ファイル: T_Matrices.cs プロジェクト: OpenDerivatives/QLCore
        public void testEigenvectors()
        {
            //("Testing eigenvalues and eigenvectors calculation...");

            setup();

            Matrix[] testMatrices = { M1, M2 };

            for (int k = 0; k < testMatrices.Length; k++)
            {
                Matrix M = testMatrices[k];
                SymmetricSchurDecomposition dec = new SymmetricSchurDecomposition(M);
                Vector eigenValues  = dec.eigenvalues();
                Matrix eigenVectors = dec.eigenvectors();
                double minHolder    = double.MaxValue;

                for (int i = 0; i < N; i++)
                {
                    Vector v = new Vector(N);
                    for (int j = 0; j < N; j++)
                    {
                        v[j] = eigenVectors[j, i];
                    }
                    // check definition
                    Vector a = M * v;
                    Vector b = eigenValues[i] * v;
                    if (norm(a - b) > 1.0e-15)
                    {
                        QAssert.Fail("Eigenvector definition not satisfied");
                    }
                    // check decreasing ordering
                    if (eigenValues[i] >= minHolder)
                    {
                        QAssert.Fail("Eigenvalues not ordered: " + eigenValues);
                    }
                    else
                    {
                        minHolder = eigenValues[i];
                    }
                }

                // check normalization
                Matrix m = eigenVectors * Matrix.transpose(eigenVectors);
                if (norm(m - I) > 1.0e-15)
                {
                    QAssert.Fail("Eigenvector not normalized");
                }
            }
        }
コード例 #2
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(SymmetricSchurDecomposition obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }