示例#1
0
 public SubMatrix(SubMatrix subMatrix, int startSubRow, int startSubCol, int row, int col)
 {
     _startIndex = subMatrix._startIndex + startSubCol + subMatrix._reference.ColCount * startSubRow;
     _reference  = subMatrix._reference;
     RowCount    = row;
     ColCount    = col;
 }
示例#2
0
        public LuDecompositionResult LuSolve()
        {
            if (RowCount != ColCount)
            {
                throw new DataException("row and col must be same");
            }

            var lOrigin = new Matrix(RowCount, ColCount);
            var uOrigin = Matrix.Identity(RowCount);

            var a = new SubMatrix(this.DeepCopy(), 0, 0, RowCount, ColCount);
            var l = new SubMatrix(lOrigin, 0, 0, RowCount, ColCount);
            var u = new SubMatrix(uOrigin, 0, 0, RowCount, ColCount);

            for (int i = 0; i < this.RowCount; i++)
            {
                //l00
                l[0, 0] = a[0, 0];

                //copy l1
                for (int j = 1; j < a.RowCount; j++)
                {
                    l[j, 0] = a[j, 0];
                }

                //copy u1
                for (int j = 1; j < a.RowCount; j++)
                {
                    u[0, j] = a[0, j] / l[0, 0];
                }

                for (int j = 1; j < a.ColCount; j++)
                {
                    for (int k = 1; k < a.ColCount; k++)
                    {
                        a[j, k] -= l[j, 0] * u[0, k];
                    }
                }

                a = new SubMatrix(a, 1, 1, a.RowCount - 1, a.ColCount - 1);
                l = new SubMatrix(l, 1, 1, l.RowCount - 1, l.ColCount - 1);
                u = new SubMatrix(u, 1, 1, u.RowCount - 1, u.ColCount - 1);
            }

            return(new LuDecompositionResult(lOrigin, uOrigin));
        }