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 23:22] – 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 ==== | ==== Portuguesa ==== | ||
t = arange(0, | t = arange(0, |
2016/groups/g1/start.1452381768.txt.gz · Last modified: 2024/01/09 18:45 (external edit)