private void button1_Click(object sender, EventArgs e) { string texto = textBox1.Text; if (texto == "" || textBox1.Text == "") { texto = "invalido"; } double textoAInt = 0; bool result = double.TryParse(texto, out textoAInt); if (result) { Regresion nuevaRegresion = new Regresion(); PasarNumero owner = this.Owner as PasarNumero; nuevaRegresion.CalcularLagrange(owner.PasarDatos(), owner.PasarPuntos(), textoAInt); } else { MessageBox.Show("Ingrese los datos correctamente"); } }
private void button1_Click(object sender, EventArgs e) { double[,] Matriz = new double[Cantidad, 2]; for (int i = 0; i < Cantidad; i++) { for (int j = 0; j < 2; j++) { string texto = dataGridView1.Rows[i].Cells[j].Value.ToString(); if (texto == "") { texto = "Invalido"; } double textoADouble; bool result = double.TryParse(texto, out textoADouble); if (result) { Matriz[i, j] = textoADouble; } } } MatrizUsada = Matriz; Regresion nuevaRegresion = new Regresion(); if (Metodo == "Regresión Lineal por mínimos cuadrados") { ResultadoRegresion nuevoResultado = new ResultadoRegresion(); nuevoResultado = nuevaRegresion.CalcularRegresionLineal(Matriz, Cantidad); MessageBox.Show("El termino independiente es: " + nuevoResultado.Resultadoa0 + ", su coeficiente es: " + nuevoResultado.Resultadoa1 + ", y su coeficiente de correlacion es: " + nuevaRegresion.CoefienteCorrelacion(Matriz, Cantidad, nuevoResultado.Resultados)); } else { if (Metodo == "Regresión Polinomial por mínimos cuadrados") { var nuevoResultado = nuevaRegresion.CalcularRegrecionPolinomial(Matriz, Cantidad, 2); ResultadosRegresion = nuevoResultado.Resultados; CoeficienteCorrelacion = nuevaRegresion.CoefienteCorrelacion(Matriz, Cantidad, nuevoResultado.Resultados); ResultadosRegresion nuevoResultadoRegresion = new Regresión.ResultadosRegresion(); nuevoResultadoRegresion.Owner = this; nuevoResultadoRegresion.Show(); } else { var nuevoResultado = nuevaRegresion.CalcularLagrange(Matriz, Cantidad, numeroLagrange); MessageBox.Show("El valor correspondiente cuando x= " + numeroLagrange + " es: " + nuevoResultado + ", a traves del metodo de Lagrange"); } } }
private void button2_Click(object sender, EventArgs e) { Regresion regresion = new Regresion(); var listax = new List <double>(); var listay = new List <double>(); while (dataGridView2.RowCount > 1) { dataGridView2.Rows.Remove(dataGridView2.CurrentRow); } for (int c = 0; c < dataGridView1.RowCount - 1; c++) { double elem; var esValido = double.TryParse(dataGridView1.Rows[c].Cells[0].Value.ToString(), out elem); if (esValido) { listax.Add(elem); } } for (int c = 0; c < dataGridView1.RowCount - 1; c++) { double elem; var esValido = double.TryParse(dataGridView1.Rows[c].Cells[1].Value.ToString(), out elem); if (esValido) { listay.Add(elem); } } var a = regresion.RP_MinimoCuadrados(listax, listay, Convert.ToDouble(error.Text)); dataGridView2.ColumnCount = a.Count(); dataGridView2.AllowUserToAddRows = true; for (int i = 0; i < a.Count; i++) { dataGridView2.Columns[i].HeaderText = "a" + i; dataGridView2.Rows[0].Cells[i].Value = a[i]; } dataGridView2.Columns[a.Count - 1].HeaderText = "Coef. Correlacion"; dataGridView2.Rows[0].Cells[a.Count - 1].Value = a[a.Count() - 1]; }
private void button1_Click(object sender, EventArgs e) { Regresion regresion = new Regresion(); var listax = new List <double>(); var listay = new List <double>(); // dataGridView2 while (dataGridView2.RowCount > 1) { dataGridView2.Rows.Remove(dataGridView2.CurrentRow); } for (int c = 0; c < dataGridView1.RowCount - 1; c++) { double elem; var esValido = double.TryParse(dataGridView1.Rows[c].Cells[0].Value.ToString(), out elem); if (esValido) { listax.Add(elem); } } for (int c = 0; c < dataGridView1.RowCount - 1; c++) { double elem; var esValido = double.TryParse(dataGridView1.Rows[c].Cells[1].Value.ToString(), out elem); if (esValido) { listay.Add(elem); } } var a = regresion.RL_MinimosCuadrados(listax, listay); dataGridView2.ColumnCount = 2; dataGridView2.AllowUserToAddRows = true; dataGridView2.Columns[0].HeaderText = "Y"; dataGridView2.Columns[1].HeaderText = "X"; dataGridView2.Rows[0].Cells[0].Value = a[0]; dataGridView2.Rows[0].Cells[1].Value = a[1]; }
private void button3_Click(object sender, EventArgs e) { Regresion regresion = new Regresion(); var listax = new List <double>(); var listay = new List <double>(); while (dataGridView2.RowCount > 1) { dataGridView2.Rows.Remove(dataGridView2.CurrentRow); } for (int c = 0; c < dataGridView1.RowCount - 1; c++) { double elem; var esValido = double.TryParse(dataGridView1.Rows[c].Cells[0].Value.ToString(), out elem); if (esValido) { listax.Add(elem); } } for (int c = 0; c < dataGridView1.RowCount - 1; c++) { double elem; var esValido = double.TryParse(dataGridView1.Rows[c].Cells[1].Value.ToString(), out elem); if (esValido) { listay.Add(elem); } } var a = regresion.CalLagrange(listax, listay, Convert.ToDouble(imagen.Text)); dataGridView2.ColumnCount = 1; dataGridView2.AllowUserToAddRows = true; dataGridView2.Columns[0].HeaderText = "Y0"; dataGridView2.Rows[0].Cells[0].Value = a; }