예제 #1
0
        /// <summary>
        /// MATLAB function 'eigs' (eigenvalues and eigenvectors);
        /// </summary>
        /// <param name="M">
        /// A sparse Matrix.
        /// </param>
        /// <param name="__WorkingPath"></param>
        public static (double[] EigenVals, MultidimensionalArray EigenVect) eigsV(this IMatrix M, string __WorkingPath = null)
        {
            using (var connector = new BatchmodeConnector(WorkingPath: __WorkingPath)) {
                if (M == null)
                {
                    throw new ArgumentNullException();
                }
                if (M.NoOfCols != M.NoOfRows)
                {
                    throw new ArgumentException("Not supported for non-symmetrical matrices.");
                }
                int N = M.NoOfCols;

                MultidimensionalArray eVect = MultidimensionalArray.Create(N, N);
                MultidimensionalArray eVal  = MultidimensionalArray.Create(N, 1);
                connector.PutMatrix(M, "Matrix");
                connector.Cmd(string.Format("[V,D] = eigs(Matrix,{0});", M.NoOfCols));
                connector.Cmd(string.Format("ev = diag(D);"));
                connector.GetMatrix(eVect, "V");
                connector.GetMatrix(eVal, "ev");

                connector.Execute(false);

                return(eVal.GetColumn(0), eVect);
            }
        }
예제 #2
0
파일: Extensions.cs 프로젝트: xyuan/BoSSS
        /// <summary>
        /// Evaluation of the condition number of a full matrix
        /// <paramref name="M"/>.
        /// </summary>
        /// <param name="M">A full square matrix</param>
        /// <param name="workingPath"></param>
        /// <returns>
        /// The condition number of <paramref name="M"/>
        /// </returns>
        public static double cond(this IMatrix M, string workingPath = null)
        {
            using (var connector = new BatchmodeConnector(WorkingPath: workingPath)) {
                MultidimensionalArray output = MultidimensionalArray.Create(1, 1);
                connector.PutMatrix(M, "Matrix");
                connector.Cmd("cond = cond(Matrix)");
                connector.GetMatrix(output, "cond");

                connector.Execute(false);

                return(output[0, 0]);
            }
        }
예제 #3
0
파일: Extensions.cs 프로젝트: xyuan/BoSSS
        /// <summary>
        /// Evaluation of the eigenvalues of a full matrix
        /// <paramref name="M"/>.
        /// </summary>
        /// <param name="M">A full square matrix</param>
        /// <param name="workingPath"></param>
        /// <returns>
        /// The eigenvalues of <paramref name="M"/> in ascending order
        /// </returns>
        public static double[] eig(this IMatrix M, string workingPath = null)
        {
            if (M.NoOfCols != M.NoOfRows)
            {
                throw new ArgumentException("Matrix must be square");
            }

            using (var connector = new BatchmodeConnector(WorkingPath: workingPath)) {
                MultidimensionalArray output = MultidimensionalArray.Create(M.NoOfCols, 1);
                connector.PutMatrix(M, "Matrix");
                connector.Cmd("eig = eig(Matrix)");
                connector.GetMatrix(output, "eig");

                connector.Execute(false);

                return(output.Storage);
            }
        }
예제 #4
0
        /// <summary>
        /// MATLAB function 'eigs' (eigenvalues of a dense matrix);
        /// </summary>
        /// <param name="M">
        /// A sparse Matrix.
        /// </param>
        /// <param name="__WorkingPath"></param>
        public static double[] eigs(this IMatrix M, string __WorkingPath = null)
        {
            using (var connector = new BatchmodeConnector(WorkingPath: __WorkingPath)) {
                if (M == null)
                {
                    throw new ArgumentNullException();
                }
                if (M.NoOfCols != M.NoOfRows)
                {
                    throw new ArgumentException("Not supported for non-symmetrical matrices.");
                }
                int N = M.NoOfCols;

                MultidimensionalArray output = MultidimensionalArray.Create(N, 1);
                connector.PutMatrix(M, "Matrix");
                connector.Cmd(string.Format("EV = eigs(Matrix,{0});", M.NoOfCols));
                connector.GetMatrix(output, "EV");

                connector.Execute(false);

                return(output.GetColumn(0));
            }
        }