Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Computes and plots a sequence y[n] which grows from an initial value
- # y[0] towards a boundary value G, depending on the growth factor q
- # Copyright 2024 Roland Richter [Mu: Python 3]
- import matplotlib.pyplot as plt
- G = 5000
- q = 0.19
- n_generations = 50
- y = n_generations * ['?']
- y[0] = 75.0
- for n in range(n_generations-1):
- y[n+1] = y[n] + q * (G - y[n]) # limited growth
- # y[n+1] = y[n] + q/G * y[n] * (G - y[n]) # logistic growth
- # print(y)
- # Define the x and y coordinates of the points
- x = [k for k in range(n_generations)]
- # Create a new plot
- plt.figure()
- # Plot the points using the 'o' symbol
- plt.plot(x, y, 'o')
- # Set the title and labels for the x and y axes
- plt.title('Growth')
- plt.xlabel('time')
- plt.ylabel('n')
- # Show the plot
- plt.show()
- # ----------------------------------------------------------------------
- # 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, either version 3 of the License, or
- # (at your option) any later version.
- #
- # 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 License
- # along with this program. If not, see <https://www.gnu.org/licenses/>.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement