Exemplo n.º 1
0
        public T 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");
            }
            TkMatrix <T> rs = new TkMatrix <T>(rowlen - 1, collen - 1);


            T factor = (ridx + cidx) % 2 == 0 ? _tIdentity : _tIdentity.Negative();

            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.Multiply(rs.determinant()));
        }
Exemplo n.º 2
0
        public static TkMatrix <T> operator /(T r, TkMatrix <T> m)
        {
            TkMatrix <T> rs = new TkMatrix <T>(m);

            for (int i = 0; i < rs.RowLen; i++)
            {
                for (int j = 0; j < rs.ColLen; j++)
                {
                    rs.m_data[i, j] = rs.m_data[i, j].Divide(r);
                }
            }
            return(rs);
        }
Exemplo n.º 3
0
        public override TkMatrix <T> GetNormalization()
        {
            var rs = new TkMatrix <T>(this.RowLen, this.ColLen);

            for (int i = 0; i < RowLen; i++)
            {
                for (int j = 0; j < ColLen; j++)
                {
                    rs.m_data[i, j] = this.m_data[i, j].GetNormalization();
                }
            }
            return(rs);
        }
Exemplo n.º 4
0
        public TkMatrix <T> adj()
        {
            TkMatrix <T> rs = new TkMatrix <T>(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);
        }
Exemplo n.º 5
0
        public static TkMatrix <T> operator *(TkMatrix <T> m, T r)
        {
            TkMatrix <T> rs = new TkMatrix <T>(m);

            for (int i = 0; i < rs.RowLen; i++)
            {
                for (int j = 0; j < rs.ColLen; j++)
                {
                    rs.m_data[i, j] = rs.m_data[i, j].Multiply(r);
                }
            }

            return(rs);
        }
Exemplo n.º 6
0
        public void set(TkMatrix <T> 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];
                }
            }
        }
Exemplo n.º 7
0
        public static TkMatrix <T> operator *(TkMatrix <T> m1, TkMatrix <T> m2)
        {
            TkMatrix <T> rs = new TkMatrix <T>(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] = _tZero;
                    for (int k = 0; k < rs.ColLen; k++)
                    {
                        rs.m_data[i, j] = rs.m_data[i, j].Add(m1.m_data[i, k].Multiply(m2.m_data[k, j]));
                    }
                }
            }
            return(rs);
        }
Exemplo n.º 8
0
        public TkMatrix <T> rowOperateAddMultiple_zb(int rowi, int rowj, T factork)
        {
            TkMatrix <T> rs = new TkMatrix <T>(this.RowLen, this.ColLen);

            for (int colIdx = 0; colIdx < rs.ColLen; colIdx++)
            {
                rs.m_data[rowj, colIdx] = this.m_data[rowj, colIdx].Add(factork.Multiply(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);
        }
Exemplo n.º 9
0
        public TkMatrix <T> rowOperateExchange_zb(int rowi, int rowj)
        {
            TkMatrix <T> rs = new TkMatrix <T>(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);
        }
Exemplo n.º 10
0
 public TkMatrix(TkMatrix <T> matrix)
 {
     this.m_data = new T[matrix.RowLen, matrix.ColLen]; this.set(matrix);
 }