program newton_raphson
real::x
!defining f(x)=given function whose root is required
f(x)=x*x-25
!defining g(x)=first order derivative of the function
g(x)=2*x
print*,'Enter the initial guess:'
read(*,*)x
!iteration starts
1 x=x-f(x)/g(x)
if(abs(f(x))>0.0001) then
goto 1
else
print*,x
endif
end
real::x
!defining f(x)=given function whose root is required
f(x)=x*x-25
!defining g(x)=first order derivative of the function
g(x)=2*x
print*,'Enter the initial guess:'
read(*,*)x
!iteration starts
1 x=x-f(x)/g(x)
if(abs(f(x))>0.0001) then
goto 1
else
print*,x
endif
end
Comments
Post a Comment