Solving by Newton–Raphson method in FORTRAN CODE::BLOCKS

Originally posted on here

The source code of Newton–Raphson method.Here the equation x3 - 2x - 5 = 0 is solved by the method of Newton–Raphson in FORTRAN language with CODE::BLOCKS.
Solving by Newton–Raphson method in FORTRAN CODE::BLOCKS

The equation x3 - 2x - 5 = 0 is solved here by the method of Newton–Raphson in FORTRAN language with CODE::BLOCKS. We know the method of Newton–Raphson is near to the false position method. Here the trick of algorithm is bellow:

1. Take a point near the solution.
2. Subtract the quotient of the functional value and the derivative functional value of that function in the point.
3. It will be the new point near the solution.
4. When the functional value is equal to zero it will be the exact solution.


The programming source code is given bellow:









program newton

    implicit none

    real
::f,x,fp,x0,x1,tol

    integer
::itrtn,i

    
print*,"Enter the initial point:"

    
read(*,*)x0

    
print*,"Enter the total iteration:"

    
read(*,*)itrtn

    
print*,"Enter the tolerance:"

    
read(*,*)tol





    
do 10 i 1,itrtn

        x1 
x0 f(x0)/fp(x0)



        if(
f(x1).eq.0then

            
print*, "The soln is:",x1

            stop

        end 
if



        if(
abs(x0-x1).le.tolthen

            
print*,"Approximate soln is:",x1

            stop

        end 
if

        
x0 x1



10  
continue



    print*,
"Maximum iteration failed"













end program



real 
function f(x)

real::x

x**2*5

return

end function



real function fp(x)

real::x

fp 
3*x**2

return

end function










Related Posts
Previous
« Prev Post