Hello, I was told to find the root of an integrand with using the bisection method. I am kind of new to such a stuff so I am kind of confused why I am not getting the expected result.(adsbygoogle = window.adsbygoogle || []).push({});

Here is my bisection code:

And also there is necessary to explain what other things mean. Eps is the approximation; tl and tup are values of an interval where the root is placed in. S is the value of total_calka for the "tl" temperature value. The total_calka statement is a value which I am getting inside subroutine integration2. And here is the code for that.Code (Fortran):tl=3.0

tup=4.0

tempred=0.0

s=-0.234726128709272990292

do while (abs(total_calka) > eps)

tempred=(tl+tup)/2.0

beta=4.0/tempred

if (total_calka * s < 0) then

tup=tempred

else

tl=tempred

endif

call integration2

end do

There is also a function inte()Code (Fortran):module int2

use variables;

use fx; use int1

implicit none

contains

subroutine integration2

open(1,file='calka.dat', access='append')

total_calka=0.0

division=0.5

tot_old=10000.0

blad=10000.0

do while (blad>error)

irange=int(intrange/division)

total_calka=-(0.5**3)/3.0

do j=1,irange

r1=0.5+(j-1)*division

r2=r1+division

calka=0.0

do i=1,ngauss

integrand(i)=inte(x(i),beta,r2,r1)

calka=calka+integrand(i)*w(i)

enddo

total_calka=total_calka+calka*(r2-r1)

enddo

write(*,*) irange,division,tot_old,total_calka

division=division/2.0

blad=abs(tot_old-total_calka)

tot_old=total_calka

write(*,*) blad

enddo

write(1,*)tempred,-2*pi*total_calka

close(1)

end subroutine integration2

end module int2

I don't know why it's not getting me a value of the root, while when I was doing a simple loop for temperature interval 0.1<T<5.0 I was getting the values of every total_calka for each temperature. I would be grateful for any hints that are helpful.Code (Text):module fx

implicit none

contains

real(10) function inte(y,beta,r2,r1)

real(kind=10)::r,beta,r6,r2,r1,u,y

r=(r2-r1)*y+r1

r6=(1.0/r)**6

u=beta*r6*(r6-1.0d0)

if (u>100.d0) then

inte=-1.0d0

else

inte=exp(-u)-1.d0

endif

inte=r*r*inte

end function inte

end module fx

**Physics Forums | Science Articles, Homework Help, Discussion**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Fortran Bisection formula fortran90/95

**Physics Forums | Science Articles, Homework Help, Discussion**