I need helping getting this done
{"nbformat":4,"nbformat_minor":0,"metadata":{"celltoolbar":"Create Assignment","kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.6.5"},"colab":{"name":"BIO3360 - A5 - A gentle introduction to dynamical systems.ipynb","provenance":[],"collapsed_sections":[]}},"cells":[{"cell_type":"markdown","metadata":{"id":"azBq0cQsXisD"},"source":["Identify yourself here:\n","\n","Student name: #################\n","\n","Student number: ##################"]},{"cell_type":"markdown","metadata":{"nbgrader":{"grade":false,"grade_id":"cell-184155173660d840","locked":true,"schema_version":1,"solution":false},"id":"Ty6Uk00PuBWV"},"source":["# BIO3360 Assignment 5#\n","\n","## A gentle introduction to dynamical systems ##\n","\n","The purpose of this assignment is to use principles of dynamical systems theory to analyze systems of ODEs used in computational biology. We will here revisit concepts such as fixed points, nullclines and stability, and support the solutions numerically to validate and explore them systematically. \n","\n","IMPORTANT REMINDER: Copy-pasting code found online will be considered as plagiarism. And this is easy to verify (trust me!). \n","\n","Below is a series of questions that need to be answered. Your \"answers\" are to be written in the code cells below the question statements. To get points, the output of your code cell must match the expected answer. If you need to anotate your code cell, or make comments use `#` before your comment. The line will be ignored by the compiler, but remain visible. E.g. `#this is a comment`\n","\n","**Word of caution: Colab's compiler keep track of assignments, even if they are in different code cells. This means that if you make changes to a variable in a cell, it will impact how this variable is used in all other cells. To avoid mixing them up, you can either change your variable names in every code cell, or redefine them at the value you want at the beginning of every new code cell. Note that this hold not only for variables but also functions, libraries etc that were defined in a previous code cell. As mentioned before, that works because all required information is stored in memory. It is critical that you remain aware of the implications of this...especially when you having been working on an assignment, or other code, for a long time!**\n","\n","First, please write your name and student number in the text cell above."]},{"cell_type":"markdown","metadata":{"id":"vveXsevqiYYl"},"source":["##Question 1 (1 points)\n","\n","Consider the exponential growth model with birth and death rates $a>0$ and $b>0$\n","\n","$$\\frac{dX}{dt} =(a-b)X$$\n","\n","a) (0.5 point) What is the fixed point of this equation? `#type your answer as a commentary in the code cell below`.\n","\n","b) (0.5 point) On which condition on $a$ and $b$ does the equation above converges to the fixed point? And diverges? In each case, write whether the fixed point is stable or unstable. (HINT: You can either solve the equation analytically, or use numerical methods to explore its dynamics)`#type your answer as a commentary in the code cell below`."]},{"cell_type":"code","metadata":{"id":"F9Hvu27xF70i"},"source":[""],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"i4M2ZZFNfLSG"},"source":["###Question 2 (4 points)\n","\n","Consider the following population growth model\n","\n","$$\\frac{dX}{dt} = X(a-X^2)$$\n","\n","a) (1 point) How many fixed point does the model has? Find those fixed points. `#type your answer as a commentary in the code cell below`.\n","\n","b) (1 point) What happens when $a<0$? `#type your answer as a commentary in the code cell below`.\n","\n","c) (1 point) using the euler method, plot the evolution of x as a function of time, over the interval ranging from 0 to a 100, with $dt=0.01$ and a=1. first, consider the initial condition $x(0)=0.1$, and then $x(0)=-0.1$. where does the solution converges to in each case? `#type your answer as a commentary in the code cell below`.\n","\n","d) (1 point) use the initial condition $x(0)=0.1$. at $t=50$, perturb the solution $x(t)$ and apply the perturbation $i=-1.01/dt$ (only once and at that precise value of t). what happens? describe the behavior of the solution. (hint: you should use here an `if` conditional statement and your euler integration line should read `x[t+1] = x[t]+dt*(x[t]*(a-x[t]**2)+i)` )\n"]},{"cell_type":"code","metadata":{"id":"mauxsnxagun_"},"source":[""],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"9boss_xg6ci2"},"source":["###question 3 (5 points)\n","\n","consider the following two dimensional predator prey system based on the lotka volterra equations (what is different here? do you notice something familiar?)\n","\n","$$\\frac{dn}{dt} = r n (1-n) - np$$\n","\n","$$\\frac{dp}{dt} = a n - p $$\n","\n","where, again, $n$ and $p$ correspond to the populations of prey and predators, respectively. this competition model is non linear, and perhaps is it a bit challenging to see its properties simply by looking at the equations. \n","\n","a) (1 point) what sort of interaction is this model describing? what sort of dynamics can we expect to see? `#type your answer as a commentary in the code cell below`.\n","\n","b) (1 point) what are the fixed points for this system?`#type your answer as a commentary in the code cell below`.\n","\n","c) (1 point) compute the nullclines of the equation above. plot those nullclines in $(n,p)$ phase space for $(a,r)=(1,1)$ (reminder: the nullclines should intersect at the fixed points found in b)). `#type your answer as a commentary in the code cell below`.\n","\n","d) (1 point) using the euler method and what we have seen in class and in previous assignments, plot the evolution of the variables $n$ and $p$ as a function of time for $(a,r)=(1,1)$ for initial conditions :\n","\n","$n(0)=0$ ;\n","$p(0)=0.4$\n","\n","and \n","\n","$n(0)=0.1$ ; \n","$p(0)=0.4$.\n","\n","towards which fixed point does the system converge in each case? \n","\n","e) (1 point) plot the flow in phase space.(hint: as seen in class, all is needed is to integrate the system for a small amount of time, say 0.1 with steps of $dt=0.01$. using two embedded `for` loops, you can simply change the initial conditions and plot the trajectories in $(n,p)$ space iteratively. )"]},{"cell_type":"code","metadata":{"id":"jymqbrjglcl2"},"source":[""],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"dow5q4xpubwu"},"source":[""],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"byny-dnkmife"},"source":[""],"execution_count":null,"outputs":[]}]} `#type="" your="" answer="" as="" a="" commentary="" in="" the="" code="" cell="" below`.\n","\n","c)="" (1="" point)="" using="" the="" euler="" method,="" plot="" the="" evolution="" of="" x="" as="" a="" function="" of="" time,="" over="" the="" interval="" ranging="" from="" 0="" to="" a="" 100,="" with="" $dt="0.01$" and="" a="1." first,="" consider="" the="" initial="" condition="" $x(0)="0.1$," and="" then="" $x(0)="-0.1$." where="" does="" the="" solution="" converges="" to="" in="" each="" case?="" `#type="" your="" answer="" as="" a="" commentary="" in="" the="" code="" cell="" below`.\n","\n","d)="" (1="" point)="" use="" the="" initial="" condition="" $x(0)="0.1$." at="" $t="50$," perturb="" the="" solution="" $x(t)$="" and="" apply="" the="" perturbation="" $i="-1.01/dt$" (only="" once="" and="" at="" that="" precise="" value="" of="" t).="" what="" happens?="" describe="" the="" behavior="" of="" the="" solution.="" (hint:="" you="" should="" use="" here="" an="" `if`="" conditional="" statement="" and="" your="" euler="" integration="" line="" should="" read="" `x[t+1]="X[t]+dt*(X[t]*(a-X[t]**2)+I)`" )\n"]},{"cell_type":"code","metadata":{"id":"mauxsnxagun_"},"source":[""],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"9boss_xg6ci2"},"source":["###question="" 3="" (5="" points)\n","\n","consider="" the="" following="" two="" dimensional="" predator="" prey="" system="" based="" on="" the="" lotka="" volterra="" equations="" (what="" is="" different="" here?="" do="" you="" notice="" something="" familiar?)\n","\n","$$\\frac{dn}{dt}="r" n="" (1-n)="" -="" np$$\n","\n","$$\\frac{dp}{dt}="a" n="" -="" p="" $$\n","\n","where,="" again,="" $n$="" and="" $p$="" correspond="" to="" the="" populations="" of="" prey="" and="" predators,="" respectively.="" this="" competition="" model="" is="" non="" linear,="" and="" perhaps="" is="" it="" a="" bit="" challenging="" to="" see="" its="" properties="" simply="" by="" looking="" at="" the="" equations.="" \n","\n","a)="" (1="" point)="" what="" sort="" of="" interaction="" is="" this="" model="" describing?="" what="" sort="" of="" dynamics="" can="" we="" expect="" to="" see?="" `#type="" your="" answer="" as="" a="" commentary="" in="" the="" code="" cell="" below`.\n","\n","b)="" (1="" point)="" what="" are="" the="" fixed="" points="" for="" this="" system?`#type="" your="" answer="" as="" a="" commentary="" in="" the="" code="" cell="" below`.\n","\n","c)="" (1="" point)="" compute="" the="" nullclines="" of="" the="" equation="" above.="" plot="" those="" nullclines="" in="" $(n,p)$="" phase="" space="" for="" $(a,r)="(1,1)$" (reminder:="" the="" nullclines="" should="" intersect="" at="" the="" fixed="" points="" found="" in="" b)).="" `#type="" your="" answer="" as="" a="" commentary="" in="" the="" code="" cell="" below`.\n","\n","d)="" (1="" point)="" using="" the="" euler="" method="" and="" what="" we="" have="" seen="" in="" class="" and="" in="" previous="" assignments,="" plot="" the="" evolution="" of="" the="" variables="" $n$="" and="" $p$="" as="" a="" function="" of="" time="" for="" $(a,r)="(1,1)$" for="" initial="" conditions="" :\n","\n","$n(0)="0$" ;\n","$p(0)="0.4$\n","\n","and" \n","\n","$n(0)="0.1$" ;="" \n","$p(0)="0.4$.\n","\n","Towards" which="" fixed="" point="" does="" the="" system="" converge="" in="" each="" case?="" \n","\n","e)="" (1="" point)="" plot="" the="" flow="" in="" phase="" space.(hint:="" as="" seen="" in="" class,="" all="" is="" needed="" is="" to="" integrate="" the="" system="" for="" a="" small="" amount="" of="" time,="" say="" 0.1="" with="" steps="" of="" $dt="0.01$." using="" two="" embedded="" `for`="" loops,="" you="" can="" simply="" change="" the="" initial="" conditions="" and="" plot="" the="" trajectories="" in="" $(n,p)$="" space="" iteratively.="">0$? `#type your answer as a commentary in the code cell below`.\n","\n","c) (1 point) using the euler method, plot the evolution of x as a function of time, over the interval ranging from 0 to a 100, with $dt=0.01$ and a=1. first, consider the initial condition $x(0)=0.1$, and then $x(0)=-0.1$. where does the solution converges to in each case? `#type your answer as a commentary in the code cell below`.\n","\n","d) (1 point) use the initial condition $x(0)=0.1$. at $t=50$, perturb the solution $x(t)$ and apply the perturbation $i=-1.01/dt$ (only once and at that precise value of t). what happens? describe the behavior of the solution. (hint: you should use here an `if` conditional statement and your euler integration line should read `x[t+1] = x[t]+dt*(x[t]*(a-x[t]**2)+i)` )\n"]},{"cell_type":"code","metadata":{"id":"mauxsnxagun_"},"source":[""],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"9boss_xg6ci2"},"source":["###question 3 (5 points)\n","\n","consider the following two dimensional predator prey system based on the lotka volterra equations (what is different here? do you notice something familiar?)\n","\n","$$\\frac{dn}{dt} = r n (1-n) - np$$\n","\n","$$\\frac{dp}{dt} = a n - p $$\n","\n","where, again, $n$ and $p$ correspond to the populations of prey and predators, respectively. this competition model is non linear, and perhaps is it a bit challenging to see its properties simply by looking at the equations. \n","\n","a) (1 point) what sort of interaction is this model describing? what sort of dynamics can we expect to see? `#type your answer as a commentary in the code cell below`.\n","\n","b) (1 point) what are the fixed points for this system?`#type your answer as a commentary in the code cell below`.\n","\n","c) (1 point) compute the nullclines of the equation above. plot those nullclines in $(n,p)$ phase space for $(a,r)=(1,1)$ (reminder: the nullclines should intersect at the fixed points found in b)). `#type your answer as a commentary in the code cell below`.\n","\n","d) (1 point) using the euler method and what we have seen in class and in previous assignments, plot the evolution of the variables $n$ and $p$ as a function of time for $(a,r)=(1,1)$ for initial conditions :\n","\n","$n(0)=0$ ;\n","$p(0)=0.4$\n","\n","and \n","\n","$n(0)=0.1$ ; \n","$p(0)=0.4$.\n","\n","towards which fixed point does the system converge in each case? \n","\n","e) (1 point) plot the flow in phase space.(hint: as seen in class, all is needed is to integrate the system for a small amount of time, say 0.1 with steps of $dt=0.01$. using two embedded `for` loops, you can simply change the initial conditions and plot the trajectories in $(n,p)$ space iteratively. )"]},{"cell_type":"code","metadata":{"id":"jymqbrjglcl2"},"source":[""],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"dow5q4xpubwu"},"source":[""],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"byny-dnkmife"},"source":[""],"execution_count":null,"outputs":[]}]}>