Hi everyone!. I’m a newbie in Fortran.

I try to solve the equation

F(x)=a/x if x > 4 and F(x) = (a/b).(3-x^2) if x <= 4

with a,b are constants that I can change any real number

I use bisection method but in this case, I don’t know how to declare the function. Here is my code

program bisec

implicit none

integer, parameter:: n=1000

double precision f,x1,x2,eps

double precision nroots(n)

integer i,nroots

exteral f

x1=0.0

x2=10.0 ! I change this number.

eps=1.0e-7

call bisection(f,x1,x2,eps,n,roots,nroots)

if (nroots==0) then

write(,) ‘no root found’

stop

end if

write(,) ‘roots of equation are’

do i=1,nroots,1

write (,) i, root(i)

end do

end program bisecfunction f

implicit none

double precision f,x

if (x>4.0) then f = a/x

else x <4.0 then f=(a/b)*(3-x**2.0)

end function

subroutine bisection(f,x1,x2,esp,n,roots,nroots)

implicit none

integer, parameter:: n=1000

double precision f,x1,x2,eps,roots(n)

double precision a,b,c,dx,root

integer n,i,j,nroots

interger, parameter::sk =200

dx = (x2-x1)/n

nroots=0

do j =1,n

a=x1+(j-1)*dx

b=a+dx

if (f(a)*f(b))>0) cycle

do i = 1, sk

c=(b+a)/2.0

if (f(c).f(a)<=0) then

b=c

else

a=c

end if

if (abs(a-b)<=eps) exit

end do

root=(a+b)/2.0

if (abs(f(root)<1.0) then

nroots=nroots+1

Roots(nroots)= root

end if

end do

end subroutine bisection

I know I get trouble in declare the funtion, please help me!