Newton Raphson Method

Example 6.2 in Book

 

Wesley N Donald

 

 

 

15-Nov-05

Minimum Error

0.00001

 

C. E. Analylis

Initial Guess

0

 

Dr. Clement

Maximum Iterations

20

 

 

 

 

 

 

Iterations

Values for X

Error

 

1

0

100

 

2

0.5

11.70929098

 

3

0.566311003

0.146728708

 

4

0.567143165

2.21064E-05

 

5

0.56714329

5.08968E-13

 

 

Option Explicit

 

Sub main()

Dim i As Integer, n As Integer

Dim x() As Double, f() As Double, fprime() As Double, Ea() As Double, iter() As Double

n = Cells(5, 2)

ReDim x(n) As Double, f(n) As Double, fprime(n) As Double, Ea(n) As Double, iter(n) As Double

x(1) = Cells(4, 2)

Ea(1) = 100

iter(1) = 1

f(1) = 0

fprime(1) = 0

For i = 2 To n Step 1

f(i) = Exp(-x(i - 1)) - x(i - 1)

fprime(i) = -Exp(-x(i - 1)) - 1

x(i) = x(i - 1) - (f(i) / fprime(i))

Ea(i) = Abs((x(i) - x(i - 1)) / x(i)) * 100

iter(i) = i

Cells(6 + i, 1) = iter(i - 1)

Cells(6 + i, 2) = x(i - 1)

Cells(6 + i, 3) = Ea(i)

If Ea(i) < Cells(3, 2) Then

End

End If

Next i

 

End Sub