예제 #1
0
        /// <summary>
        /// Scalar-Matrix multiplication.
        /// </summary>
        /// <param name="s"> The left side scalar of the multiplication operator.</param>
        /// <param name="A">The right side matrix of the multiplication operator.</param>
        /// <returns>A matrix that represents the result of the multiplication.</returns>
        public static SymmetricBandMatrix operator *(double s, SymmetricBandMatrix A)
        {
            SymmetricBandMatrix C = new SymmetricBandMatrix(A.RowCount, A.LowerBandWidth);

            double[] AData = A.Data;
            double[] CData = C.Data;


            Matrix.MultiplicationSM(s, AData, CData);

            return(C);
        }
예제 #2
0
        /// <summary>
        ///Computes all the eigenvalues of
        /// a real symmetric band matrix A.
        /// </summary>
        /// <param name="A">The real symmetric band matrix A.</param>
        /// <returns>The eigenvalues.</returns>
        public Matrix GetEigenvalues(SymmetricBandMatrix A)
        {
            if (this._dsbev == null)
            {
                this._dsbev = new DSBEV();
            }

            this.CheckDimensions(A);

            Matrix SymmetricBand = A.GetSymmetricBandPackedMatrix();

            double[] SymmetricBandData = SymmetricBand.Data;
            Matrix   EigenVects        = new Matrix(1, 1); //Se pone (1,1) pues nos e usaran

            double[] EigenVectsData = EigenVects.Data;
            Matrix   EigenVals      = new Matrix(A.RowCount, 1);

            double[] EigenValsData = EigenVals.Data;
            int      Info          = 0;

            double[] Work = new double[3 * A.RowCount - 2];


            _dsbev.Run("N", "U", A.RowCount, A.UpperBandWidth, ref SymmetricBandData, 0, SymmetricBand.RowCount, ref EigenValsData, 0, ref EigenVectsData, 0, A.RowCount, ref Work, 0, ref Info);


            #region Error
            /// = 0:  successful exit
            /// .LT. 0:  if INFO = -i, the i-th argument had an illegal value
            /// .GT. 0:  if INFO = i, the algorithm failed to converge; i
            /// off-diagonal elements of an intermediate tridiagonal
            /// form did not converge to zero.

            if (Info < 0)
            {
                string infoSTg = Math.Abs(Info).ToString();
                throw new ArgumentException("the " + infoSTg + " -th argument had an illegal value");
            }
            else if (Info > 0)
            {
                string infoSTg = Math.Abs(Info).ToString();
                throw new Exception("The algorithm failed to converge.");
            }

            #endregion


            return(EigenVals);
        }
예제 #3
0
        /// <summary>Generate a BandMatrix with random elements</summary>
        /// <param name="size">Size</param>
        /// <param name="BandWidth">Number of bands below or above the main diagonal</param>
        public static SymmetricBandMatrix Random(int size, int BandWidth)
        {
            System.Random random = new System.Random();

            SymmetricBandMatrix X = new SymmetricBandMatrix(size, BandWidth);

            double[] XData = X.Data;

            for (int j = 0; j < X.ColumnCount; j++)
            {
                for (int i = 0; i < X.RowCount; i++)
                {
                    X[i, j] = random.NextDouble();
                }
            }
            return(X);
        }
예제 #4
0
        ///// <summary>Matrix Subtraction</summary>
        /// <summary>
        /// Matrix subtraction.
        /// </summary>
        /// <param name="A"> The left side matrix of the subtraction operator.</param>
        /// <param name="B">The right side matrix of the subtraction operator.</param>
        /// <returns>A matrix that represents the result of the matrix subtraction.</returns>
        public static SymmetricBandMatrix operator -(SymmetricBandMatrix A, SymmetricBandMatrix B)
        {
            if (B.RowCount != A.RowCount || B.ColumnCount != A.ColumnCount || B.LowerBandWidth != A.LowerBandWidth || B.UpperBandWidth != A.UpperBandWidth)
            {
                throw new System.ArgumentException("Matrix dimensions are not valid.");
            }

            SymmetricBandMatrix C = new SymmetricBandMatrix(A.RowCount, A.LowerBandWidth);

            double[] AData = A.Data;
            double[] BData = B.Data;
            double[] CData = C.Data;

            for (int i = 0; i < AData.Length; i++)
            {
                CData[i] = AData[i] - BData[i];
            }

            return(C);
        }
예제 #5
0
 /// <summary>
 /// Creates a copy of the matrix.
 /// </summary>
 /// <returns>The copy of the Matrix.</returns>
 public SymmetricBandMatrix Clone()
 {
     SymmetricBandMatrix NewBandMatix = new SymmetricBandMatrix(this._RowCount, this.MeLowerBandWidth, this._Data);
     return NewBandMatix;
 }
예제 #6
0
        /// <summary>Generate a BandMatrix with random elements</summary>
        /// <param name="size">Size</param>
        /// <param name="BandWidth">Number of bands below or above the main diagonal</param>
        public static SymmetricBandMatrix Random(int size, int BandWidth)
        {
            System.Random random = new System.Random();

            SymmetricBandMatrix X = new SymmetricBandMatrix(size, BandWidth);

            double[] XData = X.Data;

            for (int j = 0; j < X.ColumnCount; j++)
            {
                for (int i = 0; i < X.RowCount; i++)
                {
                    X[i, j] = random.NextDouble();
                }
            }
            return X;
        }
예제 #7
0
        ///// <summary>Matrix Subtraction</summary>
        /// <summary>
        /// Matrix subtraction.
        /// </summary>
        /// <param name="A"> The left side matrix of the subtraction operator.</param>
        /// <param name="B">The right side matrix of the subtraction operator.</param>
        /// <returns>A matrix that represents the result of the matrix subtraction.</returns>
        public static SymmetricBandMatrix operator -(SymmetricBandMatrix A, SymmetricBandMatrix B)
        {
            if (B.RowCount != A.RowCount || B.ColumnCount != A.ColumnCount || B.LowerBandWidth != A.LowerBandWidth || B.UpperBandWidth != A.UpperBandWidth)
            {
                throw new System.ArgumentException("Matrix dimensions are not valid.");
            }

            SymmetricBandMatrix C = new SymmetricBandMatrix(A.RowCount, A.LowerBandWidth);

            double[] AData = A.Data;
            double[] BData = B.Data;
            double[] CData = C.Data;

            for (int i = 0; i < AData.Length; i++)
            {
                CData[i] = AData[i] - BData[i];
            }

            return C;
        }
예제 #8
0
        /// <summary>
        /// Scalar-Matrix multiplication.
        /// </summary>
        /// <param name="s"> The left side scalar of the multiplication operator.</param>
        /// <param name="A">The right side matrix of the multiplication operator.</param>
        /// <returns>A matrix that represents the result of the multiplication.</returns>
        public static SymmetricBandMatrix operator *(double s, SymmetricBandMatrix A)
        {
            SymmetricBandMatrix C = new SymmetricBandMatrix(A.RowCount, A.LowerBandWidth);

            double[] AData = A.Data;
            double[] CData = C.Data;

            Matrix.MultiplicationSM(s, AData, CData);

            return C;
        }
예제 #9
0
        /// <summary>
        ///Computes all the eigenvalues and eigenvectors of
        /// a real symmetric band matrix A.
        /// </summary>
        /// <param name="A">The real symmetric band matrix A.</param>
        /// <param name="EigenVects">The eigenvectors.</param>
        /// <returns>The eigenvalues.</returns>
        public Matrix GetEigenvalues(SymmetricBandMatrix A, out Matrix EigenVects)
        {
            if (this._dsbev == null) this._dsbev = new DSBEV();
            this.CheckDimensions(A);

            Matrix SymmetricBand = A.GetSymmetricBandPackedMatrix();
            double[] SymmetricBandData = SymmetricBand.Data;
            EigenVects = new Matrix(A.RowCount, A.ColumnCount);
            double[] EigenVectsData = EigenVects.Data;
            Matrix EigenVals = new Matrix(A.RowCount, 1);
            double[] EigenValsData = EigenVals.Data;
            int Info = 0;

            double[] Work = new double[3 * A.RowCount - 2];

            _dsbev.Run("V", "U", A.RowCount, A.UpperBandWidth, ref SymmetricBandData, 0, SymmetricBand.RowCount, ref EigenValsData, 0, ref EigenVectsData, 0, A.RowCount, ref Work, 0, ref Info);

            #region Error
            /// = 0:  successful exit
            /// .LT. 0:  if INFO = -i, the i-th argument had an illegal value
            /// .GT. 0:  if INFO = i, the algorithm failed to converge; i
            /// off-diagonal elements of an intermediate tridiagonal
            /// form did not converge to zero.

            if (Info < 0)
            {
                string infoSTg = Math.Abs(Info).ToString();
                throw new ArgumentException("the " + infoSTg + " -th argument had an illegal value");
            }
            else if (Info > 0)
            {
                string infoSTg = Math.Abs(Info).ToString();
                throw new Exception("The algorithm failed to converge.");
            }

            #endregion

            return EigenVals;
        }
예제 #10
0
        /// <summary>
        /// Creates a copy of the matrix.
        /// </summary>
        /// <returns>The copy of the Matrix.</returns>
        public SymmetricBandMatrix Clone()
        {
            SymmetricBandMatrix NewBandMatix = new SymmetricBandMatrix(this._RowCount, this.MeLowerBandWidth, this._Data);

            return(NewBandMatix);
        }