Пример #1
0
        public void MostrarResultadosMC(Resultado_2 rdos)
        {
            string[] v = new string[6] {
                "a0 = ", "a1 = ", "a2 = ", "a3 = ", "a4 = ", "a5 = "
            };
            lbl_textoMC.Visible = true;
            lbl_textoMC.Text    = rdos.Mensaje;
            lbl_textoMC.Font    = new Font(lbl_textoMC.Font.Name, 10);
            panel3.Controls.Add(lbl_textoMC);
            int pointX = 25;
            int pointY = 55;

            if (rdos.SePudo != false)
            {
                for (int i = 0; i < rdos.Resultados.Length; i++)
                {
                    Label lbl = new Label();
                    lbl.Name      = "lbl_Resultado_" + i;
                    lbl.AutoSize  = false;
                    lbl.Size      = new System.Drawing.Size(85, 17);
                    lbl.Font      = new Font(lbl.Font.Name, 8);
                    lbl.Location  = new Point(pointX, pointY);
                    lbl.Text      = v[i] + Math.Round(rdos.Resultados[i], 5);
                    lbl.ForeColor = Color.Red;
                    panel3.Controls.Add(lbl);
                    panel3.Show();
                    pointX += 100;
                }
                lbl_coeficiente.Text    = "Coeficiente de correlación = " + rdos.valorcoeficiente;
                lbl_coeficiente.Visible = true;
            }
        }
Пример #2
0
 public void MostrarResultadosLagrange(Resultado_2 rdos, double x)
 {
     lbl_coeficiente.Text    = $"El valor de Lagrange obtenido, con un valor de {x} para X es:";
     lbl_coeficiente.Visible = true;
     //panel3.Controls.Add(label6);
     lbl_textoMC.AutoSize = false;
     lbl_textoMC.Size     = new System.Drawing.Size(120, 17);
     lbl_textoMC.Font     = new Font(label5.Font.Name, 10);
     //lbl_textoMC.Location = new Point(25,55);
     lbl_textoMC.Text      = $"P({x}): " + Math.Round(rdos.Resultados[0], 6);
     lbl_textoMC.ForeColor = Color.Red;
     lbl_textoMC.Visible   = true;
     panel3.Controls.Add(lbl_textoMC);
     panel3.Show();
 }
Пример #3
0
        }  //ACA SE RESUELVEN LAS ECUACIONES

        public void MostrarResultados(Resultado_2 rdos)
        {
            string[] v = new string[5] {
                "x = ", "y = ", "z = ", "t = ", "s = "
            };
            lbl_texto.Visible = true;
            lbl_texto.Text    = rdos.Mensaje;
            lbl_texto.Font    = new Font(lbl_texto.Font.Name, 10);
            panel2.Controls.Add(lbl_texto);
            int pointX = 25;
            int pointY = 225;

            for (int i = 0; i < rdos.Resultados.Length; i++)
            {
                Label lbl = new Label();
                lbl.Name      = "lbl_Resultado_" + i;
                lbl.AutoSize  = false;
                lbl.Size      = new System.Drawing.Size(120, 17);
                lbl.Font      = new Font(lbl.Font.Name, 10);
                lbl.Location  = new Point(pointX, pointY);
                lbl.Text      = v[i] + Math.Round(rdos.Resultados[i], 6);
                lbl.ForeColor = Color.Red;
                panel2.Controls.Add(lbl);
                panel2.Show();
                pointX += 120;
            }
            if (rdos.Iter != 0)
            {
                Label lbl = new Label();
                lbl.Name      = "lbl_Iteraciones";
                lbl.AutoSize  = false;
                lbl.Size      = new System.Drawing.Size(200, 17);
                lbl.Font      = new Font(lbl.Font.Name, 10);
                lbl.Location  = new Point(25, 250);
                lbl.Text      = "Iteraciones Realizadas: " + rdos.Iter;
                lbl.ForeColor = Color.Green;
                panel2.Controls.Add(lbl);
                panel2.Show();
            }
        }   //ACA MOSTRAMOS LOS RESULTADOS OBTENIDOS EN PANTALLA
Пример #4
0
        private void BtnCalcular_Click(object sender, EventArgs e)
        {
            for (int i = panel3.Controls.Count - 1; i >= 0; i--)
            {
                Label label = panel3.Controls[i] as Label;
                if ((label != null) && (label.Name != "lbl_textoMC"))
                {
                    panel3.Controls.RemoveAt(i);
                    label.Dispose();
                }
            }

            lbl_coeficiente.Visible = false;
            panel3.Update();
            panel3.Refresh();

            double[] vectorX = new double[15];
            double[] vectorY = new double[15];

            //Vector de valores x
            int contador = -1;

            foreach (DataGridViewRow row in dgvXeY.Rows)
            {
                contador += 1;
                string codigo = Convert.ToString(row.Cells["X"].Value);
                if (codigo != "")
                {
                    vectorX[contador] = double.Parse(codigo);
                }
            }
            int grad = contador - 1;

            //Vector de valores y
            contador = -1;
            foreach (DataGridViewRow row in dgvXeY.Rows)
            {
                contador += 1;
                string codigo = Convert.ToString(row.Cells["Y"].Value);
                if (codigo != "")
                {
                    vectorY[contador] = double.Parse(codigo);
                }
            }

            bool   bandera_lagrange = false;
            double valor_lagrange   = 0;

            if (cmb_Lagrange.Text == "Si")
            {
                bandera_lagrange = true;
                valor_lagrange   = double.Parse(txt_valor_lagrange.Text);
            }
            else
            {
                grad = int.Parse(txt_Grado.Text);
            }

            if (bandera_lagrange)
            {
                Resultado_2 res = Logica.Unidad3.Practico3.Lagrange(vectorX, vectorY, valor_lagrange, grad);
                MostrarResultadosLagrange(res, valor_lagrange);
            }
            else
            {
                Resultado_2 res = new Resultado_2(true, "Ajuste no aceptable para polinomios de grado mayor a " + (max_grado), 0, 50);
                while (grad < max_grado + 1 & (res.valorcoeficiente < double.Parse(txt_TP3_Tolerancia.Text)) & res.SePudo == true)
                {
                    res = Logica.Unidad3.Practico3.ResolucionMC(vectorX, vectorY, contador, grad + 1, max_grado);
                    if (res.valorcoeficiente >= double.Parse(txt_TP3_Tolerancia.Text))
                    {
                        res.Mensaje = "Los valores son:";
                    }
                    else
                    {
                        grad += 1;
                    }
                }
                if (grad == max_grado + 1)
                {
                    res.SePudo = false;
                }
                MostrarResultadosMC(res);
            }
        }
Пример #5
0
        private void Btn_Resolver_Click(object sender, EventArgs e)
        {
            bool bandera        = true;
            int  cantincognitas = int.Parse(textBox1.Text);

            for (int i = 1; i <= cantincognitas + 1; i++)
            {
                for (int x = 1; x <= cantincognitas; x++)
                {
                    string    nombre = "txt" + x + i;
                    Control[] m      = panel2.Controls.Find(nombre, true);
                    if (m[0].Text.Trim() == string.Empty)
                    {
                        //m[0].BackColor = Color.Red;
                        bandera = false;
                    }
                }
            }
            if (!bandera)
            {
                MessageBox.Show("campos en las ecuaciones vacios");
            }
            else
            {
                string[] aux;
                double[,] matriz = new double[cantincognitas, cantincognitas + 1];
                for (int i = 0; i < cantincognitas; i++)
                {
                    for (int j = 0; j < cantincognitas + 1; j++)
                    {
                        string nom = "txt";
                        int    x   = j + 1;
                        int    y   = i + 1;
                        nom = nom + y + x;
                        Control[] m = panel2.Controls.Find(nom, true);
                        if (m[0].Text.Contains("/"))
                        {
                            aux          = m[0].Text.Split(new char[] { '/' }, 2);
                            matriz[i, j] = double.Parse(aux[0]) / double.Parse(aux[1]);
                        }
                        else
                        {
                            matriz[i, j] = double.Parse(m[0].Text);
                        }
                    }
                }

                bool pivot = false;
                if (cmb_Pivoteo.Text == "Si")
                {
                    pivot = true;
                }

                Resultado_2 nuevo = new Resultado_2(true, "", cantincognitas, 0);

                if (cmb_Metodos.SelectedIndex == 0)
                {
                    nuevo = Logica.Unidad2.Practico2.Gauss_Jordan(matriz, cantincognitas, pivot);
                }
                else
                {
                    if ((txt_Iter_Practico2.Text.Trim() == string.Empty))
                    {
                        MessageBox.Show("Por favor, ingrese un maximo de iteraciones");
                        txt_Iter_Practico2.BackColor = Color.Red;
                        nuevo.SePudo = false;
                    }
                    else
                    {
                        if (txt_Tole_Practico2.Text.Trim() == string.Empty)
                        {
                            MessageBox.Show("Por favor, ingrese una tolerancia");
                            txt_Tole_Practico2.BackColor = Color.Red;
                            nuevo.SePudo = false;
                        }
                        else
                        {
                            nuevo = Logica.Unidad2.Practico2.Gauss_Seidel(matriz, cantincognitas,
                                                                          int.Parse(txt_Iter_Practico2.Text), double.Parse(txt_Tole_Practico2.Text), pivot);
                        }
                    }
                }

                if (nuevo.SePudo)
                {
                    MostrarResultados(nuevo);
                }
                else
                {
                    lbl_texto.Visible = true;
                    lbl_texto.Text    = nuevo.Mensaje;
                    lbl_texto.Font    = new Font(lbl_texto.Font.Name, 10);
                    panel2.Controls.Add(lbl_texto);
                }
            }
        }  //ACA SE RESUELVEN LAS ECUACIONES