You are on page 1of 1

Newton - Raphson

Public Class Form1


Dim xo As Double
Dim x AsD ouble
Dim xi As Double
Dim fx As Double
Dim Dfx As Double
Dim fxi As Double
Dim EPS As Double
Dim i As Integer

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
xo = Val(TextBox1.Text)
EPS = Val(TextBox2.Text)
i = 0
fx = xo ^ 3 + 2 * xo ^ 2 + 10 * xo - 20
Dfx = 3 * xo ^ 2 + 4 * xo + 10
xi = xo - fx / Dfx
fxi = xi ^ 3 + 2 * xi ^ 2 + 10 * xi - 20
ListBox1.Items.Add(Format(i, "000") & Space(15) & Format(xo,
"0.000000") & Space(15) & Format(fx, "0.000000") & Space(15) & Format(Dfx,
"0.000000") & Space(15) & Format(xi, "0.000000") & Space(15) & Format(fxi,
"0.000000"))

While System.Math.Abs(fxi) > EPS

fx = xo ^ 3 + 2 * xo ^ 2 + 10 * xo - 20
Dfx = 3 * xo ^ 2 + 4 * xo + 10
xi = xo - fx / Dfx
fxi = xi ^ 3 + 2 * xi ^ 2 + 10 * xi - 20
xo = xi
i = i + 1
ListBox1.Items.Add(Format(i, "000") & Space(15) & Format(xo,
"0.000000") & Space(15) & Format(fx, "0.000000") & Space(15) & Format(Dfx,
"0.000000") & Space(15) & Format(xi, "0.000000") & Space(15) & Format(fxi,
"0.000000"))
End While
TextBox3.Text = Format(xi, "0.000000")
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
ListBox1.Items.Clear()
TextBox1.Focus()
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
End
End Sub
End Class

You might also like