Пример #1
0
        public void solveModel()
        {
            int n = 5;
            IElementalAccessMatrix A = new SparseRowMatrix(n, n, 5);
            IElementalAccessVector b = new DenseVector(n), x = new DenseVector(n);

            x.SetValue(0, 0.1);
            x.SetValue(1, 0.2);
            x.SetValue(2, 0.3);
            x.SetValue(3, 0.4);
            x.SetValue(4, 0.5);
            b = new DenseVector(x.Length);

            for (int it = 0; it < 100; it++)
            {
                model(b, x);
                grad(A, x);
                IElementalAccessVector dx     = new DenseVector(n);
                ILinearSolver          solver = new BiCGSolver();
                IPreconditioner        M      = new IdentityPreconditioner();
                DefaultLinearIteration iter   = new DefaultLinearIteration();
                iter.SetParameters(1e-10, 1e-50, 1e+5, 1000000);
                double[] ans = solve(A, b, dx, solver, M, iter);
                for (int i = 0; i < x.Length; i++)
                {
                    x.AddValue(i, -0.2 * dx.GetValue(i));
                }
                int iii = 1;
            }
        }
Пример #2
0
        private void Helper1(IElementalAccessMatrix A, IElementalAccessVector b, IElementalAccessVector x)
        {
            // Test of usual solvers and preconditoners
            ILinearSolver[] solver = new ILinearSolver[]
            {
                new BiCGSolver(),
                new BiCGstabSolver(),
                //new CGSolver(),
                new CGSSolver(),
                new GMRESSolver(),
                new QMRSolver()
            };

            IPreconditioner[] M = new IPreconditioner[]
            {
                new IdentityPreconditioner(),
                //new ILUPreconditioner(new SparseRowMatrix(A.RowCount, A.ColumnCount))
            };

            DefaultLinearIteration iter = new DefaultLinearIteration();

            iter.SetParameters(1e-10, 1e-50, 1e+5, 1000000);

            for (int i = 0; i < solver.Length; ++i)
            {
                for (int j = 0; j < M.Length; ++j)
                {
                    Helper2(A, b, x, solver[i], M[j], iter);
                }
            }
        }