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/07 16:59] – 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 32: | Line 82: | ||
*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:// | ||
+ | |||
+ | =====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 | ||
+ | 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(t/5) + 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([' | ||
+ | </ | ||
+ | |||
+ | =====El Pato ===== | ||
+ | < | ||
+ | %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([' | ||
+ | </ | ||
+ | ) | ||
+ | ===== 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 ===== | ===== Code ===== | ||
< | < | ||
+ | %matplotlib inline | ||
from numpy import * | from numpy import * | ||
from matplotlib.pyplot import * | from matplotlib.pyplot import * | ||
from scipy.integrate import odeint | from scipy.integrate import odeint | ||
+ | ion() | ||
- | t = arange(0, | + | t = arange(0,10., 0.01) |
# parameters | # parameters | ||
- | r = 2. | + | fr = 1.5 |
- | c = 0.5 | + | fa = 2. |
- | e = 0.1 | + | p = 0.6 |
- | d = 1. | + | c = 0.2 |
+ | g = 15. | ||
# initial condition: this is an array now! | # initial condition: this is an array now! | ||
- | x0 = array([1., 3.]) | + | x0 = array([50., 50.]) # Pr, Pa |
# the function still receives only `x`, but it will be an array, not a number | # the function still receives only `x`, but it will be an array, not a number | ||
- | def LV(x, t, r, c, e, d): | + | def LV(x, t, fr, fa, p, c, g): |
- | return array([ | + | # in python, arrays are numbered from 0, so the first element |
- | e * c * x[0] * x[1] - d * x[1] ]) | + | # 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([ | ||
+ | (fa*(1-p)*x[1]) + fr*(1-p)*x[0] - ((c/(3*g))*x[1]*(x[0]+x[1])) ]) | ||
- | x = odeint(LV, x0, t, (r, c, e, d)) | + | # 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 the solution | ||
Line 62: | Line 351: | ||
xlabel(' | xlabel(' | ||
ylabel(' | ylabel(' | ||
- | legend([' | + | legend([' |
</ | </ |
2016/groups/g1/start.1452185957.txt.gz · Last modified: 2024/01/09 18:45 (external edit)