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 17Files
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.COM
This 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 P
, and the vector of current pop
, which should be initialized to 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 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 (
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
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
b) We now want to consider how this 'fix point',
In the code cell below, loop over a_init
and a_final
. This means that a=a_init
for the first cycle of your for
loop, and a = a_final
for the last cycle. For each value of numpy.random
module. Store all of the values for
c) Repeat the code of b) below, but now make a scatter plot of
d) Discuss the results obtained in a Markdown cell. For which values of
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.8
mst_max
. Calculate the number of timesteps required simulate this maximum time, and initialize numpy arrays to hold the
Initialize the projectile as starting at ground level, and fired at a speed of 100msdt=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). [10 marks]
CourseNana.COM
b) In the code cell below, copy the code from part a) and plot the trajectory as
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,