Advertisement
rric

limited_growth

Apr 18th, 2024 (edited)
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.52 KB | None | 0 0
  1. # Computes and plots a sequence y[n] which grows from an initial value
  2. # y[0] towards a boundary value G, depending on the growth factor q
  3. # Copyright 2024 Roland Richter                          [Mu: Python 3]
  4.  
  5. import matplotlib.pyplot as plt
  6.  
  7. G = 5000
  8. q = 0.19
  9. n_generations = 50
  10.  
  11. y = n_generations * ['?']
  12.  
  13. y[0] = 75.0
  14.  
  15. for n in range(n_generations-1):
  16.     y[n+1] = y[n] + q * (G - y[n])  # limited growth
  17.     # y[n+1] = y[n] + q/G * y[n] * (G - y[n])   # logistic growth
  18.  
  19. # print(y)
  20.  
  21. # Define the x and y coordinates of the points
  22. x = [k for k in range(n_generations)]
  23.  
  24. # Create a new plot
  25. plt.figure()
  26.  
  27. # Plot the points using the 'o' symbol
  28. plt.plot(x, y, 'o')
  29.  
  30. # Set the title and labels for the x and y axes
  31. plt.title('Growth')
  32. plt.xlabel('time')
  33. plt.ylabel('n')
  34.  
  35. # Show the plot
  36. plt.show()
  37.  
  38. # ----------------------------------------------------------------------
  39. # This program is free software: you can redistribute it and/or modify
  40. # it under the terms of the GNU General Public License as published by
  41. # the Free Software Foundation, either version 3 of the License, or
  42. # (at your option) any later version.
  43. #
  44. # This program is distributed in the hope that it will be useful,
  45. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  46. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  47. # GNU General Public License for more details.
  48. #
  49. # You should have received a copy of the GNU General Public License
  50. # along with this program.  If not, see <https://www.gnu.org/licenses/>.
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement