Esempio n. 1
0
        private void Test_ishermitianComplex() {
            int errorCode = 0; 
            try {
                ILArray<complex> A = ILArray<complex>.empty(); 
                if (ILMath.ishermitian(A))
                    throw new Exception("ishermitian on empty array should return false"); 
                A = new complex(1.0,1.0); 
                if (!ILMath.ishermitian(A))
                    throw new Exception("ishermitian on scalar array should return true"); 
                A = ILMath.tocomplex( ILMath.vector(1,5));
                if (ILMath.ishermitian(A))
                    throw new Exception("ishermitian on scalar array should return false"); 
                errorCode = 1; 
                A = ILMath.tocomplex(ILMath.randn (4,4));
                for (int i = 0; i < 16; i++)
                    A.SetValue(new complex(A.GetValue(i).real,A.GetValue(i).real),i); 
                A[1,0] = A.GetValue(0,1).conj; 
                A[2,0] = A.GetValue(0,2).conj; 
                A[2,1] = A.GetValue(1,2).conj; 
                A[3,0] = A.GetValue(0,3).conj; 
                A[3,1] = A.GetValue(1,3).conj; 
                A[3,2] = A.GetValue(2,3).conj; 
                A[0,0] = (complex)A.GetValue(0,0).real;
                A[1,1] = (complex)A.GetValue(1,1).real;
                A[2,2] = (complex)A.GetValue(2,2).real;
                A[3,3] = (complex)A.GetValue(3,3).real;

                if (!ILMath.ishermitian(A)) 
                    throw new Exception("ishermitian: A was Hermitian but detected as not");
                A[3,2] += new complex(1.0,0.0); 
                if (ILMath.ishermitian(A)) 
                    throw new Exception("ishermitian: A was not Hermitian but detected as true");
                A[3,2] -= new complex(1.0,0.0);
                A[1,0] += new complex(1.0,0.0); 
                if (ILMath.ishermitian(A)) 
                    throw new Exception("ishermitian: A was not Hermitian but detected as true");
                A[1,0] -= new complex(1.0,0.0);
                A[3,0] += new complex(1.0,0.0); 
                if (ILMath.ishermitian(A)) 
                    throw new Exception("ishermitian: A was not Hermitian but detected as true");
                errorCode = 2; 
                Success(); 
            } catch(Exception e) {
                Error(errorCode,e.Message);
            }
        }