2016:groups:g1:start
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
2016:groups:g1:start [2016/01/09 16:35] – [El Pato] group1 | 2016: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, | ||
+ | |||
+ | # 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])), | ||
+ | | ||
+ | |||
+ | # 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(' | ||
+ | ylabel(' | ||
+ | legend([' | ||
+ | savefig(' | ||
+ | ==== Portuguesa ==== | ||
+ | t = arange(0, | ||
+ | rFec = t = arange(0, | ||
+ | rGam = arange(0, | ||
+ | |||
+ | for i in range(len(rFec)): | ||
+ | for j in range(len(rGam)): | ||
+ | x = odeint(LV, x0, t, (fr, fa, p, c, g, i, j)) | ||
+ | A[i,j] = x[5, | ||
Wiki site of the practical exercise of the [[http:// | Wiki site of the practical exercise of the [[http:// | ||
Line 33: | Line 83: | ||
*Godschalx //et al.// (2015) //Ants are less attracted to the extrafloral nectar of plants with symbiotic, nitrogen-fixing rhizobia// Ecology 96(2), pp.348-354 [[http:// | *Godschalx //et al.// (2015) //Ants are less attracted to the extrafloral nectar of plants with symbiotic, nitrogen-fixing rhizobia// Ecology 96(2), pp.348-354 [[http:// | ||
- | ==== Killing the Ants at t = 25 ==== | + | =====Maria Bonita===== |
+ | < | ||
+ | %matplotlib inline | ||
+ | from numpy import * | ||
+ | from matplotlib.pyplot import * | ||
+ | from scipy.integrate import odeint | ||
+ | ion() | ||
+ | |||
+ | t = arange(0, | ||
+ | |||
+ | # parameters | ||
+ | rv = 0.8 | ||
+ | rr = 1.5 | ||
+ | ra = 0.6 | ||
+ | kv = 5. | ||
+ | kr = 5. | ||
+ | ka = 5. | ||
+ | a = 0.15 | ||
+ | b = 0.03 | ||
+ | c = 0.15 | ||
+ | d = 0.02 | ||
+ | n = 0.1 | ||
+ | p = 1 | ||
+ | alfa = 0.25 | ||
+ | beta = 0.25 | ||
+ | |||
+ | # initial condition | ||
+ | x0 = array([1., 1., 1.]) # V, R, A | ||
+ | |||
+ | def LV(x, t, rv, rr, ra, kv, kr, ka, a, b, c, d, p, n, alfa, beta): | ||
+ | return array([ rv*x[0]*(1-(x[0]/ | ||
+ | | ||
+ | | ||
+ | |||
+ | # 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, (rv, rr, ra, kv, kr, ka, a, b, c, d, p, n, alfa, beta)) | ||
+ | |||
+ | # plot the solution | ||
+ | plot(t, x) | ||
+ | xlabel(' | ||
+ | ylabel(' | ||
+ | legend([' | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | =====Right First Model===== | ||
+ | < | ||
+ | %matplotlib inline | ||
+ | from numpy import * | ||
+ | from matplotlib.pyplot import * | ||
+ | from scipy.integrate import odeint | ||
+ | ion() | ||
+ | |||
+ | t = arange(0, | ||
+ | |||
+ | # parameters | ||
+ | fr = 8.75 | ||
+ | fa = 6.25 | ||
+ | c = 0.01 | ||
+ | p = 0.5 | ||
+ | g = 0.001 | ||
+ | |||
+ | # initial condition | ||
+ | x0 = array([50., 50.]) # Pr, Pa | ||
+ | |||
+ | 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 | ||
+ | if t > 25.: | ||
+ | g = 0. | ||
+ | p = 0.25 * sin(6*t) + 0.5 | ||
+ | return array([ (fr*p*x[0]) + fa*p*x[1] - ((c-g)*x[0]*(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(' | ||
+ | ylabel(' | ||
+ | legend([' | ||
+ | </ | ||
+ | |||
+ | |||
+ | =====Killing the Ants at t = 25===== | ||
< | < | ||
%matplotlib inline | %matplotlib inline | ||
Line 118: | Line 262: | ||
legend([' | legend([' | ||
</ | </ | ||
- | )===== Code ===== | + | ) |
+ | ===== Patolihno ===== | ||
+ | %matplotlib inline | ||
+ | from numpy import * | ||
+ | from matplotlib.pyplot import * | ||
+ | from scipy.integrate import odeint | ||
+ | ion() | ||
+ | |||
+ | t = arange(0, | ||
+ | |||
+ | # parameters | ||
+ | rv = 0.8 | ||
+ | rr = 1.5 | ||
+ | ra = 0.6 | ||
+ | rp = 0.2 | ||
+ | kv = 5. | ||
+ | kr = 5. | ||
+ | ka = 5. | ||
+ | kp = 4. | ||
+ | a = 1.5 | ||
+ | b = 3. | ||
+ | c = 1.5 | ||
+ | d = 2. | ||
+ | e = 2. | ||
+ | n = 0.6 | ||
+ | alfa = 2.5 | ||
+ | beta = 2.5 | ||
+ | |||
+ | # initial condition | ||
+ | x0 = array([10., 40., 8.,8.]) # V, R, A, P | ||
+ | |||
+ | def LV(x, t, rv, rr, ra, rp, kv, kr, ka, kp, a, b, c, d, e, n, alfa, beta): | ||
+ | return array([ rv*x[0]*(1-(x[0]/ | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | # 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, (rv, rr, ra, rp, kv, kr, ka, kp, a, b, c, d, e, n, alfa, beta)) | ||
+ | |||
+ | # plot the solution | ||
+ | plot(t, x) | ||
+ | xlabel(' | ||
+ | ylabel(' | ||
+ | legend([' | ||
+ | |||
+ | ===== Code ===== | ||
< | < | ||
2016/groups/g1/start.1452357326.txt.gz · Last modified: 2024/01/09 18:45 (external edit)