示例#1
0
        /// Returns a finder to find the next largest eigen value of the receiver's matrix.
        /// @return DhbMatrixAlgebra.LargestEigenvalueFinder
        public LargestEigenvalueFinder NextLargestEigenvalueFinder()
        {
            double    norm = 1.0 / _eigenvector.SecureProduct(_transposedEigenvector);
            DhbVector v1   = _eigenvector * norm;

            return(new LargestEigenvalueFinder(this.DesiredPrecision,
                                               _matrix.SecureProduct(SymmetricMatrix.IdentityMatrix(v1.Dimension)
                                                                     .SecureSubtract(v1.TensorProduct(_transposedEigenvector)))));
        }
示例#2
0
        /// Compute the scalar product (or dot product) of two vectors.
        /// No dimension checking is made.
        /// @return double the scalar product of the receiver with the argument
        /// @param v DHBmatrixAlgebra.DhbVector
        internal protected double SecureProduct(DhbVector v)
        {
            double sum = 0;

            for (int i = 0; i < _components.Length; i++)
            {
                sum += _components[i] * v._components[i];
            }
            return(sum);
        }
示例#3
0
        /// Iterate matrix product in eigenvalue information.
        public override double EvaluateIteration()
        {
            double oldEigenvalue = _eigenvalue;

            _transposedEigenvector  = _transposedEigenvector.SecureProduct(_matrix);
            _transposedEigenvector *= (1.0 / _transposedEigenvector[0]);
            _eigenvector            = _matrix.SecureProduct(_eigenvector);
            _eigenvalue             = _eigenvector[0];
            _eigenvector           *= (1.0 / _eigenvalue);
            return(double.IsNaN(oldEigenvalue)
                            ? 10 * this.DesiredPrecision
                            : Math.Abs(_eigenvalue - oldEigenvalue));
        }
示例#4
0
 /// @return true if the supplied vector is equal to the receiver
 /// @param v DHBmatrixAlgebra.DhbVector
 public bool Equals(DhbVector v)
 {
     if (v.Dimension != _components.Length)
     {
         return(false);
     }
     for (int i = 0; i < _components.Length; i++)
     {
         if (v._components[i] != _components[i])
         {
             return(false);
         }
     }
     return(true);
 }
示例#5
0
        /// @return MatrixAlgebra.Matrix	tensor product with the specified
        ///																vector
        /// @param v MatrixAlgebra.DhbVector	second vector to build tensor
        ///														product with.
        public Matrix TensorProduct(DhbVector v)
        {
            int n = _components.Length;
            int m = v.Dimension;

            double[,] newComponents = new double[n, m];
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    newComponents[i, j] = _components[i] * v._components[j];
                }
            }
            return(n == m ? new SymmetricMatrix(newComponents)
                                  : new Matrix(newComponents));
        }
示例#6
0
        /// Computes the product of the matrix with a vector.
        /// @return DHBmatrixAlgebra.DhbVector
        /// @param v DHBmatrixAlgebra.DhbVector
        internal protected DhbVector SecureProduct(DhbVector v)
        {
            int n = this.Rows;
            int m = this.Columns;

            double[] vectorComponents = new double[n];
            for (int i = 0; i < n; i++)
            {
                vectorComponents[i] = 0;
                for (int j = 0; j < m; j++)
                {
                    vectorComponents[i] += _components[i, j] * v.Components[j];
                }
            }
            return(new DhbVector(vectorComponents));
        }
示例#7
0
        /// @return DhbMatrixAlgebra.SymmetricMatrix
        public DhbVector[] Eigenvectors()
        {
            int n = _rows.GetLength(0);

            DhbVector[] eigenvectors = new DhbVector[n];
            double[]    temp         = new double[n];
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    temp[j] = _transform[j, i];
                }
                eigenvectors[i] = new DhbVector(temp);
            }
            return(eigenvectors);
        }
示例#8
0
        /// Computes the solution for constant vector p applying
        /// backsubstitution.
        /// @param p int
        /// @exception ArithmeticException if one diagonal element
        ///									of the triangle matrix is zero.
        private void BackSubstitution(int p)
        {
            int n = _rows.GetLength(0);

            double[] answer = new double[n];
            double   x;

            for (int i = n - 1; i >= 0; i--)
            {
                x = _rows[i, n + p];
                for (int j = i + 1; j < n; j++)
                {
                    x -= answer[j] * _rows[i, j];
                }
                answer[i] = x / _rows[i, i];
            }
            _solutions[p] = new DhbVector(answer);
        }
示例#9
0
        /// Set result to undefined.
        public override void InitializeIterations()
        {
            _eigenvalue = double.NaN;
            int n = _matrix.Columns;

            double[] eigenvectorComponents = new double[n];
            for (int i = 0; i < n; i++)
            {
                eigenvectorComponents[i] = 1.0;
            }
            _eigenvector          = new DhbVector(eigenvectorComponents);
            n                     = _matrix.Rows;
            eigenvectorComponents = new double[n];
            for (int i = 0; i < n; i++)
            {
                eigenvectorComponents[i] = 1.0;
            }
            _transposedEigenvector = new DhbVector(eigenvectorComponents);
        }
示例#10
0
 /// @return double[]
 /// @param c double[]
 public DhbVector Solve(DhbVector c)
 {
     double[] components = Solve(c.Components);
     return(components == null ? null : new DhbVector(components));
 }
示例#11
0
 /// Construct a system of linear equation Ax = y.
 /// @param a MatrixAlgebra.Matrix	matrix A
 /// @param y MatrixAlgebra.DhbVector	vector y
 /// @exception MatrixAlgebra.DhbIllegalDimension
 ///								if the system's matrix is not square
 ///								if vector dimension does not match
 ///											that of the matrix
 public LinearEquations(Matrix a, DhbVector y) : this(a.Components, y.Components)
 {
 }
示例#12
0
 /// @param v DhbMatrixAlgebra.DhbVector
 /// @exception DhbMatrixAlgebra.DhbIllegalDimension if the vector
 /// and supplied vector do not have the same dimension.
 public void AccumulateNegated(DhbVector v)
 {
     AccumulateNegated(v._components);
 }
示例#13
0
 /// @param v DhbMatrixAlgebra.DhbVector
 /// @exception DhbMatrixAlgebra.DhbIllegalDimension if the vector
 /// and supplied vector do not have the same dimension.
 public void Accumulate(DhbVector v)
 {
     Accumulate(v._components);
 }