***REGULA FALSI METHOD************************************************
* THIS PROGRAM FINDS THE ROOT OF AN ALGEBRAIC/TRANSCENDENTAl *
* EQUATION BY REGULA FALSI METHOD *
**********************************************************************
*
program REGULAFALSI
implicit doubleprecision(a-h,o-z)
c
c Defining the Function 'F(x)=0' to be solved
F(x) = x**2 - 10*x + 3d0
*
print*, 'Enter lower limit (guessed) of the interval, xl:'
read(*,*) xl
print*, 'Enter upper limit (guessed) of the interval, xu:'
read(*,*) xu
prod = F(xl) * F(xu)
*
if (prod > 0d0) then
write(6,*)'The root does not lie within the bracketed interval.'
stop
elseif (prod == 0d0) then
if (F(xl) == 0d0) then
print*, 'The exact root of the equation is:', xl
else
print*, 'The exact root of the equation is:', xu
endif
print*, 'No iterations performed'
stop
else
i = 1
error = 1d9
tolerance = 1d-5
max_iter = 3
xr = xu - F(xu)*(xl - xu)/(F(xl) - F(xu))
10 if ((error > tolerance).and.(i < max_iter)) then
prod = F(xl) * F(xr)
if (prod < 0d0) then
xu = xr
elseif (prod > 0d0) then
xl = xr
elseif (prod == 0d0) then
print*, 'The root of the equation is:', xr
print*, 'Number of iterations performed:', i
stop
endif
xr_old = xr
xr = xu - F(xu)*(xl - xu)/(F(xl) - F(xu))
error = dabs((xr - xr_old)/xr)*100
i = i + 1
go to 10
endif
endif
*
if (error <= tolerance) then
print*, 'The root of the equation is:', xr
print*, 'Number of iterations performed:', i
else
print*, 'The root is not reached within the error limit after t
$he prescribed number of iteration,', i
endif
*
stop
end
|