!===========================================================
! Bifurcation Diagram of the Logistic Map
!===========================================================
program bifurcation_diagram
 implicit none
 integer ,parameter :: dp     = 8
 real(dp),parameter :: rmin   = 2.5_dp
 real(dp),parameter :: rmax   = 4.0_dp
 integer ,parameter :: NTRANS = 500   !Number of discarted steps
 integer ,parameter :: NSTEPS = 100   !Number of recorded  steps
 integer ,parameter :: RSTEPS = 2000  !Number of values of r 
 integer            :: i              
 real(dp)           :: r,dr,x0,x1
 real(dp),parameter :: ZERO = 0.0_dp, ONE = 1.0_dp, HALF = 0.5_dp
! ----- Initialize:
 open(unit=33,file='bif.dat')
 dr     = (rmax-rmin)/RSTEPS !Increment in r
! ----- Calculate:
 r = rmin
 do while ( r <= rmax)
  x0 = HALF
! ---- Transient steps: skip
  do i=1,NTRANS
   x1 = r * x0 * (ONE-x0)
   x0 = x1
  enddo
  do i=1,NSTEPS
   x1 = r * x0 * (ONE-x0)
   write(33,*) r,x1
   x0 = x1
  enddo
  r = r + dr
 enddo ! do while
 close(33)
end program bifurcation_diagram
!  ---------------------------------------------------------------------
!  Copyright by Konstantinos N. Anagnostopoulos (2004-2022)
!  Physics Dept., National Technical University,
!  konstant@mail.ntua.gr, www.physics.ntua.gr/~konstant
!  
!  This program is free software: you can redistribute it and/or modify
!  it under the terms of the GNU General Public License as published by
!  the Free Software Foundation, version 3 of the License.
!  
!  This program is distributed in the hope that it will be useful, but
!  WITHOUT ANY WARRANTY; without even the implied warranty of
!  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
!  General Public License for more details.
!  
!  You should have received a copy of the GNU General Public Liense along
!  with this program.  If not, see <http://www.gnu.org/licenses/>.
!  -----------------------------------------------------------------------
