Saturday, April 3, 2010

ITERATION & NEWTON-RAPHSON METHOD

The following is an iteration using VBA excel code created by the author to produce approximate numerical solutions to certain mathematical problems:

Private Sub Commanditerate_Click()

Range("A8:c8").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents

Dim a, b, e, per As Double
e = Sheets(2).Cells(3, 2).Value
For x = 1 To 1000000

a = Sheets(2).Cells(6, 2).Value
b = Sheets(2).Cells(6, 3).Value
per = Abs((a - b) / b) * 100
If per < e Then GoTo 100

Sheets(2).Cells(6, 1).Value = x
Sheets(2).Cells(6, 2).Value = b
Sheets(2).Cells(7 + x, 1).Value = x
Sheets(2).Cells(7 + x, 2).Value = b
Next x

100:
Sheets(2).Cells(2, 2).Value = b
Sheets(2).Cells(7 + x, 1).Value = x
Sheets(2).Cells(7 + x, 2).Value = b
Range("b6:b6").Select
End Sub

Below is a video of iteration method by using Newton-Raphson Method