0% found this document useful (0 votes)
42 views3 pages

'Asingnando Valores A Las Variables: Form1 Varianttype

This document defines variables and functions for implementing the Newton-Raphson method to find the root of an equation. It defines variables to store the initial guess, tolerance, maximum iterations, function value and derivative at each iteration. The main loop performs the Newton-Raphson method, calculating the next guess and checking if it has converged based on the tolerance. It outputs the results to a grid and checks for failure to converge after max iterations.

Uploaded by

sandra quispe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views3 pages

'Asingnando Valores A Las Variables: Form1 Varianttype

This document defines variables and functions for implementing the Newton-Raphson method to find the root of an equation. It defines variables to store the initial guess, tolerance, maximum iterations, function value and derivative at each iteration. The main loop performs the Newton-Raphson method, calculating the next guess and checking if it has converged based on the tolerance. It outputs the results to a grid and checks for failure to converge after max iterations.

Uploaded by

sandra quispe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Dim r As Object

Public xi As Double
Public tol As Double
Public maxi As Double
Public conta As Double
Public fxi As Double
Public dfxi As Double
Public ximas1 As Double
Public fximas1 As Double

'Asingnando valores a las variables


xi = txtXi.Text
tol = Val(txtTol.Text)
maxi = txtMax.Text
^

Option Explicit On
Public Class Form1
Dim r As VariantType
Public xi As Double
Public tol As Double
Public maxi As Double
Public conta As Double
Public fxi As Double
Public dfxi As Double
Public ximas1 As Double
Public fximas1 As Double

Private Sub cmdCalcular_Click()


'Asignando valores a las variables
xi = txtXi.Text
tol = Val(txtTol.Text)
maxi = txtMax.Text

For Me.conta = 1 To maxi '-------Rutina principal


fxi = fun(xi) '-------Llama a la funcion que contiene a la ecuación
dfxi = der(xi) '-------Llama a la funcion de la derivada
ximas1 = xi - fxi / dfxi
fximas1 = fun(ximas1)
'Mostrando resultados
mfgResult.Col = 0
mfgResult.Row = conta
mfgResult.Text = conta
mfgResult.Col = 1
mfgResult.Row = conta
mfgResult.Text = Math.Round(xi, 4)
mfgResult.Col = 2
mfgResult.Row = conta
mfgResult.Text = Math.Round(fxi, 4)
mfgResult.Col = 3
mfgResult.Row = conta
mfgResult.Text = Math.Round(dfxi, 4)
mfgResult.Col = 4
mfgResult.Row = conta
mfgResult.Text = Math.Round(ximas1, 4)
mfgResult.Col = 5
mfgResult.Row = conta
mfgResult.Text = Math.Round(fximas1, 4) '---------Llama al
procedimiento muestra para resultados

If Math.Abs(fximas1) >= tol Then '-----Verifica la tolerancia


xi = ximas1
Else
Exit For 'Se sale del for si se alcanza la solucion
End If
Next

If Math.Abs(fximas1) >= tol Then


r = MsgBox("El Metodo no converge en el numero de iteraciones
especificadas")
End If

End Sub
Public Function fun(ByVal x) '-------Funcion que especifica la ecuacion
fun = x ^ 3 + 2 * x ^ 2 - 3
End Function
Public Function der(ByVal x) '--------Funcion que especifica a la derivada
der = 3 * x ^ 2 + 4 * x
End Function
Private Sub cmdBorrar_click()
mfgResult.Clear()
txtXi.Text = ""
txtTol.Text = ""
txtMax.Text = ""
mfgResult.Col = 0
mfgResult.Row = 0
mfgResult.Text = "N° Iter"
mfgResult.Col = 1
mfgResult.Row = 0
mfgResult.Text = "Xi"
mfgResult.Col = 2
mfgResult.Row = 0
mfgResult.Text = "F(Xi)"
mfgResult.Col = 3
mfgResult.Row = 0
mfgResult.Text = "F'(xi)"
mfgResult.Col = 4
mfgResult.Row = 0
mfgResult.Text = "Xi+1"
mfgResult.Col = 5
mfgResult.Row = 0
mfgResult.Text = "F(Xi+1)"End sub

Private Sub cmdSalir_click()


End
End Sub

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy