Esempio n. 1
0
        /// <summary>
        /// 指定された行列の逆行列を作成する.
        /// </summary>
        /// <param name="X">逆行列を求める行列(書き換えられることはない)</param>
        /// <returns>Xの逆行列</returns>
        public static Matrix Inverse(Matrix X)
        {
            MatrixChecker.IsSquare(X);
            Solver solver = new Solver(X, (new Matrix(X.RowSize, X.ColumnSize)).Identity());

            return(solver.X);
        }
Esempio n. 2
0
        /// <summary>
        /// 逆行列を返す.
        /// </summary>
        /// <param name="m">逆行列を求める行列(書き換えられることはない)</param>
        /// <returns></returns>
        public static Matrix Inverse(Matrix m)
        {
            MatrixChecker.IsSquare(m);
            Solved result = Func.Solve(m, (new Matrix(m.RowSize, m.ColumnSize)).Identity());

            return(result.X);
        }
Esempio n. 3
0
        /// <summary>
        /// 固有値分解
        /// </summary>
        /// <param name="x">正方行列</param>
        /// <returns></returns>
        public static Eigen Eigen(Matrix x)
        {
            MatrixChecker.IsSquare(x);

            if (x.RowSize < 2)
            {
                throw new ArgumentException("Matrix size is less than 2.");
            }

            Matrix tmp = new Matrix(x);

            Vector _reValues = new Vector();
            Vector _imValues = new Vector();

            double[][] r_vecs = null;
            double[][] i_vecs = null;

            krdlab.law.func.dgeev(tmp._body, tmp._rsize, tmp._csize,
                                  ref _reValues._body, ref _imValues._body, ref r_vecs, ref i_vecs);

            List <Vector> _reVectors = new List <Vector>();
            List <Vector> _imVectors = new List <Vector>();

            foreach (double[] vec in r_vecs)
            {
                _reVectors.Add(new Vector(vec));
            }

            foreach (double[] vec in i_vecs)
            {
                _imVectors.Add(new Vector(vec));
            }
            return(new Eigen(_reValues, _imValues, _reVectors, _imVectors));
        }
Esempio n. 4
0
 /// <summary>
 /// この行列を単位行列(I = diag(1,1,...,1))にする.
 /// </summary>
 /// <returns></returns>
 public Matrix Identity()
 {
     MatrixChecker.IsSquare(this);
     this.Zero();
     for (int i = 0; i < this.RowSize; ++i)
     {
         this[i, i] = 1;
     }
     return(this);
 }
Esempio n. 5
0
        /// <summary>
        /// AX = B を解く.
        /// </summary>
        /// <param name="a">[n, n] 行列</param>
        /// <param name="b">[n, *] 行列</param>
        /// <returns></returns>
        public static Solved Solve(Matrix a, Matrix b)
        {
            MatrixChecker.IsSquare(a);
            Matrix _a = new Matrix(a);
            Matrix _b = new Matrix(b);
            Matrix x  = new Matrix();

            krdlab.law.func.dgesv(ref x._body, ref x._rsize, ref x._csize,
                                  _a._body, _a._rsize, _a._csize, _b._body, _b._rsize, _b._csize);
            return(new Solved(x));
        }
Esempio n. 6
0
        /// <summary>
        /// 逆行列化する.
        /// </summary>
        /// <returns>逆行列化後の自身への参照</returns>
        /// <exception cref="Exception.NotSquareMatrixException">
        /// 正方行列でないときに throw される.
        /// </exception>
        public Matrix Inverse()
        {
            MatrixChecker.IsSquare(this);

            Matrix A = new Matrix(this);

            this.Identity();

            clapack.Function.dgesv(ref this._body, ref this._rsize, ref this._csize,
                                   A._body, A._rsize, A._csize, this._body, this._rsize, this._csize);

            return(this);
        }
Esempio n. 7
0
        /// <summary>
        /// 逆行列化する.
        /// </summary>
        /// <returns>逆行列化後の自身への参照</returns>
        /// <exception cref="System.ArgumentException">
        /// 正方行列でないときに throw される.
        /// </exception>
        public Matrix Inverse()
        {
            MatrixChecker.IsSquare(this);

            Matrix A = new Matrix(this);

            this.Identity();

            krdlab.law.func.dgesv(ref this._body, ref this._rsize, ref this._csize,
                                  A._body, A._rsize, A._csize, this._body, this._rsize, this._csize);

            return(this);
        }