예제 #1
0
파일: RtwMatrix.cs 프로젝트: Lannyland/IPPA
        //determinent
        public float Determinant()
        {
            float determinent = 0;

            if(this.Rows != this.Columns)
                throw new RtwMatrixException("Attempt to find the determinent of a non square matrix");
                //return 0;

            //get the determinent of a 2x2 matrix
            if(this.Rows == 2 && this.Columns == 2)
            {
                determinent = (this[0,0] * this[1,1]) - (this[0,1] * this[1,0]);
                return determinent;
            }

            RtwMatrix tempMtx = new RtwMatrix(this.Rows - 1, this.Columns - 1);

            //find the determinent with respect to the first row
            for(int j = 0; j < this.Columns; j++)
            {

                tempMtx = this.Minor(0, j);

                //recursively add the determinents
                determinent += (int)Math.Pow(-1, j) * this[0,j] * tempMtx.Determinant();

            }

            return determinent;
        }
예제 #2
0
파일: RtwMatrix.cs 프로젝트: Lannyland/IPPA
        //adjoint matrix
        public RtwMatrix Adjoint()
        {
            if(this.Rows < 2 || this.Columns < 2)
                throw new RtwMatrixException("Adjoint matrix not available");

            RtwMatrix tempMtx = new RtwMatrix(this.Rows-1 , this.Columns-1);
            RtwMatrix adjMtx = new RtwMatrix (this.Columns , this.Rows);

            for(int i = 0; i < this.Rows; i++)
            {
                for(int j = 0; j < this.Columns;j++)
                {

                    tempMtx = this.Minor(i, j);

                    //put the determinent of the minor in the transposed position
                    adjMtx[j,i] = (int)Math.Pow(-1,i+j) * tempMtx.Determinant();
                }
            }

            return adjMtx;
        }