User Tools

Site Tools


2016:groups:g1:start

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
2016:groups:g1:start [2016/01/09 23:22] group12016:groups:g1:start [2024/01/09 18:45] (current) – external edit 127.0.0.1
Line 2: Line 2:
 ====== Less is more: when positives don't sum ====== ====== Less is more: when positives don't sum ======
  
 +==== Plot 1 ====
 +
 +%matplotlib inline
 +from numpy import *
 +from matplotlib.pyplot import *
 +from scipy.integrate import odeint
 +ion()
 +
 +t = arange(0,2., 0.01)
 +
 +# parameters
 +fr = 8.75
 +fa = 6.25
 +p = 0.7
 +c = 0.01
 +g = 0.001
 +
 +# initial condition: this is an array now!
 +x0 = array([10., 10.]) # Pr, Pa
 +
 +# the function still receives only `x`, but it will be an array, not a number
 +def LV(x, t, fr, fa, p, c, g):
 +    # in python, arrays are numbered from 0, so the first element 
 +    # is x[0], the second is x[1]. The square brackets `[ ]` define a
 +    # list, that is converted to an array using the function `array()`.
 +    # Notice that the first entry corresponds to dV/dt and the second to dP/dt
 +    return array([ (fr*p*x[0]) + fa*p*x[1] - ((c-g)*x[0]*(x[0]+x[1])),
 +                   (fa*(1-p)*x[1]) + fr*(1-p)*x[0] - ((c-3*g)*x[1]*(x[0]+x[1])) ])
 +
 +# call the function that performs the integration
 +# the order of the arguments is as below: the derivative function,
 +# the initial condition, the points where we want the solution, and
 +# a list of parameters
 +x = odeint(LV, x0, t, (fr, fa, p, c, g))
 +
 +# plot the solution
 +plot(t, x)
 +xlabel('$t [years^{-1}]$', fontsize=25) # define label of x-axis
 +ylabel('$Plants Population$', fontsize=25) # and of y-axis
 +legend(['$P_{r}$', '$P_{a}$'], loc='lower right', fontsize=20)
 +savefig('foo1.pdf')
 ==== Portuguesa ==== ==== Portuguesa ====
 t = arange(0,3., 0.01) t = arange(0,3., 0.01)
2016/groups/g1/start.1452381768.txt.gz · Last modified: 2024/01/09 18:45 (external edit)