# Computational Laboratory 4CCP1300 Assessment

#### Assessment information

In this jupyter notebook, you will find the guidelines and questions to be completed for the assignment for the computational modeling course. The assignment is due by **17 ?ℎ${}^{th}$ March 2023 at 12:00 (noon) GMT**, and must be submitted via Turnitin on KEATS. This means that you must download this completed jupyter notebook from CoCalc, save it locally, and then submit it via KEATS. You can download your completed jupyter notebook from CoCalc once completed via the

`Files`

tab, and then clicking on the 'cloud' download button on the right hand side. Remember that submitting at the last moment might put you at risk of unexpected events (failing internet connection or other problems), so plan your time, and aim to submit well BEFORE the deadline. A section on KEATS will be opened soon to allow for your online submissions there. Please note that the completed jupyter notebooks should be submitted directly (this file ending .ipynb), rather than a pdf or text document, so that the code can be run by the markers and checked for accuracy of the code. Submitted work will be checked for similarity of the submitted notebooks to other students - plagiarism will not be tolerated. Note that the basic similarity measure on TurnItIn will be high, due to the same questions in each notebook, and will just be used as a guide, so don't worry if this crude measure is high.
CourseNana.COMThis document will provide a set of three problems that you will need to solve by using the knowledge built up from the notebooks and exercises completed during the course. You can revisit previous notebooks to refresh your knowledge from the course. The various parts of the problems should be submitted in separate code cells under each subsection of the questions. These cells should generate the results, and will build on the work of previous cells. Furthermore, text cells should be included with discussion and more information about each question where required. Note that the code itself (Python cells) will be marked, so please follow good coding practices outlined in the lectures (appropriate comments in the code, and clean, consistent and well structured code, with output appropriately formatted for readability). Note that all cells should execute properly without error messages given, such that when you go in the menu to `'Kernel'`

then `'Restart & Run All'`

, all the appropriate output from the code cells will be generated for marking each of the questions. Finally, please fill out your name, k-number and email address below, as this is how your marks will be returned to you. Good Luck!
CourseNana.COM

A molecular conformer is a particular shape or atomic arrangement that a molecule can adopt. Often molecules will flip between these two arrangements of their atoms. The aim in this problem is to model the changes in the numbers of molecules in different shapes (conformers) over a period of time. CourseNana.COM

We assume that there are two conformers of a particular molecule which we want to model, conformer

a) We can write the number of

**Write a code cell below, to initialize a numpy array of the appropriate 2×2$2\times 2$ matrix of probabilities assigned to the variable P, and the vector of current ?$A$ and ?$B$ populations, assigned to the variable pop, which should be initialized to (150,150)$(150,150)$. Calculate the matrix multiplication of P and the vector pop (use the numpy module to help), and therefore print out what the population of each type is after one hour (which should be ??=135${n}_{A}=135$ and ??=165${n}_{B}=165$). Finally, have the code test whether the matrix P is a symmetric matrix or not, and print out a statement about this.** [8 marks]
CourseNana.COM

b) We are particularly interested in what happens after a long time - are there a steady number of `P`

, and use it to update the populations many times.
CourseNana.COM

**Set up a loop in the code cell below, to find out what the populations are 72 hours after the initial condition. Each iteration, also check that the total number of molecules ( ??+??${n}_{A}+{n}_{B}$) is conserved, and equal to the original number (300, to within reasonable numerical precision). Write out the final number of ?−$A-$ and ?−$B-$molecules. Is this a stable number, or does it change after another day?** [6 marks]
CourseNana.COM

c) This long-time 'steady-state' behaviour can calculated directly, since we know that any vector where the application of a matrix results only in only a scaling of this vector (leaving the relative magnitudes of the elements of the vector unchanged) must be an eigenvector of the matrix. Specifically, if the populations are steady and not growing overall, the eigenvalue corresponding to this eigenvector must also be equal to 1. (Check the definition of an eigenvector to make sure you are happy with this logic). CourseNana.COM

**In the code cell below, diagonalize the matrix P, and find the eigenvector corresponding to the eigenvalue equal to 1. Note that this eigenvector is not normalized corresponding to the initial conditions we set (i.e. that the total population is 300 at every time). Find and print out the factor that the eigenvector should be multiplied by, in order to ensure that the long-time steady state populations of ?$A$- and ?$B$-molecules matches the values obtained in part c). This number should be printed out to 4 decimal places.**
CourseNana.COM

Note that you should use the `numpy`

or `scipy`

modules in order to do this diagonalization, though it may be worth checking that your code is doing what it should by comparing to a pen-and-paper diagonalization of the matrix. [6 marks]
CourseNana.COM

## Problem 2: The logistic map

In this problem we are considering the logistic map, a very simple sequence with very non-trivial behaviour. It simply updates a (scalar) variable, such that its next value depends solely on its current value. The sequence has the following form: CourseNana.COM

where

a) **Write a function called find_fix_point in the code cell below, which takes as its arguments, the growth rate ?$a$, and an initial value for ?0${x}_{0}$. It should return the convergence point of the sequence. We assume in this problem that the sequence reaches a converged state after ?=100$n=100$iterations, so that the convergence point ?∗${x}^{\ast}$ can be approximated by the ?=100$n=100$ element of the sequence (?100${x}_{100}$).** [6 marks]
CourseNana.COM

b) We now want to consider how this 'fix point',

**In the code cell below, loop over 1000$1000$ uniformly spaced growth rates in the interval between a_init and a_final. This means that a=a_initfor the first cycle of your for loop, and a = a_final for the last cycle. For each value of ?$a$, we also want to loop over 50$50$ possible values for ?0${x}_{0}$ in the range [0,1]. However rather than these taken to be uniformly spaced, these initial conditions should be chosen at random, using the numpy.random module. Store all of the values for ?∗${x}^{\ast}$ in an array (found using the function defined in part a), and make a scatter plot of ?∗${x}^{\ast}$ against ?$a$, for ?$a$ (on the x-axis) in the range 1.5$1.5$ to 4$4$, with each point represented by a small black point. Be sure to always label your axes!** [9 marks]
CourseNana.COM

c) **Repeat the code of b) below, but now make a scatter plot of ?∗${x}^{\ast}$ for 1000$1000$ equally-spaced values of ?$a$ in the interval [3,4], and a final plot for ?$a$ in the interval [3.5,3.8].** [2 mark]
CourseNana.COM

d) **Discuss the results obtained in a Markdown cell. For which values of ?$a$ do you obtain more than one fix point? Discuss the observed trend as ?$a$ is increased, and the consequence of the accumulation of fix points for the stability of a growing population. Why are the long-time trends of this sequence so different to the previous question.** [2 marks]
CourseNana.COM

## Problem 3: Projectile motion

One of the big challenges in mathematical physics is the solution to differential equations, such as Newtons equations. In this problem, we aim to simulate the motion of a projectile under the force of gravity. While simple 'free' projectiles like this can be solved analytically (with the 'constant acceleration' equations), we are going to instead use the Euler method to numerically integrate these equations in time to follow the trajectory of the projectile, and so these analytic constant acceleration equations should *not* be used.
CourseNana.COM

In order to do this, we note that we can decouple the

With these two equations, we can predict the position and velocity of the particle at the next time point, from knowledge of the position and velocity at the previous time point. CourseNana.COM

a) **Initialise variables denoting the timestep for the integration, dt, the acceleration due to gravity, g=9.8ms**
CourseNana.COM

**Initialize the projectile as starting at ground level, and fired at a speed of 100ms −1${}^{-1}$ at an angle of 30∘${}^{\circ}$ above ground level, choosing ** [10 marks]
CourseNana.COM

`dt=0.01`

seconds. Print out the maximum height above ground level that the projectile reaches, the maximum distance the projectile travels in the x-direction before it hits the ground, and the time that the projectile travels (Note that while these values can be obtained analytically from constant acceleration equations, they should instead be found from the simulated dynamics of the Euler propagation).b) **In the code cell below, copy the code from part a) and plot the trajectory as ?$x$- against ?$y$-position for the projectile until it reaches the ground. Include axes labels.** [3 marks]
CourseNana.COM

c) The total energy of the projectile at each point in time can be calculated as the sum of its kinetic and potential energy. Find the energy of the projectile (assuming a mass of 10kg) at each point in time in another array, and create a labelled plot of it as a function of time. CourseNana.COM

**In a text/markdown cell underneath, discuss what this plot is showing, and discuss what it should look like for the exact propagation of the projectile. Describe how the plot changes as the timestep, Δ?$\mathrm{\Delta}t$ is changed, and why. What is the fundamental approximation made in the numerical solution we have implemented?** [9 marks]
CourseNana.COM