Example #1
0
        public float cofactor_zb(int ridx, int cidx)
        {
            int rowlen = this.RowLen;
            int collen = this.ColLen;

            if (rowlen < 2 || collen < 2)
            {
                throw new CtkException("The Length need > 1");
            }
            CtkMatrixf rs = new CtkMatrixf(rowlen - 1, collen - 1);


            int factor = (ridx + cidx) % 2 == 0 ? 1 : -1;

            for (int i = 0, i1 = 0; i < rowlen; i++)
            {
                if (i == ridx)
                {
                    continue;
                }

                for (int j = 0, j1 = 0; j < collen; j++)
                {
                    if (j == cidx)
                    {
                        continue;
                    }
                    rs.m_data[i1, j1] = this.m_data[i, j];
                    j1++;
                }
                i1++;
            }
            return(factor * rs.determinant());
        }
Example #2
0
        public static CtkMatrixf operator /(float r, CtkMatrixf m)
        {
            CtkMatrixf rs = new CtkMatrixf(m);

            for (int i = 0; i < rs.RowLen; i++)
            {
                for (int j = 0; j < rs.ColLen; j++)
                {
                    rs.m_data[i, j] /= r;
                }
            }
            return(rs);
        }
Example #3
0
        public CtkMatrixf adj()
        {
            CtkMatrixf rs = new CtkMatrixf(this.ColLen, this.RowLen);

            for (int i = 0; i < rs.RowLen; i++)
            {
                for (int j = 0; j < rs.ColLen; j++)
                {
                    rs.m_data[i, j] = this.cofactor_zb(j, i);
                }
            }
            return(rs);
        }
Example #4
0
        public void set(CtkMatrixf matrix)
        {
            if (this.RowLen != matrix.RowLen ||
                this.ColLen != matrix.ColLen)
            {
                throw new CtkException("Different length of data");
            }

            for (int i = 0; i < matrix.RowLen; i++)
            {
                for (int j = 0; j < matrix.ColLen; j++)
                {
                    this.m_data[i, j] = matrix.m_data[i, j];
                }
            }
        }
Example #5
0
        public static CtkMatrixf operator *(CtkMatrixf m1, CtkMatrixf m2)
        {
            CtkMatrixf rs = new CtkMatrixf(m1.RowLen, m1.ColLen);

            for (int i = 0; i < rs.RowLen; i++)
            {
                for (int j = 0; j < rs.ColLen; j++)
                {
                    rs.m_data[i, j] = 0;
                    for (int k = 0; k < rs.ColLen; k++)
                    {
                        rs.m_data[i, j] += m1.m_data[i, k] * m2.m_data[k, j];
                    }
                }
            }
            return(rs);
        }
Example #6
0
        public CtkMatrixf rowOperateAddMultiple_zb(int rowi, int rowj, float factork)
        {
            CtkMatrixf rs = new CtkMatrixf(this.RowLen, this.ColLen);

            for (int colIdx = 0; colIdx < rs.ColLen; colIdx++)
            {
                rs.m_data[rowj, colIdx] = this.m_data[rowj, colIdx] + factork * this.m_data[rowi, colIdx];
            }

            for (int rowIdx = 0; rowIdx < rs.RowLen; rowIdx++)
            {
                if (rowIdx == rowj)
                {
                    continue;
                }
                for (int colIdx = 0; colIdx < rs.ColLen; colIdx++)
                {
                    rs.m_data[rowIdx, colIdx] = this.m_data[rowIdx, colIdx];
                }
            }
            return(rs);
        }
Example #7
0
        public CtkMatrixf rowOperateExchange_zb(int rowi, int rowj)
        {
            CtkMatrixf rs = new CtkMatrixf(this.RowLen, this.ColLen);

            for (int colIdx = 0; colIdx < rs.ColLen; colIdx++)
            {
                rs.m_data[rowi, colIdx] = this.m_data[rowj, colIdx];
                rs.m_data[rowj, colIdx] = this.m_data[rowi, colIdx];
            }

            for (int rowIdx = 0; rowIdx < rs.RowLen; rowIdx++)
            {
                if (rowIdx == rowi || rowIdx == rowj)
                {
                    continue;
                }
                for (int colIdx = 0; colIdx < rs.ColLen; colIdx++)
                {
                    rs.m_data[rowIdx, colIdx] = this.m_data[rowIdx, colIdx];
                }
            }
            return(rs);
        }
Example #8
0
 public CtkMatrixf(CtkMatrixf matrix)
 {
     this.m_data = new float[matrix.RowLen, matrix.ColLen]; this.set(matrix);
 }