pietrod21

By-Catch Extinction

Mar 28th, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.20 KB | None | 0 0
  1. # PROBLEM 1
  2. #
  3. # There are two species of fish. We want to harvest the species 1, but we have a bycatch of species 2.
  4. # Model logistic growth for both species with the constants and the initial values given below.
  5. # Include harvesting at the harvest_rate given below.
  6. # A fixed fraction p = 0...1 of this harvest will consist of species 2.
  7. # Implement this using the Forward Euler Method.
  8. # Using pencil and paper, determine the threshold value of p for fish 2 not to go extinct.
  9. # Set the variable p to this threshold value when you submit the solution.
  10.  
  11. from udacityplots import *
  12.  
  13. def bycatch():
  14.     maximum_growth_rate_1 = 0.5 # 1 / year
  15.     carrying_capacity_1 = 2.0e6 # tons
  16.     maximum_growth_rate_2 = 0.3 # 1 / year
  17.     carrying_capacity_2 = 1.0e6 # tons    
  18.     harvest_rate = 0.8 * 2.5e5 # rate of catching both kinds of fish, tons / year
  19.    
  20.     # Insert the correct value of p
  21.     p = 0.375 # fraction of bycatch, i.e. fish 2
  22.  
  23.     end_time = 100. # years
  24.     h = 0.1 # years
  25.     num_steps = int(end_time / h)
  26.     times = h * numpy.array(range(num_steps + 1))
  27.  
  28.     fish_1 = numpy.zeros(num_steps + 1) # tons
  29.     fish_1[0] = 1.3e6
  30.     fish_2 = numpy.zeros(num_steps + 1) # tons
  31.     fish_2[0] = 7.5e5
  32.  
  33.     for step in range(num_steps):
  34.         fish_1[step + 1] = fish_1[step]+maximum_growth_rate_1*(1.-fish_1[step]/carrying_capacity_1)*fish_1[step]*h-(1.-p)*harvest_rate*h
  35.         fish_2[step + 1] = fish_2[step]+maximum_growth_rate_2*(1.-fish_2[step]/carrying_capacity_2)*fish_2[step]*h-p*harvest_rate*h
  36.  
  37.  
  38.         if fish_1[step + 1] < 0. or fish_2[step + 1] < 0.:
  39.             break
  40.  
  41.     return step, times, fish_1, fish_2
  42.  
  43. step, times, fish_1, fish_2 = bycatch()
  44.  
  45. @show_plot
  46. def plot_fish():
  47.     fish_1_plot = matplotlib.pyplot.plot(times[:step + 1], fish_1[:step + 1], label='Fish 1')
  48.     fish_2_plot = matplotlib.pyplot.plot(times[:step + 1], fish_2[:step + 1], label = 'Fish 2')
  49.     matplotlib.pyplot.legend(('Fish 1', 'Fish 2'), loc='upper right')
  50.  
  51.     axes = matplotlib.pyplot.gca()
  52.     axes.set_xlabel('Time in years')
  53.     axes.set_ylabel('Amount of fish in tons')
  54.     matplotlib.pyplot.xlim(xmin = 0.)
  55.     matplotlib.pyplot.ylim(ymin = 0.)
  56.     matplotlib.pyplot.show()
  57. plot_fish()
Advertisement
Add Comment
Please, Sign In to add comment