Solving by Fixed Point Iteration method in FORTRAN CODE::BLOCKS

Originally posted on here

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

The equation x3 - 2x - 5 = 0 is solved here by the method of Fixed Point Iteration in FORTRAN language with CODE::BLOCKS. Here the trick of algorithm of Fixed Point Iteration is given bellow:

1. Take a point enclosed to the solution.
2. Make another function which gives the value of x.
3. Put the point value in the new function and this will be the new point.
4. Do as before until you get the result.


The programming source code is given bellow:









program fixed

    implicit none

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

    integer
::i,itrtn



    
print*,"Enter the initial point:"

    
read(*,*)x0

    
print*,"Enter the total iteration:"

    
read(*,*)itrtn

    
print*,"Enter the tolerance:"

    
read(*,*)tol

print*,x0

    
do 10 i 1,itrtn





        x1 
g(x0);

print*,
x1

        
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

    f 
x**2*-5

    
return

end function





real function g(x)

    
real::x

    g 
= (x+5.)**(1./3.)

    return

end function












Related Posts
Previous
« Prev Post