!===========================================================
!Discrete Logistic Map:
!Liapunov exponent from sum_i ln|f'(x_i)|
! ntrans: number of discarted iteration in order to discart
!         transient behaviour
! nsteps: number of terms in the sum
!===========================================================
program logistic_map
 implicit none
 integer , parameter :: dp = 8
 integer             :: ntrans,nsteps,i
 real(dp)            :: r,x0,x1,sum
 real(dp), parameter :: ONE=1.0_dp,TWO=2.0_dp

! ----- Input:      
 print *,'# Enter ntrans, nsteps, r, x0:'
 read  *,         ntrans, nsteps, r, x0
 print *,'# ntrans  = ',ntrans
 print *,'# nsteps  = ',nsteps
 print *,'# r       = ',r
 print *,'# x0      = ',x0

 do i = 1,ntrans
  x1  = r   * x0        * (ONE -       x0)
  x0  = x1
 enddo
 sum  =       log(abs(r * (ONE - TWO * x0)))
! ----- Initialize:
 open(unit=33,file='lia.dat')
 write(33,*) 1,x0,sum
! ----- Calculate:
 do i = 2,nsteps
  x1  = r   * x0        * (ONE -       x0)
  sum = sum + log(abs(r * (ONE - TWO * x1)))
  write(33,*)i,x1,sum/i
  x0  = x1
 enddo
 close(33)
end program logistic_map
!  ---------------------------------------------------------------------
!  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/>.
!  -----------------------------------------------------------------------
