{"id":166,"date":"2019-01-09T00:31:44","date_gmt":"2019-01-09T08:31:44","guid":{"rendered":"http:\/\/gantovnik.com\/bio-tips\/?p=166"},"modified":"2019-01-09T00:31:44","modified_gmt":"2019-01-09T08:31:44","slug":"lotka-volterra-equations-for-predator-pray-populations","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/lotka-volterra-equations-for-predator-pray-populations\/","title":{"rendered":"Lotka-Volterra equations for predator\/pray populations"},"content":{"rendered":"<pre>import os\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy import integrate\nos.chdir(r'D:\\projects\\wordpress\\ex34')\nos.getcwd()\na, b, c, d = 0.4, 0.002, 0.001, 0.7\ndef f(xy, t):\nx, y = xy\n    return [a * x - b * x * y, c * x * y - d * y]\n\nxy0 = [600, 400]\nt = np.linspace(0, 50, 250)\nxy_t = integrate.odeint(f, xy0, t)\nxy_t.shape\nfig, axes = plt.subplots(1, 2, figsize=(8, 4))\naxes[0].plot(t, xy_t[:,0], 'r', label=\"Prey\")\naxes[0].plot(t, xy_t[:,1], 'b', label=\"Predator\")\naxes[0].set_xlabel(\"Time\")\naxes[0].set_ylabel(\"Number of animals\")\naxes[0].legend()\naxes[1].plot(xy_t[:,0], xy_t[:,1], 'k')\naxes[1].set_xlabel(\"Number of prey\")\naxes[1].set_ylabel(\"Number of predators\")\nfig.tight_layout()\nplt.savefig(\"example34.png\", dpi=100)\nplt.show()\nplt.close()\n\n<img data-recalc-dims=\"1\" decoding=\"async\" class=\"  wp-image-167 aligncenter\" src=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example34.png?resize=600%2C300\" alt=\"example34\" width=\"600\" height=\"300\" srcset=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example34.png?w=800&amp;ssl=1 800w, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example34.png?resize=300%2C150&amp;ssl=1 300w, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example34.png?resize=768%2C384&amp;ssl=1 768w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>import os import numpy as np import matplotlib.pyplot as plt from scipy import integrate os.chdir(r&#8217;D:\\projects\\wordpress\\ex34&#8242;) os.getcwd() a, b, c, d = 0.4, 0.002, 0.001, 0.7 def f(xy, t): x, y = xy return [a * x &#8211; b * x * y, c * x * y &#8211; d * y] xy0 = [600, 400] [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","_lmt_disableupdate":"yes","_lmt_disable":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-166","post","type-post","status-publish","format-standard","hentry","category-python"],"modified_by":null,"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8bH0k-2G","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":136,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/multivariate-interpolation\/","url_meta":{"origin":166,"position":0},"title":"Multivariate interpolation","author":"gantovnik","date":"2019-01-04","format":false,"excerpt":"import os import matplotlib.pyplot as plt import numpy as np from scipy import interpolate os.chdir(r'D:\\data\\scripts\\web1\\ex28') os.getcwd() x = y = np.linspace(-2, 2, 20) def f(x, y): return np.exp(-(x + .5)**2 - 2*(y + .5)**2) - np.exp(-(x - .5)**2 - 2*(y - .5)**2) X, Y = np.meshgrid(x, y) # simulate noisy\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example28","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example28.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example28.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example28.png?resize=525%2C300 1.5x"},"classes":[]},{"id":232,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/regression\/","url_meta":{"origin":166,"position":1},"title":"#47 Regression","author":"gantovnik","date":"2019-01-13","format":false,"excerpt":"","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example47_2.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example47_2.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example47_2.png?resize=525%2C300 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example47_2.png?resize=700%2C400 2x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example47_2.png?resize=1050%2C600 3x"},"classes":[]},{"id":85,"url":"https:\/\/gantovnik.com\/bio-tips\/2018\/12\/subplots-in-matplotlib\/","url_meta":{"origin":166,"position":2},"title":"#13 Subplots in matplotlib","author":"gantovnik","date":"2018-12-29","format":false,"excerpt":"","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example13","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example13.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example13.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example13.png?resize=525%2C300 1.5x"},"classes":[]},{"id":93,"url":"https:\/\/gantovnik.com\/bio-tips\/2018\/12\/plots-of-nonlinear-functions\/","url_meta":{"origin":166,"position":3},"title":"Plots of nonlinear functions","author":"gantovnik","date":"2018-12-31","format":false,"excerpt":"import os import matplotlib.pyplot as plt import numpy as np os.chdir('\/home\/vg\/Downloads\/projects\/ex15') os.getcwd() #define model parameters x=np.linspace(-2,2,1000) #examples of nonlinear functions f1=x**2-x-1 f2=x**3-3*np.sin(x) f3=np.exp(x)-2 f4=1-x**2+np.sin(50\/(1+x**2)) fig,axes=plt.subplots(1,4,figsize=(12,3),sharey=True) for n,f in enumerate([f1,f2,f3,f4]): axes[n].plot(x,f,lw=1.5) axes[n].axhline(0,ls=':',color='k') axes[n].set_ylim(-5,5) axes[n].set_xticks([-2,-1,0,1,2]) axes[n].set_xlabel(r'$x$',fontsize=18) axes[0].set_ylabel(r'$f(x)$',fontsize=18) titles=[r'$f(x)=x^2-x-1$',r'$f(x)=x^3-3\\sin(x)$',r'$f(x)=\\exp(x)-2$', r'$f(x)=\\sin\\left(50\/(1+x^2)\\right)+1-x^2$'] for n,title in enumerate(titles): axes[n].set_title(title) plt.savefig(\"example15.png\", dpi=100) plt.show() plt.close()","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example15","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example15.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example15.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example15.png?resize=525%2C300 1.5x"},"classes":[]},{"id":243,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/classification\/","url_meta":{"origin":166,"position":4},"title":"#48 Classification","author":"gantovnik","date":"2019-01-13","format":false,"excerpt":"\u00a0","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example48","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example48.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example48.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example48.png?resize=525%2C300 1.5x"},"classes":[]},{"id":139,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/multidimensional-spline\/","url_meta":{"origin":166,"position":5},"title":"Multidimensional Spline","author":"gantovnik","date":"2019-01-04","format":false,"excerpt":"import os import matplotlib.pyplot as plt import numpy as np from scipy import interpolate os.chdir(r'D:\\data\\scripts\\web1\\ex29') os.getcwd() np.random.seed(115925231) x = y = np.linspace(-1, 1, 100) X, Y = np.meshgrid(x, y) def f(x, y): return np.exp(-x**2 - y**2) * np.cos(4*x) * np.sin(6*y) Z = f(X, Y) N = 500 xdata = np.random.uniform(-1,\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example29","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example29.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example29.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example29.png?resize=525%2C300 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/166","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/comments?post=166"}],"version-history":[{"count":0,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/166\/revisions"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}