toop_project.src.Matrix.DiagonalMatrix.LU C# (CSharp) Method

LU() public method

public LU ( ) : BaseMatrix
return BaseMatrix
        public override BaseMatrix LU()
        {
            var newal = new double[al.Length][];
            for (int i = 0; i < al.Length; i++)
                newal[i] = al[i].Clone() as double[];

            var matrPrec = new DiagonalMatrix(di.Clone() as double[], newal, au, shift_l, shift_u);
            // Деление всего нижнего треугольника на элементы главной диагонали, причём
            // элементы j-го столбца деляться на di[j]

            for (int l_diags = 0; l_diags < shift_l.Length; l_diags++)
                for (int j = 0, indl = shift_l[l_diags]; indl < al.Length; j++, indl++)
                    matrPrec.al[indl][l_diags] /= matrPrec.di[j];

            // Для расчёта новых di, необходимы произведения симметричных элементов
            // для этого нахожим одинаковые смещения
            HashSet<int> shift = new HashSet<int>(shift_l); // одинаковые смещения
            shift.IntersectWith(shift_u);

            if (shift.Count != 0)
                for (int i = 1; i < di.Length; i++)
                {
                    double sum = 0;
                    for (int k = 0; k < shift_l.Length; k++)
                        sum += matrPrec.al[i][k] * matrPrec.au[i][k];
                    matrPrec.di[i] -= sum;
                }
            return matrPrec;
        }