Sie sind auf Seite 1von 6

Public partial class Form1 : Form

{
public Form1()
{
InitializeComponent();
}

private void dataGridView1_KeyPress(object sender, KeyPressEventArgs e)


{

if (dataGridView1.CurrentCell.ColumnIndex == 0)
{
if (!(char.IsNumber(e.KeyChar)) && (e.KeyChar != (char)Keys.Back) &&
e.KeyChar != Convert.ToChar('.') && e.KeyChar != Convert.ToChar('-'))
{
MessageBox.Show("Solo se permiten números", "Advertencia",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
e.Handled = true;
return;
}
}
if (dataGridView1.CurrentCell.ColumnIndex == 1)
{
if (!(char.IsNumber(e.KeyChar)) && (e.KeyChar != (char)Keys.Back) &&
e.KeyChar != Convert.ToChar('.') && e.KeyChar != Convert.ToChar('-'))
{
MessageBox.Show("Solo se permiten números", "Advertencia",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
e.Handled = true;
return;
}
}
}
private void dataGridView1_EditingControlShowing(object sender,
DataGridViewEditingControlShowingEventArgs e)
{
if (dataGridView1.CurrentCell.ColumnIndex == 1)
{
TextBox txt = e.Control as TextBox;
if (txt != null)
{
txt.KeyPress -= new
KeyPressEventHandler(dataGridView1_KeyPress);
txt.KeyPress += new
KeyPressEventHandler(dataGridView1_KeyPress);
}
}
if (dataGridView1.CurrentCell.ColumnIndex == 0)
{
TextBox txt = e.Control as TextBox;
if (txt != null)
{
txt.KeyPress -= new
KeyPressEventHandler(dataGridView1_KeyPress);
txt.KeyPress += new
KeyPressEventHandler(dataGridView1_KeyPress);
}
}
}

private void label1_Click(object sender, EventArgs e)


{

private void button2_Click(object sender, EventArgs e)


{
//
label3.Visible = true;
label4.Visible = true;
//prueba.Visible = true;
textBox1.Visible = true;
button3.Visible = true;
label5.Visible = true;
textBox3.Visible = true;
//declaro variables
float[] datos = new float[dataGridView1.Rows.Count - 1];
float[] funciones = new float[dataGridView1.Rows.Count - 1];

// Doy los valores que pertenecen

for (int c = 0; c <= (dataGridView1.Rows.Count-2); c++)


{
datos[c] = Convert.ToSingle(dataGridView1.Rows[c].Cells[0].Value);
funciones[c] =
Convert.ToSingle(dataGridView1.Rows[c].Cells[1].Value);
Console.WriteLine(datos[c] + " " + funciones[c]);
}

//programa
float[,] T;
int n = datos.Length;
int i = 0, m, j;
m = n - 1;

T = new float[n - 1, n - 1];


Console.WriteLine("primeras diferencias divididas");
while (i <= m - 1)
{
T[i, 0] = (funciones[i + 1] - funciones[i]) / (datos[i + 1] -
datos[i]);
Console.WriteLine("{0 }", T[i, 0]);
i = i + 1;
}
j = 1;
while (j <= m - 1)
{
i = j;
Console.WriteLine();
Console.WriteLine("Diferencias divididas de orden {0}", j + 1);
while (i <= m - 1)
{
T[i, j] = (T[i, j - 1] - T[i - 1, j - 1]) / (datos[i + 1] -
datos[i - j]);
Console.WriteLine("{0}", T[i, j]);
i = i + 1;
}
j = j + 1;
}
// fin programa
for (int a = 0; a <= n - 2; a++)
{
for(int b = 0; b <= n - 2; b++)
{
Console.WriteLine("Elemento ["+ b + ": "+ a + " ] = "+ T[b, a]);
}
}
//Sacar El polinomio
String polinomio = "" + funciones[0];
for (int coef = 0; coef <= n-2; coef++)
{

for (int contadorVariable = 0; contadorVariable <= coef-1;


contadorVariable++)
{
if(datos[contadorVariable] >= 0)
{
polinomio = polinomio + "( x " + (-datos[contadorVariable])
+ ")";
}
else
{
polinomio = polinomio + "( x +" + (-datos[contadorVariable])
+ ")";
}

}
polinomio = polinomio + " + " + T[coef, coef];
}
Console.WriteLine(polinomio);
textBox2.Text = polinomio;

//prueba

private void dataGridView1_CellContentClick(object sender,


DataGridViewCellEventArgs e)
{

private void textBox1_TextChanged(object sender, EventArgs e)


{

private void prueba_KeyPress(object sender, KeyPressEventArgs e)


{

private void label3_Click(object sender, EventArgs e)


{

private void textBox3_TextChanged(object sender, EventArgs e)


{

private void textBox1_TextChanged_1(object sender, EventArgs e)


{

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)


{
if (!(char.IsNumber(e.KeyChar)) && (e.KeyChar != (char)Keys.Back) &&
e.KeyChar != Convert.ToChar('.') && e.KeyChar != Convert.ToChar('-'))
{
MessageBox.Show("Solo se permiten números", "Advertencia",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
e.Handled = true;
return;
}
}

private void button3_Click(object sender, EventArgs e)


{
//declaro variables
float[] datos = new float[dataGridView1.Rows.Count - 1];
float[] funciones = new float[dataGridView1.Rows.Count - 1];
// Doy los valores que pertenecen

for (int c = 0; c <= (dataGridView1.Rows.Count - 2); c++)


{
datos[c] = Convert.ToSingle(dataGridView1.Rows[c].Cells[0].Value);
funciones[c] =
Convert.ToSingle(dataGridView1.Rows[c].Cells[1].Value);
Console.WriteLine(datos[c] + " " + funciones[c]);
}

//programa
float[,] T;
int n = datos.Length;
int i = 0, m, j;
m = n - 1;

T = new float[n - 1, n - 1];


Console.WriteLine("primeras diferencias divididas");
while (i <= m - 1)
{
T[i, 0] = (funciones[i + 1] - funciones[i]) / (datos[i + 1] -
datos[i]);
Console.WriteLine("{0 }", T[i, 0]);
i = i + 1;
}
j = 1;
while (j <= m - 1)
{
i = j;
Console.WriteLine();
Console.WriteLine("Diferencias divididas de orden {0}", j + 1);
while (i <= m - 1)
{
T[i, j] = (T[i, j - 1] - T[i - 1, j - 1]) / (datos[i + 1] -
datos[i - j]);
Console.WriteLine("{0}", T[i, j]);
i = i + 1;
}
j = j + 1;
}
// fin programa
for (int a = 0; a <= n - 2; a++)
{
for (int b = 0; b <= n - 2; b++)
{
Console.WriteLine("Elemento [" + b + ": " + a + " ] = " + T[b,
a]);
}
}
//Sacar El polinomio
String polinomio = "" + funciones[0];
for (int coef = 0; coef <= n - 2; coef++)
{

for (int contadorVariable = 0; contadorVariable <= coef - 1;


contadorVariable++)
{
if (datos[contadorVariable] >= 0)
{
polinomio = polinomio + "( x " + (-datos[contadorVariable])
+ ")";
}
else
{
polinomio = polinomio + "( x +" + (-datos[contadorVariable])
+ ")";
}

}
polinomio = polinomio + " + " + T[coef, coef];

}
Console.WriteLine(polinomio);
textBox2.Text = polinomio;

//prueba
float prueba = Convert.ToSingle(textBox1.Text);
float poli;
float poliprincipal = funciones[0];

for (int coef = 0; coef <= n - 2; coef++)


{
poli = T[coef, coef];
Console.WriteLine("poli eentrada:" + poli);
for (int contadorVariable = 0; contadorVariable <= coef ;
contadorVariable++)
{
poli = poli * (prueba + (-datos[contadorVariable]));
Console.WriteLine("poli es:" + poli);
}
poliprincipal = poliprincipal + poli;
Console.WriteLine("Resultado es asd:" + poliprincipal);

}
Console.WriteLine("Resultado es :" + poliprincipal);
textBox3.Text = Convert.ToString(poliprincipal);

Das könnte Ihnen auch gefallen