University of Babylon
Subject : Fortran 90
College of Engineering
Derivation
The Newton-Raphson method is based on the principle that if the initial
guess of the root of f(x)=0 at xi , then if one draws the tangent to the curve at
f(xi), the point xi+1 where the tangent crosses the x -axis is an improved
estimate of the root (Figure 1).
Which gives
EX
solve x3 x 1 = 0 for x.
In this case f(x) = x3 x 1, so f ' (x) = 3x2 1
Need to decide on an appropriate initial guess x0 for this problem. A
rough graph can help. Note that f(1) = 1 < 0 and f(2) = 5 > 0. Therefore, a
root of f(x) = 0 must exist between 1 and 2. Let us take x0 = 1 as our initial
guess. Then
and with x0 = 1 we get x1 = 1.5.
Now
and with x1 = 1.5 we get x2 = 1.34783. For the next stage,
and with the value just found for x2, we find x3 = 1.32520. Carrying on, we
find that x4 = 1.32472, x5 = 1.32472, etc. We can stop when the digits stop
changing to the required degree of accuracy. We conclude that the root is
1.32472 to 5 decimal places.
program newton_raphson
implicit none
real, parameter::error =1e-4
integer::i
real::xo,x1,f,fd
read*,xo
i=1
10x1=xo-(f(xo)/fd(xo))
if(abs((x1-xo)/x1)<error)then
print*,"root is ", x1 ,"no. of iteration=", i
else
xo=x1
i=i+1
goto 10
endif
end