Ejemplo n.º 1
0
        public Vector Solve(Slae <ProfileMatrix> SLAE, Vector Initial, int maxiter, double eps)
        {
            int    iterNum;
            double pr, pr1, alpha, betta, residual;
            Vector Az;

            Vector r = new Vector(SLAE.RightPart.Differ(SLAE.Matrix.Multiply(Initial)));

            Vector result = new Vector(Initial);

            residual = r.Norm() / SLAE.RightPart.Norm();
            Vector z = new Vector(r);
            Vector s = new Vector(r);
            Vector p = new Vector(r);

            pr1 = p.Scalar(r);
            for (iterNum = 0; iterNum < maxiter && residual >= eps; iterNum++)
            {
                Az       = SLAE.Matrix.Multiply(z);
                alpha    = pr1 / Az.Scalar(s);
                result   = result.Sum(z.Mult(alpha));
                r        = r.Differ(Az.Mult(alpha));
                p        = p.Differ(SLAE.Matrix.TMultiply(s).Mult(alpha));
                pr       = p.Scalar(r);
                betta    = pr / pr1;
                pr1      = pr;
                z        = r.Sum(z.Mult(betta));
                s        = p.Sum(s.Mult(betta));
                residual = r.Norm() / SLAE.RightPart.Norm();
                if (!autotest)
                {
                    if (!InputOutput.OutputIterationToForm(iterNum, residual, maxiter, false))
                    {
                        MessageBox.Show("Ошибка при выводе данных на форму.", "Опаньки...", MessageBoxButtons.OK);
                    }
                }
            }
            if (!autotest)
            {
                if (!InputOutput.OutputIterationToForm(iterNum - 1, residual, maxiter, true))
                {
                    MessageBox.Show("Ошибка при выводе данных на форму.", "Опаньки...", MessageBoxButtons.OK);
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        public Vector Solve(Slae<DenseMatrix> SLAE, Vector Initial, int maxiter, double eps)
        {
            int iterNum;
            double pr, pr1, alpha, betta, residual;
            Vector Az;

            Vector r = new Vector(SLAE.RightPart.Differ(SLAE.Matrix.Multiply(Initial)));

            Vector result = new Vector(Initial);

            residual = r.Norm() / SLAE.RightPart.Norm();
            Vector z = new Vector(r);
            Vector s = new Vector(r);
            Vector p = new Vector(r);
            pr1 = p.Scalar(r);
            for (iterNum = 0; iterNum < maxiter && residual >= eps; iterNum++)
            {
                Az = SLAE.Matrix.Multiply(z);
                alpha = pr1 / Az.Scalar(s);
                result = result.Sum(z.Mult(alpha));
                r = r.Differ(Az.Mult(alpha));
                p = p.Differ(SLAE.Matrix.TMultiply(s).Mult(alpha));
                pr = p.Scalar(r);
                betta = pr / pr1;
                pr1 = pr;
                z = r.Sum(z.Mult(betta));
                s = p.Sum(s.Mult(betta));
                residual = r.Norm() / SLAE.RightPart.Norm();
                if (!autotest)
                {
                    if (!InputOutput.OutputIterationToForm(iterNum, residual, maxiter, false))
                        MessageBox.Show("Ошибка при выводе данных на форму.", "Опаньки...", MessageBoxButtons.OK);
                }
            }
            if (!autotest)
            {
                if (!InputOutput.OutputIterationToForm(iterNum - 1, residual, maxiter, true))
                    MessageBox.Show("Ошибка при выводе данных на форму.", "Опаньки...", MessageBoxButtons.OK);
            }
            return result;
        }
Ejemplo n.º 3
0
        public Vector Solve(Slae<ProfileMatrix> SLAE, Vector Initial, int maxiter, double eps)
        {
            int iterNum;
            double iner_r,iner_mr, alpha, betta, residual;
            Vector Az, Mr;

            Vector r = new Vector(SLAE.RightPart.Differ(SLAE.Matrix.Multiply(Initial)));

            Vector result = new Vector(Initial);

            residual = r.Norm() / SLAE.RightPart.Norm();
            if (Data.preconditioner == 0)//нет предобуславливания
            {
                Vector z = new Vector(r);
                for (iterNum = 0; iterNum < maxiter && residual >= eps; iterNum++)
                {
                    iner_r = r.Scalar(r);
                    Az = SLAE.Matrix.Multiply(z);
                    alpha = r.Scalar(r) / Az.Scalar(z);
                    result = result.Sum(z.Mult(alpha));
                    r = r.Differ(Az.Mult(alpha));
                    betta = r.Scalar(r) / iner_r;
                    z = r.Sum(z.Mult(betta));

                    residual = r.Norm() / SLAE.RightPart.Norm();
                    if (!autotest)
                    {
                        if (!InputOutput.OutputIterationToForm(iterNum, residual, maxiter, false))
                            MessageBox.Show("Ошибка при выводе данных на форму.", "Опаньки...", MessageBoxButtons.OK);
                    }
                }
                if (!autotest)
                {
                    if (!InputOutput.OutputIterationToForm(iterNum - 1, residual, maxiter, true))
                        MessageBox.Show("Ошибка при выводе данных на форму.", "Опаньки...", MessageBoxButtons.OK);
                }
            }
            else
                if (Data.preconditioner == 1 || Data.preconditioner == 2 || Data.preconditioner == 3 || Data.preconditioner == 4)//диагональное предобуславливание или Неполное разложение Холесского
                {
                    Vector z = new Vector(SLAE.PMatrix.ReverseProgress(SLAE.PMatrix.DirectProgress(r)));
                    for (iterNum = 0; iterNum < maxiter && residual >= eps; iterNum++)
                    {
                        Mr = SLAE.PMatrix.ReverseProgress(SLAE.PMatrix.DirectProgress(r));//M^-1*r(k-1)
                        Az = SLAE.Matrix.Multiply(z);//A*z(k-1)
                        alpha = Mr.Scalar(r) / Az.Scalar(z);
                        result = result.Sum(z.Mult(alpha));
                        iner_mr = Mr.Scalar(r);//(M^-1*r(k-1),r(k-1))
                        r = r.Differ(Az.Mult(alpha));
                        Mr = SLAE.PMatrix.ReverseProgress(SLAE.PMatrix.DirectProgress(r));
                        betta = Mr.Scalar(r) / iner_mr;
                        z = Mr.Sum(z.Mult(betta));

                        residual = r.Norm() / SLAE.RightPart.Norm();
                        if (!autotest)
                        {
                            if (!InputOutput.OutputIterationToForm(iterNum, residual, maxiter, false))
                                MessageBox.Show("Ошибка при выводе данных на форму.", "Опаньки...", MessageBoxButtons.OK);
                        }
                    }
                    if (!autotest)
                    {
                        if (!InputOutput.OutputIterationToForm(iterNum - 1, residual, maxiter, true))
                            MessageBox.Show("Ошибка при выводе данных на форму.", "Опаньки...", MessageBoxButtons.OK);
                    }
                }
                return result;
        }
Ejemplo n.º 4
0
        public Vector Solve(Slae <ProfileMatrix> SLAE, Vector Initial, int maxiter, double eps)
        {
            int    iterNum;
            double iner_r, iner_mr, alpha, betta, residual;
            Vector Az, Mr;

            Vector r = new Vector(SLAE.RightPart.Differ(SLAE.Matrix.Multiply(Initial)));

            Vector result = new Vector(Initial);

            residual = r.Norm() / SLAE.RightPart.Norm();
            if (Data.preconditioner == 0)//нет предобуславливания
            {
                Vector z = new Vector(r);
                for (iterNum = 0; iterNum < maxiter && residual >= eps; iterNum++)
                {
                    iner_r = r.Scalar(r);
                    Az     = SLAE.Matrix.Multiply(z);
                    alpha  = r.Scalar(r) / Az.Scalar(z);
                    result = result.Sum(z.Mult(alpha));
                    r      = r.Differ(Az.Mult(alpha));
                    betta  = r.Scalar(r) / iner_r;
                    z      = r.Sum(z.Mult(betta));

                    residual = r.Norm() / SLAE.RightPart.Norm();
                    if (!autotest)
                    {
                        if (!InputOutput.OutputIterationToForm(iterNum, residual, maxiter, false))
                        {
                            MessageBox.Show("Ошибка при выводе данных на форму.", "Опаньки...", MessageBoxButtons.OK);
                        }
                    }
                }
                if (!autotest)
                {
                    if (!InputOutput.OutputIterationToForm(iterNum - 1, residual, maxiter, true))
                    {
                        MessageBox.Show("Ошибка при выводе данных на форму.", "Опаньки...", MessageBoxButtons.OK);
                    }
                }
            }
            else
            if (Data.preconditioner == 1 || Data.preconditioner == 2 || Data.preconditioner == 3 || Data.preconditioner == 4)    //диагональное предобуславливание или Неполное разложение Холесского
            {
                Vector z = new Vector(SLAE.PMatrix.ReverseProgress(SLAE.PMatrix.DirectProgress(r)));
                for (iterNum = 0; iterNum < maxiter && residual >= eps; iterNum++)
                {
                    Mr      = SLAE.PMatrix.ReverseProgress(SLAE.PMatrix.DirectProgress(r)); //M^-1*r(k-1)
                    Az      = SLAE.Matrix.Multiply(z);                                      //A*z(k-1)
                    alpha   = Mr.Scalar(r) / Az.Scalar(z);
                    result  = result.Sum(z.Mult(alpha));
                    iner_mr = Mr.Scalar(r);    //(M^-1*r(k-1),r(k-1))
                    r       = r.Differ(Az.Mult(alpha));
                    Mr      = SLAE.PMatrix.ReverseProgress(SLAE.PMatrix.DirectProgress(r));
                    betta   = Mr.Scalar(r) / iner_mr;
                    z       = Mr.Sum(z.Mult(betta));

                    residual = r.Norm() / SLAE.RightPart.Norm();
                    if (!autotest)
                    {
                        if (!InputOutput.OutputIterationToForm(iterNum, residual, maxiter, false))
                        {
                            MessageBox.Show("Ошибка при выводе данных на форму.", "Опаньки...", MessageBoxButtons.OK);
                        }
                    }
                }
                if (!autotest)
                {
                    if (!InputOutput.OutputIterationToForm(iterNum - 1, residual, maxiter, true))
                    {
                        MessageBox.Show("Ошибка при выводе данных на форму.", "Опаньки...", MessageBoxButtons.OK);
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 5
0
        public Vector Solve(Slae<DisperseMatrix> SLAE, Vector Initial, int maxiter, double eps)
        {
            int iterNum;
            double iner_p, alpha, betta, residual;
            Vector Ar;

            Vector result = new Vector(Initial);

            if (Data.preconditioner == 0)//нет предобуславливания
            {
                Vector r = new Vector(SLAE.RightPart.Differ(SLAE.Matrix.Multiply(Initial)));
                Vector z = new Vector(r);
                Vector p = new Vector(SLAE.Matrix.Multiply(z));

                residual = Math.Sqrt(r.Scalar(r)) / SLAE.RightPart.Norm();

                for (iterNum = 0; iterNum < maxiter && residual >= eps; iterNum++)
                {
                    iner_p = p.Scalar(p);
                    alpha = p.Scalar(r) / iner_p;
                    result = result.Sum(z.Mult(alpha));
                    r = r.Differ(p.Mult(alpha));
                    Ar = SLAE.Matrix.Multiply(r);
                    betta = -p.Scalar(Ar) / iner_p;
                    z = r.Sum(z.Mult(betta));
                    p = Ar.Sum(p.Mult(betta));

                    residual = Math.Sqrt(r.Scalar(r)) / SLAE.RightPart.Norm();
                    if (!autotest)
                    {
                        if (!InputOutput.OutputIterationToForm(iterNum, residual, maxiter, false))
                            MessageBox.Show("Ошибка при выводе данных на форму.", "Опаньки...", MessageBoxButtons.OK);
                    }
                }
                if (!autotest)
                {
                    if (!InputOutput.OutputIterationToForm(iterNum - 1, residual, maxiter, true))
                        MessageBox.Show("Ошибка при выводе данных на форму.", "Опаньки...", MessageBoxButtons.OK);
                }
            }
            else
                if (Data.preconditioner == 1 || Data.preconditioner == 2 || Data.preconditioner == 3 || Data.preconditioner == 4)//LU или LU(sq)-предобуславливание
                {
                    Vector fAx = new Vector(SLAE.RightPart.Differ(SLAE.Matrix.Multiply(result)));
                    Vector r = new Vector(SLAE.PMatrix.DirectProgress(fAx));
                    Vector z = new Vector(SLAE.PMatrix.ReverseProgress(r));
                    Vector p = new Vector(SLAE.PMatrix.DirectProgress(SLAE.Matrix.Multiply(z)));

                    if ((r == null) || (z == null) || (p == null)) return null;

                    residual = Math.Sqrt(r.Scalar(r)) / SLAE.RightPart.Norm();

                    for (iterNum = 0; iterNum < maxiter && residual >= eps; iterNum++)
                    {
                        iner_p = p.Scalar(p);
                        alpha = p.Scalar(r) / iner_p;
                        result = result.Sum(z.Mult(alpha));
                        r = r.Differ(p.Mult(alpha));
                        Ar = SLAE.PMatrix.DirectProgress(SLAE.Matrix.Multiply(SLAE.PMatrix.ReverseProgress(r)));//L^-1*A*U^-1*r(k)
                        betta = -p.Scalar(Ar) / iner_p;
                        z = SLAE.PMatrix.ReverseProgress(r).Sum(z.Mult(betta));
                        p = Ar.Sum(p.Mult(betta));

                        residual = Math.Sqrt(r.Scalar(r)) / SLAE.RightPart.Norm();
                        if (!autotest)
                        {
                            if (!InputOutput.OutputIterationToForm(iterNum, residual, maxiter, false))
                                MessageBox.Show("Ошибка при выводе данных на форму.", "Опаньки...", MessageBoxButtons.OK);
                        }
                    }
                    if (!autotest)
                    {
                        if (!InputOutput.OutputIterationToForm(iterNum - 1, residual, maxiter, true))
                            MessageBox.Show("Ошибка при выводе данных на форму.", "Опаньки...", MessageBoxButtons.OK);
                    }
                }
                return result;
        }
Ejemplo n.º 6
0
        public Vector Solve(Slae <DisperseMatrix> SLAE, Vector Initial, int maxiter, double eps)
        {
            int    iterNum;
            double iner_p, alpha, betta, residual;
            Vector Ar;

            Vector result = new Vector(Initial);


            if (Data.preconditioner == 0)//нет предобуславливания
            {
                Vector r = new Vector(SLAE.RightPart.Differ(SLAE.Matrix.Multiply(Initial)));
                Vector z = new Vector(r);
                Vector p = new Vector(SLAE.Matrix.Multiply(z));

                residual = Math.Sqrt(r.Scalar(r)) / SLAE.RightPart.Norm();

                for (iterNum = 0; iterNum < maxiter && residual >= eps; iterNum++)
                {
                    iner_p = p.Scalar(p);
                    alpha  = p.Scalar(r) / iner_p;
                    result = result.Sum(z.Mult(alpha));
                    r      = r.Differ(p.Mult(alpha));
                    Ar     = SLAE.Matrix.Multiply(r);
                    betta  = -p.Scalar(Ar) / iner_p;
                    z      = r.Sum(z.Mult(betta));
                    p      = Ar.Sum(p.Mult(betta));

                    residual = Math.Sqrt(r.Scalar(r)) / SLAE.RightPart.Norm();
                    if (!autotest)
                    {
                        if (!InputOutput.OutputIterationToForm(iterNum, residual, maxiter, false))
                        {
                            MessageBox.Show("Ошибка при выводе данных на форму.", "Опаньки...", MessageBoxButtons.OK);
                        }
                    }
                }
                if (!autotest)
                {
                    if (!InputOutput.OutputIterationToForm(iterNum - 1, residual, maxiter, true))
                    {
                        MessageBox.Show("Ошибка при выводе данных на форму.", "Опаньки...", MessageBoxButtons.OK);
                    }
                }
            }
            else
            if (Data.preconditioner == 1 || Data.preconditioner == 2 || Data.preconditioner == 3 || Data.preconditioner == 4)    //LU или LU(sq)-предобуславливание
            {
                Vector fAx = new Vector(SLAE.RightPart.Differ(SLAE.Matrix.Multiply(result)));
                Vector r   = new Vector(SLAE.PMatrix.DirectProgress(fAx));
                Vector z   = new Vector(SLAE.PMatrix.ReverseProgress(r));
                Vector p   = new Vector(SLAE.PMatrix.DirectProgress(SLAE.Matrix.Multiply(z)));

                if ((r == null) || (z == null) || (p == null))
                {
                    return(null);
                }

                residual = Math.Sqrt(r.Scalar(r)) / SLAE.RightPart.Norm();

                for (iterNum = 0; iterNum < maxiter && residual >= eps; iterNum++)
                {
                    iner_p = p.Scalar(p);
                    alpha  = p.Scalar(r) / iner_p;
                    result = result.Sum(z.Mult(alpha));
                    r      = r.Differ(p.Mult(alpha));
                    Ar     = SLAE.PMatrix.DirectProgress(SLAE.Matrix.Multiply(SLAE.PMatrix.ReverseProgress(r)));//L^-1*A*U^-1*r(k)
                    betta  = -p.Scalar(Ar) / iner_p;
                    z      = SLAE.PMatrix.ReverseProgress(r).Sum(z.Mult(betta));
                    p      = Ar.Sum(p.Mult(betta));

                    residual = Math.Sqrt(r.Scalar(r)) / SLAE.RightPart.Norm();
                    if (!autotest)
                    {
                        if (!InputOutput.OutputIterationToForm(iterNum, residual, maxiter, false))
                        {
                            MessageBox.Show("Ошибка при выводе данных на форму.", "Опаньки...", MessageBoxButtons.OK);
                        }
                    }
                }
                if (!autotest)
                {
                    if (!InputOutput.OutputIterationToForm(iterNum - 1, residual, maxiter, true))
                    {
                        MessageBox.Show("Ошибка при выводе данных на форму.", "Опаньки...", MessageBoxButtons.OK);
                    }
                }
            }
            return(result);
        }