Trabajo escrito del semestral de métodos Julio Fong, Eric Hidalgo, Julio Chen, Mary Navarro, Alex Núñez Universidad Tecnológica de Panamá, Faculta de Eléctrica
[email protected]
I. Introducción En este trabajo que se presentará a continuación se tomará como tema principal los métodos interpoladores, los cuales son aquellos que nos permiten estimar un polinomio que pase por los puntos ya previamente dados, los cuales son el polinomio interpolador de Lagrange y el polinomio de Newton. En el documento se mostrará paso a paso como el algoritmo creado con las especificaciones del docente, es capaz de buscar dicho polinomio (de un orden máximo de 4) por ambos métodos. También se mostrará los objetivos del proyecto, y una explicación más detallada de lo que respecta a los métodos interpoladores. Se utilizarán diversas herramientas tecnológicas (visuales) para proveer al estudiantado y al docente una mejor comprensión del tema.
Expandiendo el producto para verlo mejor:
Estos polinomios básicos de Lagrange se construyen con una propiedad:
El grado del polinomio de interpolación de Lagrange es igual o menor que n. Es el menor grado posible. El polinomio encontrado es único. Hay otras maneras de calcular este polinomio (con sus ventajas e inconvenientes).
II. Justificación A. Polinomio interpolador de Lagrange Empezamos con un conjunto de n + 1 puntos en el plano (que tengan diferentes coordenadas x): (x 0 , y 0 ), (x 1 , y 1 ), (x 2 , y 2 ),....,(x n , y n ). Nuestro objetivo es encontrar una función polinómica que pase por esos n + 1 puntos y que tengan el menor grado posible. Un polinomio que pase por varios puntos determinados se llama un polinomio de interpolación. Vamos a ver una forma de la solución que es el llamado polinomio de interpolación de Lagrange. (Lagrange publicó su fórmula en 1795 pero ya había sido publicada en 1779 por Waring y redescubierta por Euler en 1783). La fórmula general para el polinomio de interpolación de Lagrange es
Donde usamos polinomios básicos de Lagrange:
La forma de Lagrange es sencilla y se comprueba con facilidad que es un polinomio de interpolación y su grado. Pero para conocer los coeficientes del polinomio hay que simplificar los términos.
B .Polinomio de Newton Partiendo de n puntos (x, y), podemos obtener un polinomio de grado n − 1. El método que se utilizará es el de las diferencias divididas para obtener los coeficientes, el cual facilita la tarea de resolver un sistema de ecuaciones usando el cociente de sumas y restas. Sólo existe un único polinomio que interpola una serie de puntos. Existen ciertas ventajas en el uso de este polinomio respecto al polinomio interpolador de Lagrange. Por ejemplo, si fuese necesario añadir algún nuevo punto o nodo a la función, tan sólo habría que calcular este último punto, dada la relación de recurrencia existente y demostrada anteriormente. Dada una colección de n puntos de x y sus imágenes f(x), se pueden calcular los coeficientes del polinomio interpolante utilizando las siguientes expresiones:
Trabajo escrito del semestral de métodos Julio Fong, Eric Hidalgo, Julio Chen, Mary Navarro, Alex Núñez Universidad Tecnológica de Panamá, Faculta de Eléctrica
[email protected] B) Viñeta de presentación
Finalmente, a partir de los valores obtenidos, se pueden obtener dos formas de representar el polinomio: Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click End End Sub Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click
III. Objetivos A) Obtener el polinomio interpolador utilizando los puntos previamente dados por medio de los métodos de Newton y Lagrange. B) Utilizar el programa para para obtener dicho polinomio. C) Lograr una buena compresión del uso de las diversas herramientas informáticas que nos permitirán desarrollar de manera adecuada este proyecto.
IV. Código de programación A) El programa consta con 7 pestañas con diseños diferentes, cada pestaña tiene un código diferente que será anexa a continuación de cada una.
End Sub Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click Form2.Visible = True End Sub End Class
Trabajo escrito del semestral de métodos Julio Fong, Eric Hidalgo, Julio Chen, Mary Navarro, Alex Núñez Universidad Tecnológica de Panamá, Faculta de Eléctrica
[email protected] C)
Menú Principal
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click Me.Close() End Sub End Class D) Interpolación para 2 pares ordenados
Public Class Form2 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click End End Sub Private Sub GroupBox1_Enter(sender As Object, e As EventArgs) Handles GroupBox1.Enter End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click If (Dos.Checked = True) Then Form3.Visible = True ElseIf (Tres.Checked = True) Then Form4.Visible = True ElseIf (Cuatro.Checked = True) Then Form5.Visible = True ElseIf (Cinco.Checked = True) Then Form6.Visible = True ElseIf (Funcion.Checked = True) Then Form7.Visible = True Else MsgBox("Seleccione una opción", MsgBoxStyle.Exclamation) End If End Sub
Public Class Form3 Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load End Sub Private Sub Proceder() If txty0.TextLength > 0 And txty1.TextLength > 0 And txtx0.TextLength > 0 And txtx1.TextLength > 0 Then btngen.Enabled = True btngenNewton.Enabled = True Else btngen.Enabled = False btngenNewton.Enabled = False End If End Sub Private Sub Evaluar() If btngen.Enabled = True And txtval.TextLength > 0 Then btnEvaluar.Enabled = True btnEvaluarNewton.Enabled = True Else btnEvaluar.Enabled = False btnEvaluarNewton.Enabled = False End If End Sub Private Sub Label3_Click(sender As Object, e As EventArgs) Handles Label3.Click Proceder() End Sub
Trabajo escrito del semestral de métodos Julio Fong, Eric Hidalgo, Julio Chen, Mary Navarro, Alex Núñez Universidad Tecnológica de Panamá, Faculta de Eléctrica
[email protected] Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click End End Sub Private Sub txty0_TextChanged(sender As Object, e As EventArgs) Handles txty0.TextChanged Proceder() End Sub Private Sub txty1_TextChanged(sender As Object, e As EventArgs) Handles txty1.TextChanged Proceder() End Sub Private Sub txtx0_TextChanged(sender As Object, e As EventArgs) Handles txtx0.TextChanged Proceder() End Sub Private Sub txtx1_TextChanged(sender As Object, e As EventArgs) Handles txtx1.TextChanged Proceder() End Sub 'Para el boton del polinomio Lagrange Private Sub btngen_Click(sender As Object, e As EventArgs) Handles btngen.Click Dim y0, y1, x0, x1, Pol1, Pol0 As Double y0 = txty0.Text y1 = txty1.Text x0 = txtx0.Text x1 = txtx1.Text 'Las variables Pol1 y Pol0 son los coeficientes de cada termino del polinomio Pol1 = (y0 / (x0 - x1)) + (y1 / (x1 - x0)) Pol0 = (y0 * x1 / (x1 - x0)) + (y1 * x0 / (x0 - x1)) MsgBox(Pol1.ToString + "X+(" + Pol0.ToString + ")") End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click Me.Close() End Sub Private Sub txtval_TextChanged(sender As Object, e As EventArgs) Handles txtval.TextChanged Evaluar() End Sub 'Para el boton de evaluacion Lagrange Private Sub btnEvaluar_Click(sender As Object, e As EventArgs) Handles btnEvaluar.Click Dim y0, y1, x0, x1, Pol1, Pol0, val, eval As Double y0 = txty0.Text y1 = txty1.Text x0 = txtx0.Text x1 = txtx1.Text val = txtval.Text 'Las variables Pol1 y Pol0 son los coeficientes de cada termino del polinomio Pol1 = (y0 / (x0 - x1)) + (y1 / (x1 - x0)) Pol0 = (y0 * x1 / (x1 - x0)) + (y1 * x0 / (x0 - x1)) eval = (Pol1 * val) + Pol0 MsgBox("El polinomio evaluado en " + val.ToString + " toma el valor de:" + Chr(13) + eval.ToString) End Sub 'Para el boton del polinomio Newton Private Sub btngenNewton_Click(sender As Object, e As EventArgs) Handles btngenNewton.Click Dim y0, y1, x0, x1, A1, Pol0, Pol1 As Double y0 = txty0.Text y1 = txty1.Text x0 = txtx0.Text x1 = txtx1.Text A1 = (y1 - y0) / (x1 - x0) Pol1 = A1 Pol0 = y0 - A1 * x0 MsgBox(Pol1.ToString + "X+(" + Pol0.ToString + ")") End Sub
Trabajo escrito del semestral de métodos Julio Fong, Eric Hidalgo, Julio Chen, Mary Navarro, Alex Núñez Universidad Tecnológica de Panamá, Faculta de Eléctrica
[email protected] 'Para el boton de la evaluacion Newton Private Sub btnEvaluarNewton_Click(sender As Object, e As EventArgs) Handles btnEvaluarNewton.Click Dim y0, y1, x0, x1, A1, Pol0, Pol1, val, eval As Double y0 = txty0.Text y1 = txty1.Text x0 = txtx0.Text x1 = txtx1.Text A1 = (y1 - y0) / (x1 - x0) Pol1 = A1 Pol0 = y0 - A1 * x0 val = txtval.Text eval = Pol1 * val + Pol0 MsgBox("El polinomio evaluado en " + val.ToString + " toma el valor de:" + Chr(13) + eval.ToString) End Sub End Class E)
Interpolación para 3 pares ordenados
Else btngen.Enabled = False btngenNewton.Enabled = False End If End Sub Private Sub Evaluar() If btngen.Enabled = True And txtval.TextLength > 0 Then btnEvaluar.Enabled = True btnEvaluarNewton.Enabled = True Else btnEvaluar.Enabled = False btnEvaluarNewton.Enabled = False End If End Sub Private Sub Label3_Click(sender As Object, e As EventArgs) Handles Label3.Click End Sub Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click End End Sub Private Sub txty0_TextChanged(sender As Object, e As EventArgs) Handles txty0.TextChanged Proceder() End Sub Private Sub txty1_TextChanged(sender As Object, e As EventArgs) Handles txty1.TextChanged Proceder() End Sub
Public Class Form4 Private Sub Form4_Load(sender As Object, e As EventArgs) Handles MyBase.Load End Sub Private Sub Proceder() If txty0.TextLength > 0 And txty1.TextLength > 0 And txty2.TextLength > 0 And txtx0.TextLength > 0 And txtx1.TextLength > 0 And txtx2.TextLength > 0 Then btngen.Enabled = True btngenNewton.Enabled = True
Private Sub txtx0_TextChanged(sender As Object, e As EventArgs) Handles txtx0.TextChanged Proceder() End Sub Private Sub txtx1_TextChanged(sender As Object, e As EventArgs) Handles txtx1.TextChanged Proceder() End Sub
Trabajo escrito del semestral de métodos Julio Fong, Eric Hidalgo, Julio Chen, Mary Navarro, Alex Núñez Universidad Tecnológica de Panamá, Faculta de Eléctrica
[email protected] Private Sub btngen_Click(sender As Object, e As EventArgs) Handles btngen.Click Dim y0, y1, y2, x0, x1, x2, Div0, Div1, Div2, Pol2, Pol1, Pol0 As Double y0 = txty0.Text y1 = txty1.Text y2 = txty2.Text x0 = txtx0.Text x1 = txtx1.Text x2 = txtx2.Text Div0 = ((x0 - x1) * (x0 - x2)) Div1 = ((x1 - x0) * (x1 - x2)) Div2 = ((x2 - x0) * (x2 - x1)) Pol0 = ((y0 * x1 * x2) / Div0) + ((y1 * x0 * x2) / Div1) + ((y2 * x0 * x1) / Div2) Pol1 = ((y0 * (x1 + x2)) / Div0) + ((y1 * (x0 + x2)) / Div1) + ((y2 * (x0 + x1)) / Div2) Pol2 = ((y0) / Div0) + ((y1) / Div1) + ((y2) / Div2) MsgBox(Pol2.ToString + "(X^(2))+(" + Pol1.ToString + ")X+(" + Pol0.ToString + ")") End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click Me.Close() End Sub Private Sub txtval_TextChanged(sender As Object, e As EventArgs) Handles txtval.TextChanged Evaluar() End Sub Private Sub btnEvaluar_Click(sender As Object, e As EventArgs) Handles btnEvaluar.Click Dim y0, y1, y2, x0, x1, x2, val, eval, Div0, Div1, Div2, Pol2, Pol1, Pol0 As Double y0 = txty0.Text y1 = txty1.Text y2 = txty2.Text x0 = txtx0.Text x1 = txtx1.Text x2 = txtx2.Text val = txtval.Text
Div0 = ((x0 - x1) * (x0 - x2)) Div1 = ((x1 - x0) * (x1 - x2)) Div2 = ((x2 - x0) * (x2 - x1)) Pol0 = ((y0 * x1 * x2) / Div0) + ((y1 * x0 * x2) / Div1) + ((y2 * x0 * x1) / Div2) Pol1 = -(((y0 * (x1 + x2)) / Div0) + ((y1 * (x0 + x2)) / Div1) + ((y2 * (x0 + x1)) / Div2)) Pol2 = ((y0 / Div0) + (y1 / Div1) + (y2 / Div2)) eval = (Pol2 * (val) ^ 2) + Pol1 * val + Pol0 MsgBox("El polinomio evaluado en " + val.ToString + " toma el valor de:" + Chr(13) + eval.ToString) End Sub Private Sub txty2_TextChanged(sender As Object, e As EventArgs) Handles txty2.TextChanged Proceder() End Sub Private Sub txtx2_TextChanged(sender As Object, e As EventArgs) Handles txtx2.TextChanged Proceder() End Sub Private Sub btngenNewton_Click(sender As Object, e As EventArgs) Handles btngenNewton.Click Dim y0, y1, y2, x0, x1, x2, A1, A2, B2, Pol0, Pol1, Pol2 As Double y0 = txty0.Text y1 = txty1.Text y2 = txty2.Text x0 = txtx0.Text x1 = txtx1.Text x2 = txtx2.Text A1 = (y1 - y0) / (x1 - x0) A2 = (y2 - y1) / (x2 - x1) B2 = (A2 - A1) / (x2 - x0) Pol2 = B2 Pol1 = A1 - B2 * (x0 + x1) Pol0 = y0 - A1 * x0 + B2 * x0 * x1 MsgBox(Pol2.ToString + "(X^(2))+(" + Pol1.ToString + ")X+(" + Pol0.ToString + ")") End Sub
Trabajo escrito del semestral de métodos Julio Fong, Eric Hidalgo, Julio Chen, Mary Navarro, Alex Núñez Universidad Tecnológica de Panamá, Faculta de Eléctrica
[email protected] Private Sub btnEvaluarNewton_Click(sender As Object, e As EventArgs) Handles btnEvaluarNewton.Click Dim y0, y1, y2, x0, x1, x2, A1, A2, B2, Pol0, Pol1, Pol2, val, eval As Double y0 = txty0.Text y1 = txty1.Text y2 = txty2.Text x0 = txtx0.Text x1 = txtx1.Text x2 = txtx2.Text A1 = (y1 - y0) / (x1 - x0) A2 = (y2 - y1) / (x2 - x1) B2 = (A2 - A1) / (x2 - x0) Pol2 = B2 Pol1 = A1 - B2 * (x0 + x1) Pol0 = y0 - A1 * x0 + B2 * x0 * x1 val = txtval.Text eval = (Pol2 * (val) ^ 2) + Pol1 * val + Pol0 MsgBox("El polinomio evaluado en " + val.ToString + " toma el valor de:" + Chr(13) + eval.ToString) End Sub End Class
F)
Interpolación para 4 pares ordenados
If txty0.TextLength > 0 And txty1.TextLength > 0 And txty2.TextLength > 0 And txty3.TextLength > 0 And txtx0.TextLength > 0 And txtx1.TextLength > 0 And txtx2.TextLength > 0 And txtx3.TextLength > 0 Then btngen.Enabled = True btngenNewton.Enabled = True Else btngen.Enabled = False btngenNewton.Enabled = False End If End Sub Private Sub Evaluar() If btngen.Enabled = True And txtval.TextLength > 0 Then btnEvaluar.Enabled = True btnEvaluarNewton.Enabled = True Else btnEvaluar.Enabled = False btnEvaluarNewton.Enabled = False End If End Sub Private Sub Label3_Click(sender As Object, e As EventArgs) Handles Label3.Click End Sub Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click End End Sub Private Sub txty0_TextChanged(sender As Object, e As EventArgs) Handles txty0.TextChanged Proceder() End Sub
Public Class Form5 Private Sub Form5_Load(sender As Object, e As EventArgs) Handles MyBase.Load End Sub Private Sub Proceder()
Private Sub txty1_TextChanged(sender As Object, e As EventArgs) Handles txty1.TextChanged Proceder() End Sub Private Sub txtx0_TextChanged(sender As Object, e As EventArgs) Handles txtx0.TextChanged Proceder() End Sub
Trabajo escrito del semestral de métodos Julio Fong, Eric Hidalgo, Julio Chen, Mary Navarro, Alex Núñez Universidad Tecnológica de Panamá, Faculta de Eléctrica
[email protected] Private Sub txtx1_TextChanged(sender As Object, e As EventArgs) Handles txtx1.TextChanged Proceder() End Sub Private Sub btngen_Click(sender As Object, e As EventArgs) Handles btngen.Click Dim y0, y1, y2, y3, x0, x1, x2, x3, Div0, Div1, Div2, Div3, Pol3, Pol2, Pol1, Pol0 As Double y0 = txty0.Text y1 = txty1.Text y2 = txty2.Text y3 = txty3.Text x0 = txtx0.Text x1 = txtx1.Text x2 = txtx2.Text x3 = txtx3.Text Div0 = ((x0 - x1) * (x0 - x2) * (x0 - x3)) Div1 = ((x1 - x0) * (x1 - x2) * (x1 - x3)) Div2 = ((x2 - x0) * (x2 - x1) * (x2 - x3)) Div3 = ((x3 - x0) * (x3 - x1) * (x3 - x2)) Pol0 = ((y0 * x1 * x2 * x3) / Div0) + ((y1 * x0 * x2 * x3) / Div1) + ((y2 * x0 * x1 * x3) / Div2) + ((y3 * x0 * x1 * x2) / Div3) Pol1 = ((y0 * (x1 * x2 + x1 * x3 + x2 * x3) / Div0) + (y1 * (x0 * x2 + x0 * x3 + x2 * x3) / Div1) + (y2 * (x0 * x1 + x0 * x3 + x1 * x3) / Div2) + (y3 * (x0 * x1 + x0 * x2 + x1 * x2) / Div3)) Pol2 = -(((y0 * (x1 + x2 + x3)) / Div0) + ((y1 * (x0 + x2 + x3)) / Div1) + ((y2 * (x0 + x1 + x3)) / Div2) + ((y3 * (x0 + x1 + x2)) / Div3)) Pol3 = ((y0) / Div0) + ((y1) / Div1) + ((y2) / Div2) + ((y3) / Div3) MsgBox(Pol3.ToString + "(X^(3))+(" + Pol2.ToString + ")(X^(2))+(" + Pol1.ToString + ")X+(" + Pol0.ToString + ")") End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.Close() End Sub Private Sub txtval_TextChanged(sender As Object, e As EventArgs) Handles txtval.TextChanged Evaluar() End Sub Private Sub btnEvaluar_Click(sender As Object, e As EventArgs) Handles btnEvaluar.Click Dim y0, y1, y2, y3, x0, x1, x2, x3, val, eval, Div0, Div1, Div2, Div3, Pol3, Pol2, Pol1, Pol0 As Double Dim i As Integer y0 = txty0.Text y1 = txty1.Text y2 = txty2.Text y3 = txty3.Text x0 = txtx0.Text x1 = txtx1.Text x2 = txtx2.Text x3 = txtx3.Text val = txtval.Text Div0 = ((x0 - x1) * (x0 - x2) * (x0 - x3)) Div1 = ((x1 - x0) * (x1 - x2) * (x1 - x3)) Div2 = ((x2 - x0) * (x2 - x1) * (x2 - x3)) Div3 = ((x3 - x0) * (x3 - x1) * (x3 - x2)) Pol0 = ((y0 * x1 * x2 * x3) / Div0) + ((y1 * x0 * x2 * x3) / Div1) + ((y2 * x0 * x1 * x3) / Div2) + ((y3 * x0 * x1 * x2) / Div3) Pol1 = ((y0 * (x1 * x2 + x1 * x3 + x2 * x3) / Div0) + (y1 * (x0 * x2 + x0 * x3 + x2 * x3) / Div1) + (y2 * (x0 * x1 + x0 * x3 + x1 * x3) / Div2) + (y3 * (x0 * x1 + x0 * x2 + x1 * x2) / Div3)) Pol2 = -(((y0 * (x1 + x2 + x3)) / Div0) + ((y1 * (x0 + x2 + x3)) / Div1) + ((y2 * (x0 + x1 + x3)) / Div2) + ((y3 * (x0 + x1 + x2)) / Div3)) Pol3 = ((y0) / Div0) + ((y1) / Div1) + ((y2) / Div2) + ((y3) / Div3) eval = (Pol3 * (val) ^ 3) + (Pol2 * (val) ^ 2) + Pol1 * val + Pol0
Trabajo escrito del semestral de métodos Julio Fong, Eric Hidalgo, Julio Chen, Mary Navarro, Alex Núñez Universidad Tecnológica de Panamá, Faculta de Eléctrica
[email protected] MsgBox("El polinomio evaluado en " + val.ToString + " toma el valor de:" + Chr(13) + eval.ToString) End Sub Private Sub txty2_TextChanged(sender As Object, e As EventArgs) Handles txty2.TextChanged Proceder() End Sub Private Sub txtx2_TextChanged(sender As Object, e As EventArgs) Handles txtx2.TextChanged Proceder() End Sub Private Sub txty3_TextChanged(sender As Object, e As EventArgs) Handles txty3.TextChanged Proceder() End Sub Private Sub txtx3_TextChanged(sender As Object, e As EventArgs) Handles txtx3.TextChanged Proceder() End Sub Private Sub btngenNewton_Click(sender As Object, e As EventArgs) Handles btngenNewton.Click Dim y0, y1, y2, y3, x0, x1, x2, x3, A1, A2, A3, B2, B3, C3, Pol0, Pol1, Pol2, Pol3 As Double y0 = txty0.Text y1 = txty1.Text y2 = txty2.Text y3 = txty3.Text x0 = txtx0.Text x1 = txtx1.Text x2 = txtx2.Text x3 = txtx3.Text A1 = (y1 - y0) / (x1 - x0) A2 = (y2 - y1) / (x2 - x1) A3 = (y3 - y2) / (x3 - x2) B2 = (A2 - A1) / (x2 - x0) B3 = (A3 - A2) / (x3 - x1) C3 = (B3 - B2) / (x3 - x0) Pol3 = C3 Pol2 = B2 - C3 * (x0 + x1 + x2) Pol1 = A1 - B2 * (x0 + x1) + C3 * (x0 * x1 + x0 * x2 + x1 * x2)
Pol0 = y0 - A1 * x0 + B2 * x0 * x1 - C3 * x0 * x1 * x2 MsgBox(Pol3.ToString + "(X^(3))+(" + Pol2.ToString + ")(X^(2))+(" + Pol1.ToString + ")X+(" + Pol0.ToString + ")") End Sub Private Sub btnEvaluarNewton_Click(sender As Object, e As EventArgs) Handles btnEvaluarNewton.Click Dim y0, y1, y2, y3, x0, x1, x2, x3, A1, A2, A3, B2, B3, C3, Pol0, Pol1, Pol2, Pol3, val, eval As Double y0 = txty0.Text y1 = txty1.Text y2 = txty2.Text y3 = txty3.Text x0 = txtx0.Text x1 = txtx1.Text x2 = txtx2.Text x3 = txtx3.Text A1 = (y1 - y0) / (x1 - x0) A2 = (y2 - y1) / (x2 - x1) A3 = (y3 - y2) / (x3 - x2) B2 = (A2 - A1) / (x2 - x0) B3 = (A3 - A2) / (x3 - x1) C3 = (B3 - B2) / (x3 - x0) Pol3 = C3 Pol2 = B2 - C3 * (x0 + x1 + x2) Pol1 = A1 - B2 * (x0 + x1) + C3 * (x0 * x1 + x0 * x2 + x1 * x2) Pol0 = y0 - A1 * x0 + B2 * x0 * x1 - C3 * x0 * x1 * x2 val = txtval.Text eval = (Pol3 * (val) ^ 3) + (Pol2 * (val) ^ 2) + Pol1 * val + Pol0 MsgBox("El polinomio evaluado en " + val.ToString + " toma el valor de:" + Chr(13) + eval.ToString) End Sub End Class
Trabajo escrito del semestral de métodos Julio Fong, Eric Hidalgo, Julio Chen, Mary Navarro, Alex Núñez Universidad Tecnológica de Panamá, Faculta de Eléctrica
[email protected] G) Interpolación para 5 pares ordenados
End If End Sub Private Sub Label3_Click(sender As Object, e As EventArgs) Handles Label3.Click End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click End Public Class Form6
End Sub
Private Sub Form6_Load(sender As Object, e As EventArgs) Handles MyBase.Load Private Sub txty0_TextChanged(sender As Object, e As EventArgs) Handles txty0.TextChanged End Sub Private Sub Proceder() If txty0.TextLength > 0 And txty1.TextLength > 0 And txty2.TextLength > 0 And txty3.TextLength > 0 And txty4.TextLength > 0 And txtx0.TextLength > 0 And txtx1.TextLength > 0 And txtx2.TextLength > 0 And txtx3.TextLength > 0 And txtx4.TextLength > 0 Then
Proceder() End Sub
Private Sub txty1_TextChanged(sender As Object, e As EventArgs) Handles txty1.TextChanged Proceder() End Sub
btngen.Enabled = True btngenNewton.Enabled = True Else btngen.Enabled = False btngenNewton.Enabled = False End If
Private Sub txtx0_TextChanged(sender As Object, e As EventArgs) Handles txtx0.TextChanged Proceder() End Sub
End Sub Private Sub Evaluar() If btngen.Enabled = True And txtval.TextLength > 0 Then btnEvaluar.Enabled = True btnEvaluarNewton.Enabled = True
Private Sub txtx1_TextChanged(sender As Object, e As EventArgs) Handles txtx1.TextChanged Proceder() End Sub
Else btnEvaluar.Enabled = False btnEvaluarNewton.Enabled = False
Private Sub btngen_Click(sender As Object, e As EventArgs) Handles btngen.Click
Trabajo escrito del semestral de métodos Julio Fong, Eric Hidalgo, Julio Chen, Mary Navarro, Alex Núñez Universidad Tecnológica de Panamá, Faculta de Eléctrica
[email protected] Dim y0, y1, y2, y3, y4, x0, x1, x2, x3, x4, Div0, Div1, Div2, Div3, Div4, Pol4, Pol3, Pol2, Pol1, Pol0 As Double y0 = txty0.Text y1 = txty1.Text y2 = txty2.Text y3 = txty3.Text y4 = txty4.Text x0 = txtx0.Text x1 = txtx1.Text
x2) + (x1 * x4) + (x2 * x4))) / Div3) + ((y4 * ((x0 * x1) + (x0 * x2) + (x0 * x3) + (x1 * x2) + (x1 * x3) + (x2 * x3))) / Div4)) 'Correct o's Pol3 = -(((y0 * (x1 + x2 + x3 + x4)) / Div0) + ((y1 * (x0 + x2 + x3 + x4)) / Div1) + ((y2 * (x0 + x1 + x3 + x4)) / Div2) + ((y3 * (x0 + x1 + x2 + x4)) / Div3) + ((y4 * (x0 + x1 + x2 + x3)) / Div4)) Pol4 = ((y0) / Div0) + ((y1) / Div1) + ((y2) / Div2) + ((y3) / Div3) + ((y4) / Div4) MsgBox(Pol4.ToString + "(X^(4))+(" + Pol3.ToString + "(X^(3))+(" + Pol2.ToString + ")(X^(2))+(" + Pol1.ToString + ")X+(" + Pol0.ToString + ")")
x2 = txtx2.Text End Sub x3 = txtx3.Text x4 = txtx4.Text Div0 = ((x0 - x1) * (x0 - x2) * (x0 - x3) * (x0 - x4)) Div1 = ((x1 - x0) * (x1 - x2) * (x1 - x3) * (x1 - x4)) Div2 = ((x2 - x0) * (x2 - x1) * (x2 - x3) * (x2 - x4))
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click Me.Close() End Sub
Div3 = ((x3 - x0) * (x3 - x1) * (x3 - x2) * (x3 - x4)) Div4 = ((x4 - x0) * (x4 - x1) * (x4 - x2) * (x4 - x3)) 'Correct o's Pol0 = ((y0 * x1 * x2 * x3 * x4) / Div0) + ((y1 * x0 * x2 * x3 * x4) / Div1) + ((y2 * x0 * x1 * x3 * x4) / Div2) + ((y3 * x0 * x1 * x2 * x4) / Div3) + ((y4 * x0 * x1 * x2 * x3) / Div4)
Private Sub txtval_TextChanged(sender As Object, e As EventArgs) Handles txtval.TextChanged Evaluar() End Sub
'Correct o's Pol1 = -(((y0 * ((x1 * x2 * x3) + (x1 * x2 * x4) + (x1 * x3 * x4) + (x2 * x3 * x4))) / Div0) + ((y1 * ((x0 * x2 * x3) + (x0 * x2 * x4) + (x0 * x3 * x4) + (x2 * x3 * x4))) / Div1) + (y2 * ((x0 * x1 * x3) + (x0 * x1 * x4) + (x0 * x3 * x4) + (x1 * x3 * x4)) / Div2) + (y3 * ((x0 * x1 * x2) + (x0 * x1 * x4) + (x0 * x2 * x4) + (x1 * x2 * x4)) / Div3) + (y4 * ((x0 * x1 * x2) + (x0 * x1 * x3) + (x0 * x2 * x3) + (x1 * x2 * x3)) / Div4)) 'Correct o's Pol2 = (((y0 * ((x1 * x2) + (x1 * x3) + (x1 * x4) + (x2 * x3) + (x2 * x4) + (x3 * x4))) / Div0) + ((y1 * ((x0 * x2) + (x0 * x3) + (x0 * x4) + (x2 * x3) + (x2 * x4) + (x3 * x4))) / Div1) + ((y2 * ((x0 * x1) + (x0 * x3) + (x0 * x4) + (x1 * x3) + (x1 * x4) + (x3 * x4))) / Div2) + ((y3 * ((x0 * x1) + (x0 * x2) + (x0 * x4) + (x1 *
Private Sub btnEvaluar_Click(sender As Object, e As EventArgs) Handles btnEvaluar.Click Dim y0, y1, y2, y3, y4, x0, x1, x2, x3, x4, val, eval, Div0, Div1, Div2, Div3, Div4, Pol4, Pol3, Pol2, Pol1, Pol0 As Double y0 = txty0.Text y1 = txty1.Text y2 = txty2.Text y3 = txty3.Text y4 = txty4.Text x0 = txtx0.Text
Trabajo escrito del semestral de métodos Julio Fong, Eric Hidalgo, Julio Chen, Mary Navarro, Alex Núñez Universidad Tecnológica de Panamá, Faculta de Eléctrica
[email protected] x1 = txtx1.Text x2 = txtx2.Text x3 = txtx3.Text x4 = txtx4.Text val = txtval.Text Div0 = ((x0 - x1) * (x0 - x2) * (x0 - x3) * (x0 - x4)) Div1 = ((x1 - x0) * (x1 - x2) * (x1 - x3) * (x1 - x4)) Div2 = ((x2 - x0) * (x2 - x1) * (x2 - x3) * (x2 - x4)) Div3 = ((x3 - x0) * (x3 - x1) * (x3 - x2) * (x3 - x4)) Div4 = ((x4 - x0) * (x4 - x1) * (x4 - x2) * (x4 - x3)) Pol0 = ((y0 * x1 * x2 * x3 * x4) / Div0) + ((y1 * x0 * x2 * x3 * x4) / Div1) + ((y2 * x0 * x1 * x3 * x4) / Div2) + ((y3 * x0 * x1 * x2 * x4) / Div3) + ((y4 * x0 * x1 * x2 * x3) / Div4) Pol1 = -(((y0 * ((x1 * x2 * x3) + (x1 * x2 * x4) + (x1 * x3 * x4) + (x2 * x3 * x4))) / Div0) + ((y1 * ((x0 * x2 * x3) + (x0 * x2 * x4) + (x0 * x3 * x4) + (x2 * x3 * x4))) / Div1) + (y2 * ((x0 * x1 * x3) + (x0 * x1 * x4) + (x0 * x3 * x4) + (x1 * x3 * x4)) / Div2) + (y3 * ((x0 * x1 * x2) + (x0 * x1 * x4) + (x0 * x2 * x4) + (x1 * x2 * x4)) / Div3) + (y4 * ((x0 * x1 * x2) + (x0 * x1 * x3) + (x0 * x2 * x3) + (x1 * x2 * x3)) / Div4)) Pol2 = (((y0 * ((x1 * x2) + (x1 * x3) + (x1 * x4) + (x2 * x3) + (x2 * x4) + (x3 * x4))) / Div0) + ((y1 * ((x0 * x2) + (x0 * x3) + (x0 * x4) + (x2 * x3) + (x2 * x4) + (x3 * x4))) / Div1) + ((y2 * ((x0 * x1) + (x0 * x3) + (x0 * x4) + (x1 * x3) + (x1 * x4) + (x3 * x4))) / Div2) + ((y3 * ((x0 * x1) + (x0 * x2) + (x0 * x4) + (x1 * x2) + (x1 * x4) + (x2 * x4))) / Div3) + ((y4 * ((x0 * x1) + (x0 * x2) + (x0 * x3) + (x1 * x2) + (x1 * x3) + (x2 * x3))) / Div4))
Private Sub txty2_TextChanged(sender As Object, e As EventArgs) Handles txty2.TextChanged Proceder() End Sub Private Sub txtx2_TextChanged(sender As Object, e As EventArgs) Handles txtx2.TextChanged Proceder() End Sub Private Sub txty3_TextChanged(sender As Object, e As EventArgs) Handles txty3.TextChanged Proceder() End Sub Private Sub txtx3_TextChanged(sender As Object, e As EventArgs) Handles txtx3.TextChanged Proceder() End Sub Private Sub txty4_TextChanged(sender As Object, e As EventArgs) Handles txty4.TextChanged Proceder() End Sub Private Sub txtx4_TextChanged(sender As Object, e As EventArgs) Handles txtx4.TextChanged Proceder()
Pol3 = -(((y0 * (x1 + x2 + x3 + x4)) / Div0) + ((y1 * (x0 + x2 + x3 + x4)) / Div1) + ((y2 * (x0 + x1 + x3 + x4)) / Div2) + ((y3 * (x0 + x1 + x2 + x4)) / Div3) + ((y4 * (x0 + x1 + x2 + x3)) / Div4))
Private Sub btngenNewton_Click(sender As Object, e As EventArgs) Handles btngenNewton.Click
Pol4 = ((y0) / Div0) + ((y1) / Div1) + ((y2) / Div2) + ((y3) / Div3) + ((y4) / Div4)
Dim y0, y1, y2, y3, y4, x0, x1, x2, x3, x4, A1, A2, A3, A4, B2, B3, B4, C3, C4, D4, Pol0, Pol1, Pol2, Pol3, Pol4 As Double
eval = (Pol4 * (val) ^ 4) + (Pol3 * (val) ^ 3) + (Pol2 * (val) ^ 2) + Pol1 * val + Pol0 MsgBox("El polinomio evaluado en " + val.ToString + " toma el valor de:" + Chr(13) + eval.ToString) End Sub
End Sub
y0 = txty0.Text y1 = txty1.Text y2 = txty2.Text y3 = txty3.Text
Trabajo escrito del semestral de métodos Julio Fong, Eric Hidalgo, Julio Chen, Mary Navarro, Alex Núñez Universidad Tecnológica de Panamá, Faculta de Eléctrica
[email protected] y4 = txty4.Text x0 = txtx0.Text
Dim y0, y1, y2, y3, y4, x0, x1, x2, x3, x4, A1, A2, A3, A4, B2, B3, B4, C3, C4, D4, Pol0, Pol1, Pol2, Pol3, Pol4, val, eval As Double
x1 = txtx1.Text
y0 = txty0.Text
x2 = txtx2.Text
y1 = txty1.Text
x3 = txtx3.Text
y2 = txty2.Text
x4 = txtx4.Text
y3 = txty3.Text
A1 = (y1 - y0) / (x1 - x0)
y4 = txty4.Text
A2 = (y2 - y1) / (x2 - x1)
x0 = txtx0.Text
A3 = (y3 - y2) / (x3 - x2)
x1 = txtx1.Text
A4 = (y4 - y3) / (x4 - x3)
x2 = txtx2.Text
B2 = (A2 - A1) / (x2 - x0)
x3 = txtx3.Text
B3 = (A3 - A2) / (x3 - x1)
x4 = txtx4.Text
B4 = (A4 - A3) / (x4 - x2)
A1 = (y1 - y0) / (x1 - x0)
C3 = (B3 - B2) / (x3 - x0)
A2 = (y2 - y1) / (x2 - x1)
C4 = (B4 - B3) / (x4 - x1)
A3 = (y3 - y2) / (x3 - x2)
D4 = (C4 - C3) / (x4 - x0)
A4 = (y4 - y3) / (x4 - x3)
Pol4 = D4
B2 = (A2 - A1) / (x2 - x0)
Pol3 = C3 - D4 * (x0 + x1 + x2 + x3)
B3 = (A3 - A2) / (x3 - x1)
Pol2 = B2 - C3 * (x0 + x1 + x2) + D4 * (x0 * x1 + x0 * x2 + x0 * x3 + x1 * x2 + x1 * x3 + x2 * x3) Pol1 = A1 - B2 * (x0 + x1) + C3 * (x0 * x1 + x0 * x2 + x1 * x2) - D4 * (x0 * x1 * x2 + x0 * x1 * x3 + x0 * x2 * x3 + x1 * x2 * x3) Pol0 = y0 - A1 * x0 + B2 * x0 * x1 - C3 * x0 * x1 * x2 + D4 * x0 * x1 * x2 * x3 MsgBox(Pol4.ToString + "(X^(4))+(" + Pol3.ToString + "(X^(3))+(" + Pol2.ToString + ")(X^(2))+(" + Pol1.ToString + ")X+(" + Pol0.ToString + ")") End Sub
Private Sub btnEvaluarNewton_Click(sender As Object, e As EventArgs) Handles btnEvaluarNewton.Click
B4 = (A4 - A3) / (x4 - x2) C3 = (B3 - B2) / (x3 - x0) C4 = (B4 - B3) / (x4 - x1) D4 = (C4 - C3) / (x4 - x0) Pol4 = D4 Pol3 = C3 - D4 * (x0 + x1 + x2 + x3) Pol2 = B2 - C3 * (x0 + x1 + x2) + D4 * (x0 * x1 + x0 * x2 + x0 * x3 + x1 * x2 + x1 * x3 + x2 * x3) Pol1 = A1 - B2 * (x0 + x1) + C3 * (x0 * x1 + x0 * x2 + x1 * x2) - D4 * (x0 * x1 * x2 + x0 * x1 * x3 + x0 * x2 * x3 + x1 * x2 * x3) Pol0 = y0 - A1 * x0 + B2 * x0 * x1 - C3 * x0 * x1 * x2 + D4 * x0 * x1 * x2 * x3
Trabajo escrito del semestral de métodos Julio Fong, Eric Hidalgo, Julio Chen, Mary Navarro, Alex Núñez Universidad Tecnológica de Panamá, Faculta de Eléctrica
[email protected] val = txtval.Text eval = (Pol4 * (val) ^ 4) + (Pol3 * (val) ^ 3) + (Pol2 * (val) ^ 2) + Pol1 * val + Pol0 MsgBox("El polinomio evaluado en " + val.ToString + " toma el valor de:" + Chr(13) + eval.ToString) End Sub Private Sub Label4_Click(sender As Object, e As EventArgs) Handles Label4.Click End Sub Private Sub Label7_Click(sender As Object, e As EventArgs) Handles Label7.Click End Sub End Class H) Interpolación par funciones trascendentes
Public Class Form7 Private Sub Form7_Load(sender As Object, e As EventArgs) Handles MyBase.Load End Sub Private Sub Proceder() If txty0.TextLength > 0 And txty1.TextLength > 0 And txty2.TextLength > 0 And txty3.TextLength > 0 And txty4.TextLength > 0 And txtx0.TextLength > 0 And txtx1.TextLength > 0 And txtx2.TextLength > 0 And
txtx3.TextLength > 0 And txtx4.TextLength > 0 Then btngen.Enabled = True btngenNewton.Enabled = True Else btngen.Enabled = False btngenNewton.Enabled = False End If End Sub Private Sub Evaluar() If btngen.Enabled = True And txtval.TextLength > 0 Then btnEvaluar.Enabled = True btnEvaluarNewton.Enabled = True Else btnEvaluar.Enabled = False btnEvaluarNewton.Enabled = False End If End Sub Private Sub Darval() If txtconst1.TextLength > 0 And txtconst2.TextLength > 0 And txtx0.TextLength > 0 And txtx1.TextLength > 0 And txtx2.TextLength > 0 And txtx3.TextLength > 0 And txtx4.TextLength > 0 Then valconst.Enabled = True Else valconst.Enabled = False End If End Sub Private Sub Label3_Click(sender As Object, e As EventArgs) Handles Label3.Click End Sub Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click End End Sub Private Sub txty0_TextChanged(sender As Object, e As EventArgs) Handles txty0.TextChanged Proceder() End Sub
Trabajo escrito del semestral de métodos Julio Fong, Eric Hidalgo, Julio Chen, Mary Navarro, Alex Núñez Universidad Tecnológica de Panamá, Faculta de Eléctrica
[email protected] Private Sub txty1_TextChanged(sender As Object, e As EventArgs) Handles txty1.TextChanged Proceder() End Sub Private Sub txtx0_TextChanged(sender As Object, e As EventArgs) Handles txtx0.TextChanged Proceder() End Sub Private Sub txtx1_TextChanged(sender As Object, e As EventArgs) Handles txtx1.TextChanged Proceder() End Sub Private Sub btngen_Click(sender As Object, e As EventArgs) Handles btngen.Click Dim y0, y1, y2, y3, y4, x0, x1, x2, x3, x4, Div0, Div1, Div2, Div3, Div4, Pol4, Pol3, Pol2, Pol1, Pol0 As Double y0 = txty0.Text y1 = txty1.Text y2 = txty2.Text y3 = txty3.Text y4 = txty4.Text x0 = txtx0.Text x1 = txtx1.Text x2 = txtx2.Text x3 = txtx3.Text x4 = txtx4.Text Div0 = ((x0 - x1) * (x0 - x2) * (x0 x3) * (x0 - x4)) Div1 = ((x1 - x0) * (x1 - x2) * (x1 x3) * (x1 - x4)) Div2 = ((x2 - x0) * (x2 - x1) * (x2 x3) * (x2 - x4)) Div3 = ((x3 - x0) * (x3 - x1) * (x3 x2) * (x3 - x4)) Div4 = ((x4 - x0) * (x4 - x1) * (x4 x2) * (x4 - x3)) 'Correct o's Pol0 = ((y0 * x1 * x2 * x3 * x4) / Div0) + ((y1 * x0 * x2 * x3 * x4) / Div1) + ((y2 * x0 * x1 * x3 * x4) / Div2) +
((y3 * x0 * x1 * x2 * x4) / Div3) + ((y4 * x0 * x1 * x2 * x3) / Div4) 'Correct o's Pol1 = -(((y0 * ((x1 * x2 * x3) + (x1 * x2 * x4) + (x1 * x3 * x4) + (x2 * x3 * x4))) / Div0) + ((y1 * ((x0 * x2 * x3) + (x0 * x2 * x4) + (x0 * x3 * x4) + (x2 * x3 * x4))) / Div1) + (y2 * ((x0 * x1 * x3) + (x0 * x1 * x4) + (x0 * x3 * x4) + (x1 * x3 * x4)) / Div2) + (y3 * ((x0 * x1 * x2) + (x0 * x1 * x4) + (x0 * x2 * x4) + (x1 * x2 * x4)) / Div3) + (y4 * ((x0 * x1 * x2) + (x0 * x1 * x3) + (x0 * x2 * x3) + (x1 * x2 * x3)) / Div4)) 'Correct o's Pol2 = (((y0 * ((x1 * x2) + (x1 * x3) + (x1 * x4) + (x2 * x3) + (x2 * x4) + (x3 * x4))) / Div0) + ((y1 * ((x0 * x2) + (x0 * x3) + (x0 * x4) + (x2 * x3) + (x2 * x4) + (x3 * x4))) / Div1) + ((y2 * ((x0 * x1) + (x0 * x3) + (x0 * x4) + (x1 * x3) + (x1 * x4) + (x3 * x4))) / Div2) + ((y3 * ((x0 * x1) + (x0 * x2) + (x0 * x4) + (x1 * x2) + (x1 * x4) + (x2 * x4))) / Div3) + ((y4 * ((x0 * x1) + (x0 * x2) + (x0 * x3) + (x1 * x2) + (x1 * x3) + (x2 * x3))) / Div4)) 'Correct o's Pol3 = -(((y0 * (x1 + x2 + x3 + x4)) / Div0) + ((y1 * (x0 + x2 + x3 + x4)) / Div1) + ((y2 * (x0 + x1 + x3 + x4)) / Div2) + ((y3 * (x0 + x1 + x2 + x4)) / Div3) + ((y4 * (x0 + x1 + x2 + x3)) / Div4)) Pol4 = ((y0) / Div0) + ((y1) / Div1) + ((y2) / Div2) + ((y3) / Div3) + ((y4) / Div4) MsgBox(Pol4.ToString + "(X^(4))+(" + Pol3.ToString + "(X^(3))+(" + Pol2.ToString + ")(X^(2))+(" + Pol1.ToString + ")X+(" + Pol0.ToString + ")") End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click Me.Close() End Sub
Trabajo escrito del semestral de métodos Julio Fong, Eric Hidalgo, Julio Chen, Mary Navarro, Alex Núñez Universidad Tecnológica de Panamá, Faculta de Eléctrica
[email protected] Private Sub txtval_TextChanged(sender As Object, e As EventArgs) Handles txtval.TextChanged Evaluar() End Sub Private Sub btnEvaluar_Click(sender As Object, e As EventArgs) Handles btnEvaluar.Click Dim y0, y1, y2, y3, y4, x0, x1, x2, x3, x4, val, eval, Div0, Div1, Div2, Div3, Div4, Pol4, Pol3, Pol2, Pol1, Pol0 As Double y0 = txty0.Text y1 = txty1.Text y2 = txty2.Text y3 = txty3.Text y4 = txty4.Text x0 = txtx0.Text x1 = txtx1.Text x2 = txtx2.Text x3 = txtx3.Text x4 = txtx4.Text val = txtval.Text Div0 = ((x0 - x1) * (x0 - x2) * (x0 x3) * (x0 - x4)) Div1 = ((x1 - x0) * (x1 - x2) * (x1 x3) * (x1 - x4)) Div2 = ((x2 - x0) * (x2 - x1) * (x2 x3) * (x2 - x4)) Div3 = ((x3 - x0) * (x3 - x1) * (x3 x2) * (x3 - x4)) Div4 = ((x4 - x0) * (x4 - x1) * (x4 x2) * (x4 - x3)) Pol0 = ((y0 * x1 * x2 * x3 * x4) / Div0) + ((y1 * x0 * x2 * x3 * x4) / Div1) + ((y2 * x0 * x1 * x3 * x4) / Div2) + ((y3 * x0 * x1 * x2 * x4) / Div3) + ((y4 * x0 * x1 * x2 * x3) / Div4) Pol1 = -(((y0 * ((x1 * x2 * x3) + (x1 * x2 * x4) + (x1 * x3 * x4) + (x2 * x3 * x4))) / Div0) + ((y1 * ((x0 * x2 * x3) + (x0 * x2 * x4) + (x0 * x3 * x4) + (x2 * x3 * x4))) / Div1) + (y2 * ((x0 * x1 * x3) + (x0 * x1 * x4) + (x0 * x3 * x4) + (x1 * x3 * x4)) / Div2) + (y3 * ((x0 * x1 * x2) + (x0 * x1 * x4) + (x0 * x2 * x4) + (x1 * x2 * x4)) / Div3) + (y4 * ((x0 * x1 * x2) + (x0 * x1 * x3) + (x0 * x2 * x3) + (x1 * x2 * x3)) / Div4))
Pol2 = (((y0 * ((x1 * x2) + (x1 * x3) + (x1 * x4) + (x2 * x3) + (x2 * x4) + (x3 * x4))) / Div0) + ((y1 * ((x0 * x2) + (x0 * x3) + (x0 * x4) + (x2 * x3) + (x2 * x4) + (x3 * x4))) / Div1) + ((y2 * ((x0 * x1) + (x0 * x3) + (x0 * x4) + (x1 * x3) + (x1 * x4) + (x3 * x4))) / Div2) + ((y3 * ((x0 * x1) + (x0 * x2) + (x0 * x4) + (x1 * x2) + (x1 * x4) + (x2 * x4))) / Div3) + ((y4 * ((x0 * x1) + (x0 * x2) + (x0 * x3) + (x1 * x2) + (x1 * x3) + (x2 * x3))) / Div4)) Pol3 = -(((y0 * (x1 + x2 + x3 + x4)) / Div0) + ((y1 * (x0 + x2 + x3 + x4)) / Div1) + ((y2 * (x0 + x1 + x3 + x4)) / Div2) + ((y3 * (x0 + x1 + x2 + x4)) / Div3) + ((y4 * (x0 + x1 + x2 + x3)) / Div4)) Pol4 = ((y0) / Div0) + ((y1) / Div1) + ((y2) / Div2) + ((y3) / Div3) + ((y4) / Div4) eval = (Pol4 * (val) ^ 4) + (Pol3 * (val) ^ 3) + (Pol2 * (val) ^ 2) + Pol1 * val + Pol0 MsgBox("El polinomio evaluado en " + val.ToString + " toma el valor de:" + Chr(13) + eval.ToString) End Sub Private Sub txty2_TextChanged(sender As Object, e As EventArgs) Handles txty2.TextChanged Proceder() End Sub Private Sub txtx2_TextChanged(sender As Object, e As EventArgs) Handles txtx2.TextChanged Proceder() End Sub Private Sub txty3_TextChanged(sender As Object, e As EventArgs) Handles txty3.TextChanged Proceder() End Sub
Trabajo escrito del semestral de métodos Julio Fong, Eric Hidalgo, Julio Chen, Mary Navarro, Alex Núñez Universidad Tecnológica de Panamá, Faculta de Eléctrica
[email protected] Private Sub txtx3_TextChanged(sender As Object, e As EventArgs) Handles txtx3.TextChanged Proceder() End Sub Private Sub txty4_TextChanged(sender As Object, e As EventArgs) Handles txty4.TextChanged Proceder() End Sub Private Sub txtx4_TextChanged(sender As Object, e As EventArgs) Handles txtx4.TextChanged Proceder() End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles valconst.Click Dim c1, c2, x0, x1, x2, x3, x4 As Double c1 = txtconst1.Text c2 = txtconst2.Text x0 = txtx0.Text x1 = txtx1.Text x2 = txtx2.Text x3 = txtx3.Text x4 = txtx4.Text If (exponencial.Checked = True) Then txty0.Text = c1 * ((2.718281828) ^ ((c2) * (x0))) txty1.Text = c1 * ((2.718281828) ^ ((c2) * (x1))) txty2.Text = c1 * ((2.718281828) ^ ((c2) * (x2))) txty3.Text = c1 * ((2.718281828) ^ ((c2) * (x3))) txty4.Text = c1 * ((2.718281828) ^ ((c2) * (x4))) ElseIf (seno.Checked = True) Then txty0.Text = c1 * Math.Sin(c2 * x0) txty1.Text = c1 * Math.Sin(c2 * x1)
txty2.Text = c1 * Math.Sin(c2 * x2) txty3.Text = c1 * Math.Sin(c2 * x3) txty4.Text = c1 * Math.Sin(c2 * x4) ElseIf (coseno.Checked = True) Then txty0.Text = c1 * Math.Cos(c2 * x0) txty1.Text = c1 * Math.Cos(c2 * x1) txty2.Text = c1 * Math.Cos(c2 * x2) txty3.Text = c1 * Math.Cos(c2 * x3) txty4.Text = c1 * Math.Cos(c2 * x4) ElseIf (tangente.Checked = True) Then txty0.Text = c1 * Math.Tan(c2 * x0) txty1.Text = c1 * Math.Tan(c2 * x1) txty2.Text = c1 * Math.Tan(c2 * x2) txty3.Text = c1 * Math.Tan(c2 * x3) txty4.Text = c1 * Math.Tan(c2 * x4) ElseIf (logaritmo.Checked = True) Then txty0.Text = c1 * Math.Log10(c2 * x0) txty1.Text = c1 * Math.Log10(c2 * x1) txty2.Text = c1 * Math.Log10(c2 * x2) txty3.Text = c1 * Math.Log10(c2 * x3) txty4.Text = c1 * Math.Log10(c2 * x4) ElseIf (logaritmon.Checked = True) Then txty0.Text = c1 * Math.Log(c2 * x0) txty1.Text = c1 * Math.Log(c2 * x1) txty2.Text = c1 * Math.Log(c2 * x2)
Trabajo escrito del semestral de métodos Julio Fong, Eric Hidalgo, Julio Chen, Mary Navarro, Alex Núñez Universidad Tecnológica de Panamá, Faculta de Eléctrica
[email protected] txty3.Text = c1 * Math.Log(c2 *
Pol4 = D4 Pol3 = C3 - D4 * (x0 + x1 + x2 +
x3) txty4.Text = c1 * Math.Log(c2 * x4) Else MsgBox("Seleccione una funcion") End If End Sub Private Sub txtconst2_TextChanged(sender As Object, e As EventArgs) Handles txtconst2.TextChanged Darval() End Sub Private Sub txtconst1_TextChanged(sender As Object, e As EventArgs) Handles txtconst1.TextChanged Darval() End Sub Private Sub btngenNewton_Click(sender As Object, e As EventArgs) Handles btngenNewton.Click Dim y0, y1, y2, y3, y4, x0, x1, x2, x3, x4, A1, A2, A3, A4, B2, B3, B4, C3, C4, D4, Pol0, Pol1, Pol2, Pol3, Pol4 As Double y0 = txty0.Text y1 = txty1.Text y2 = txty2.Text y3 = txty3.Text y4 = txty4.Text x0 = txtx0.Text x1 = txtx1.Text x2 = txtx2.Text x3 = txtx3.Text x4 = txtx4.Text A1 = (y1 - y0) / (x1 - x0) A2 = (y2 - y1) / (x2 - x1) A3 = (y3 - y2) / (x3 - x2) A4 = (y4 - y3) / (x4 - x3) B2 = (A2 - A1) / (x2 - x0) B3 = (A3 - A2) / (x3 - x1) B4 = (A4 - A3) / (x4 - x2) C3 = (B3 - B2) / (x3 - x0) C4 = (B4 - B3) / (x4 - x1) D4 = (C4 - C3) / (x4 - x0)
x3) Pol2 = B2 - C3 * (x0 + x1 + x2) + D4 * (x0 * x1 + x0 * x2 + x0 * x3 + x1 * x2 + x1 * x3 + x2 * x3) Pol1 = A1 - B2 * (x0 + x1) + C3 * (x0 * x1 + x0 * x2 + x1 * x2) - D4 * (x0 * x1 * x2 + x0 * x1 * x3 + x0 * x2 * x3 + x1 * x2 * x3) Pol0 = y0 - A1 * x0 + B2 * x0 * x1 - C3 * x0 * x1 * x2 + D4 * x0 * x1 * x2 * x3 MsgBox(Pol4.ToString + "(X^(4))+(" + Pol3.ToString + "(X^(3))+(" + Pol2.ToString + ")(X^(2))+(" + Pol1.ToString + ")X+(" + Pol0.ToString + ")") End Sub Private Sub btnEvaluarNewton_Click(sender As Object, e As EventArgs) Handles btnEvaluarNewton.Click Dim y0, y1, y2, y3, y4, x0, x1, x2, x3, x4, A1, A2, A3, A4, B2, B3, B4, C3, C4, D4, Pol0, Pol1, Pol2, Pol3, Pol4, val, eval As Double y0 = txty0.Text y1 = txty1.Text y2 = txty2.Text y3 = txty3.Text y4 = txty4.Text x0 = txtx0.Text x1 = txtx1.Text x2 = txtx2.Text x3 = txtx3.Text x4 = txtx4.Text A1 = (y1 - y0) / (x1 - x0) A2 = (y2 - y1) / (x2 - x1) A3 = (y3 - y2) / (x3 - x2) A4 = (y4 - y3) / (x4 - x3) B2 = (A2 - A1) / (x2 - x0) B3 = (A3 - A2) / (x3 - x1) B4 = (A4 - A3) / (x4 - x2) C3 = (B3 - B2) / (x3 - x0) C4 = (B4 - B3) / (x4 - x1) D4 = (C4 - C3) / (x4 - x0) Pol4 = D4 Pol3 = C3 - D4 * (x0 + x1 + x2 + x3)
Trabajo escrito del semestral de métodos Julio Fong, Eric Hidalgo, Julio Chen, Mary Navarro, Alex Núñez Universidad Tecnológica de Panamá, Faculta de Eléctrica
[email protected] Pol2 = B2 - C3 * (x0 + x1 + x2) + D4 * (x0 * x1 + x0 * x2 + x0 * x3 + x1 * x2 + x1 * x3 + x2 * x3) Pol1 = A1 - B2 * (x0 + x1) + C3 * (x0 * x1 + x0 * x2 + x1 * x2) - D4 * (x0 * x1 * x2 + x0 * x1 * x3 + x0 * x2 * x3 + x1 * x2 * x3) Pol0 = y0 - A1 * x0 + B2 * x0 * x1 - C3 * x0 * x1 * x2 + D4 * x0 * x1 * x2 * x3 val = txtval.Text eval = (Pol4 * (val) ^ 4) + (Pol3 * (val) ^ 3) + (Pol2 * (val) ^ 2) + Pol1 * val + Pol0 MsgBox("El polinomio evaluado en " + val.ToString + " toma el valor de:" + Chr(13) + eval.ToString) End Sub Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click MsgBox("Las constantes que seran ingresadas funcionan de la siguiente manera:" + Chr(13) + "La constante constante 1 sera colocada antes de la funcion a manera de factor, la constante 2, junto con la variable independiente tambien como facto") End Sub End Class
V. Conclusiones A) Ambas interpolaciones son métodos que permiten la creación de un polinomio de grado n-1, donde n es el número de datos que se tienen. Ambos métodos asumen que no existe ruido en sus mediciones de datos, es decir, que el polinomio generado por el método pasara por todas las coordenadas insertadas al método. B) El propósito de ambos métodos es poder generar una función para la cual se puedan introducir todos los datos originales y obtener 0 error, pues la curva se va modelando punto a punto. Al obtener una función, se puede crear aproximaciones y estimaciones. (En nuestros métodos, no proporcionamos al
la función, solamente el valor f(x) para la x deseada). C)
El método de Newton, donde las “y” entre corchetes se refieren al cálculo de diferencias dividas, el cual es un algoritmo usado para computar tablas de funciones logarítmicas y trigonométricas, usando división recursiva.
D) El método de Larange obtiene una misma función, pero elimina por completo la necesidad de usar diferencias divididas. Los polinomios de lagrange son más fáciles de computar, pues elimina la necesidad de recurrir a métodos de recursión.
VI. Recomendaciones A) Lo más interesante de este proyecto fue el uso de la amplia gama de aplicaciones que se puede obtener en internet para construir algoritmos. Fue bastante entretenido idear y trabajar como grupo, en cómo realizar un programa que tuviera una buena estética y un lenguaje sencillo para trabajar. B) Pudimos observar la gran cantidad utilidades que tienen los métodos desarrollados en este proyecto, para diversas ramas de estudio tal como es la física, matemáticas y las ciencias sociales. C) Lo que más nos gustó fue, el haber probado diversos lenguajes a la vez, tal como fue con JAVA, PYTHON, C++, y VISUAL BASIC. Fue entretenido probar diversos algoritmos de practica que compilaran y corrieran bien, sin ningún problema, al final escogimos VB por que nos resultó bastante familiar el lenguaje y era más sencilla sus denotaciones.