Está en la página 1de 11

Universidad Tecnológica de Panamá

Centro Regional de panamá Oeste


Proyecto#1
Métodos numéricos

Integrantes:
Carol De León
Alexander Flores
Edward González
Katherine González

Profesora:
Geovana Bonagas

Grupo:
9II-121

Métodos preparados:

Newton Raphson: Carol De León, Edward González


Regula falsi:
Gauss Seidel: Alexander Flores, Katherine González
Método Newton Raphson
Preparado por Carol De León, Edward González
Formulario
código
Public Class Form1
Private Function fx(ByVal x As Single) As Single
Dim resultado As Single
resultado = x ^ 4 + 2 * x ^ 2 + 10 * x - 20
Return resultado
End Function
Private Function dfx(ByVal x As Single) As Single
Dim resultado As Single
resultado = 4 * x ^ 3 + 4 * x + 10
Return resultado
End Function
Private Function d2fx(ByVal x As Single) As Single
Dim resultado As Single
resultado = 12 * x ^ 2 + 4
Return resultado
End Function
Sub newtonraphson(ByVal Xo As Double, ByVal eps As Single, ByVal nmax As
Integer)
Dim n As Integer
Dim rn As Single
Dim convergencia As Single
Dim fin As Boolean
Dim xold As Single
Dim numerador As Single
Dim denominador As Single
n = 0
rn = 100
convergencia = fx(Xo) * d2fx(Xo)
If (convergencia <= 0) Then
MessageBox.Show("No se puede encontrar raiz por este método")
End
End If
fin = False
While (fin = False)
xold = Xo
numerador = fx(Xo)
denominador = dfx(Xo)
Xo = xold - numerador / denominador
n = n + 1
If (n > 2) Then
rn = Math.Abs((Xo - xold) / Xo)
End If

End While
Label6.Text = "Se realizaron" & n & "repeticiones"
TextBox5.Text = rn
TextBox6.Text = Xo
End Sub
Private Function fb(ByVal x As Single) As Single
Dim resultado As Single
resultado = x ^ 4 + 2 * x ^ 2 + 10 * x - 20 'funcion a evaluar
Return resultado
End Function
Sub biseccion(ByVal xi As Single, ByVal xd As Single, ByVal ee As Single, ByVal
nmax As Integer)
Dim n As Integer
Dim xn As Double
Dim res As Single
Dim rn As Single
Dim mul As Single
Dim fin As Boolean
Dim xnold As Single
n = 0
xn = 0
res = 0
rn = 100
mul = fb(xi) * fb(xd)
If (mul > 0) Then
MessageBox.Show("No se puede encontrar raíz por este método")
End
End If
fin = False
While (fin = False)
xnold = xn
n = n + 1
If (xn <> 0 And n > 1) Then
rn = Math.Abs((xn - xnold) / xn)
End If
mul = fb(xn) * fb(xi)
If (mul < 0) Then
xd = xn
ElseIf (mul > 0) Then
xi = xn
Else
rn = 0
End If
mul = fb(xi) * fb(xd)
If ((n > nmax) Or (ee > rn) Or (rn = 0) Or (mul > 0)) Then
fin = True
End If
End While
Label6.Text = "se realizaron" & n & "repeticiones "
TextBox2.Text = xn
TextBox3.Text = rn
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

newtonraphson(Val(TextBox1.Text), Val(TextBox2.Text), Val(TextBox3.Text))


End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles


Button2.Click
biseccion(Val(TextBox4.Text), Val(TextBox7.Text), Val(TextBox5.Text),
Val(TextBox6.Text))
End Sub
End Class
Ejecución del método
Método Regula Falsi
Preparado por Katherine González
Formulario

Codigo
Public Class Form1
Function f(x)
f = x ^ 2 * Math.Abs(Math.Cos(Math.Sqrt(x))) - 5
End Function

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles


Button1.Click
Dim a As Double
Dim b As Double
Dim c As Double
Dim tol As Double
Dim eror As Double
Dim n As Integer
Dim nmax As Integer

a = Val(TextBox1.Text)
b = Val(TextBox2.Text)
tol = Val(TextBox4.Text)
nmax = Val(TextBox5.Text)

n = 3.1415
Do
c = b - (f(b) * (a - b)) / (f(a) - f(b))
eror = Math.Abs(c - b)
If f(b) * f(c) < 0 Then
a = b
b = c
TextBox7.Text = Math.Abs((c - b) / c)
Else
a = c
b = b
TextBox7.Text = Math.Abs((c - a) / c)
End If
ListBox1.Items.Add(c)

n = n + 1

Loop While eror > tol And n <= nmax

TextBox6.Text = c

Label9.Text = "Se realizaron" & Str(n - 1) & "Iteraciones"

End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles


Button2.Click
End
End Sub
End Class

Ejecución del método


Método Newton Raphson
Preparado por Alexander Flores, Katherine González
Formulario
Código
Public Class Form1
Private Sub Gauss_Seidel(ByVal V1 As Single, ByVal V2 As Single, ByVal V3 As
Single, ByVal V4 As Single, ByVal V5 As Single, ByVal V6 As Single, ByVal V7 As
Single, ByVal V8 As Single, ByVal V9 As Single, ByVal T1 As Single, ByVal T2 As
Single, ByVal T3 As Single, ByVal EE As Single, ByVal NMAX As Single)
Dim X1old, X2old, X3old As Double
Dim x1new, x2new, x3new As Double
Dim valor1, valor2, valor3, valor4, valor5, valor6, valor7, valor8, valor9
As Double
Dim ter1, ter2, ter3 As Double
Dim eror As Double
Dim nmaximo As Integer
Dim n As Integer
Dim rx1n, rx2n, rx3n As Double
Dim fin As Boolean
valor1 = V1
valor2 = V2
valor3 = V3
valor4 = V4
valor5 = V5
valor6 = V6
valor7 = V7
valor8 = V8
valor9 = V9
ter1 = T1
ter2 = T2
ter3 = T3
eror = EE
nmaximo = NMAX
X1old = 0
X2old = 1
X3old = 0

If ((Math.Abs(valor1) > ((Math.Abs(valor2) And Math.Abs(valor3))))) And


((Math.Abs(valor5) > ((Math.Abs(valor4) And Math.Abs(valor6))))) And
((Math.Abs(valor9) > ((Math.Abs(valor8) And Math.Abs(valor7))))) Then
fin = True 'si hay convergencia
Else
'no hay convergencia
MessageBox.Show("EL METODO PUEDE PRESENTAR FALLAS A CAUSA DE LA NO
CONVERGENCIA. INTENTE PIVOTEO")
End
End If

n = 0
While fin = True
x1new = (ter1 - valor2 * X2old - valor3 * X3old) / valor1
x2new = (ter2 - valor4 * x1new - valor6 * X3old) / valor5
x3new = (ter3 - valor7 * x1new - valor8 * x2new) / valor9

rx1n = Math.Abs((x1new - X1old) / x1new) * 100


rx2n = Math.Abs((x2new - X2old) / x2new) * 100
rx3n = Math.Abs((x3new - X3old) / x3new) * 100

X1old = x1new
X2old = x2new
X3old = x3new

n = n + 1
If (n > nmaximo) Or (rx1n < eror And rx2n < eror And rx3n < eror) Then
fin = False
End If
End While

Label11.Text = "Se realizaron" & Str(n - 1) & "Iteraciones"


TextBox15.Text = X1old
TextBox16.Text = X2old
TextBox17.Text = X3old

TextBox18.Text = rx1n
TextBox19.Text = rx2n
TextBox20.Text = rx3n

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles


Button1.Click
Gauss_Seidel(Val(TextBox1.Text), Val(TextBox2.Text), Val(TextBox3.Text),
Val(TextBox4.Text), Val(TextBox5.Text), Val(TextBox6.Text), Val(TextBox7.Text),
Val(TextBox8.Text), Val(TextBox9.Text), Val(TextBox10.Text), Val(TextBox11.Text),
Val(TextBox12.Text), Val(TextBox13.Text), Val(TextBox14.Text))
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles


Button2.Click
End

End Sub
End Class
Ejecución del método

También podría gustarte