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.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.0) then
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 = 1, itrtn
xv = (a * f(b) - b* f(a)) / (f(b)-f(a))
if(f(xv).eq.0) then
print*,"The soln is: ",xv
stop
end if
if(f(a)*f(xv).le.0) then
b = xv
print*,a,b
else
a = xv
print*,a,b
end if
if(abs(a-b).le.tol) then
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**3 - 2*x -5
return
end function