private void btn_Calcular_Click(object sender, EventArgs e)
        {
            var incognitas  = Convert.ToInt16(txt_NumeroIncognitas.Text);
            var filas       = incognitas;
            var columnas    = incognitas + 1;
            var Tolerancia  = Convert.ToDouble(txt_ErrorRelativo.Text);
            var iteraciones = Convert.ToInt16(txt_Iteraciones.Text);

            ParametroGaussSeided parametro = new ParametroGaussSeided(filas, columnas)
            {
                Tolerancia       = Tolerancia,
                Iteraciones      = iteraciones,
                NumeroIncognitas = incognitas
            };

            for (int i = 0; i < filas; i++)
            {
                for (int c = 0; c < columnas; c++)
                {
                    parametro.Matriz[i, c] = Convert.ToDouble(Matriz[i, c].Text);
                }
            }
            try
            {
                var resultado = MetodosEcuaciones.GaussSeided(parametro);
                MostrarResultado(resultado);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
Exemple #2
0
        public ResultadoEcuacionesGaussSeided GaussSeided(ParametroGaussSeided parametro)
        {
            double[] vector = new double[parametro.NumeroIncognitas];

            double[] Anterior = new double[parametro.NumeroIncognitas];
            double   errorRelativo;
            int      contador = 0;
            var      despejes = DespejarIncognitas(parametro.Matriz);

            do
            {
                for (int i = 0; i < vector.Length; i++)
                {
                    Anterior[i] = vector[i];
                }

                EvaluarSoluciones(vector, despejes);

                errorRelativo = CalculoErrorRelativo(vector, Anterior);

                contador += 1;
            } while (Math.Abs(errorRelativo) > parametro.Tolerancia && contador < parametro.Iteraciones);

            List <Incognita> Solucion = new List <Incognita>();

            for (int i = 0; i < vector.Length; i++)
            {
                Solucion.Add(new Incognita()
                {
                    Valor = vector[i], Nombre = "X" + (i + 1)
                });
            }

            return(new ResultadoEcuacionesGaussSeided()
            {
                ErrorRelativo = errorRelativo,
                Iteraciones = contador,
                Solucion = Solucion
            });
        }