Solving by False Position method in FORTRAN CODE::BLOCKS

Originally posted on here

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

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

1. Take two point whose functional value sign is opposite.
2. Do as the formula.
3. Follow the source code bellow.


The programming source code is given bellow:







program false

    implicit none

    real
::a,b,f,x,tol,xv

    integer
::itrtn,i



    
print*, "Enter the initial values (a,b):"

    
read(*,*)a,b



    
if( (f(a)*f(b)) .gt.0then

        write
(*,*)"Can not be done"f(a), f(b);

        
stop

    end 
if





    print*, 
"Enter the number of iteration:"

    
read(*,*)itrtn

    
print*, "Enter the tolerance:"

    
read(*,*)tol



    
do 10 i 1itrtn

        xv 
= (f(b) - bf(a)) / (f(b)-f(a))

        if(
f(xv).eq.0then

            
print*,"The soln is: ",xv

            stop

        end 
if

        if(
f(a)*f(xv).le.0then

                b 
xv

                
print*,a,b

            
else

                
xv

                
print*,a,b

        end 
if

        if(
abs(a-b).le.tolthen

            
print*, "The approximate soln is: ",xv

            stop

        end 
if

    
10 continue

    print*,
"Maximum iteration failed"



end program





real 
function f(x)

    
real::x

    f 
x**2*-5

    
return

end function












Related Posts
Previous
« Prev Post