示例#1
0
        public static bool IsNearlyEigenpair(AnySquareMatrix A, Complex[] v, Complex a)
        {
            int d = A.Dimension;

            // compute products
            Complex[] Av = new Complex[d];
            for (int i=0; i<d; i++) {
                Av[i] = 0.0;
                for (int j=0; j<d; j++) {
                    Av[i] += A[i,j]*v[j];
                }
            }
            Complex[] av = new Complex[d];
            for (int i=0; i<d; i++) {
                av[i] = a * v[i];
            }

            // compute tolorance
            double N = MatrixNorm(A);
            double n = 0.0;
            for (int i = 0; i < d; i++) {
                n += ComplexMath.Abs(v[i]);
            }
            double ep = TargetPrecision * (N * n / d + ComplexMath.Abs(a) * n);

            // compare elements within tollerance
            for (int i = 0; i < d; i++) {
                if (ComplexMath.Abs(Av[i] - av[i]) > ep) return (false);
            }
            return (true);
        }
示例#2
0
        public static bool IsNearlyEigenpair(AnySquareMatrix A, ColumnVector v, double a)
        {
            // compute products
            ColumnVector Av = A * v;
            ColumnVector av = a * v;

            // compute tolorance
            int d = v.Dimension;
            double N = MatrixNorm(A);
            double n = MatrixNorm(v);
            double ep = TargetPrecision * (Math.Abs(N*n)/d + Math.Abs(a*n));

            // compare elements within tolorance
            for (int i = 0; i < d; i++) {
                if (Math.Abs(Av[i] - av[i]) > ep) return (false);
            }
            return (true);
        }