program bisection
real::a,b,c
print*,'Enter two initial guess values:-'
read(*,*)a,b
if(abs(f(a))<0.00001)then
print*,'The root is =',a
elseif(abs(f(b))<0.00001)then
print*,'The root is =',b
elseif(f(a)*f(b)< 0.00001)then
1 c=(a+b)/2
if(f(a)*f(c)<0.00001) then
b=c
else
a=c
endif
if(abs(f(c))>0.00001) then
go to 1
else
print*,'The root is =',c
endif
else
print*,'Change the initial guess.'
endif
end
!define your function below
function f(x)
real::x
f=x*x*x+2*x*x-5*x-6
return
end function
real::a,b,c
print*,'Enter two initial guess values:-'
read(*,*)a,b
if(abs(f(a))<0.00001)then
print*,'The root is =',a
elseif(abs(f(b))<0.00001)then
print*,'The root is =',b
elseif(f(a)*f(b)< 0.00001)then
1 c=(a+b)/2
if(f(a)*f(c)<0.00001) then
b=c
else
a=c
endif
if(abs(f(c))>0.00001) then
go to 1
else
print*,'The root is =',c
endif
else
print*,'Change the initial guess.'
endif
end
!define your function below
function f(x)
real::x
f=x*x*x+2*x*x-5*x-6
return
end function
Comments
Post a Comment