1. Homepage
  2. Programming
  3. 4CCP1300 Mathematics and Computation for Physics - Computational Laboratory Assessment

4CCP1300 Mathematics and Computation for Physics - Computational Laboratory Assessment

Engage in a Conversation
UKKCL4CCP1300Mathematics and Computation for PhysicsComputational LaboratoryPython

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 17th 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.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

Problem 1: Molecular conformers

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 and conformer B, and the total number of molecules is fixed, so that nA+nB remains the same. We assume that every hour, 20% of the current population of conformer A will turn into conformer B. However, there is a chance of also transitioning in the other direction, and so each hour, 10% of the molecules in conformer B turn back into conformer A. We assume that initially, there are 150 'A molecules' and 150 'B molecules'. We also assume that the changes in populations take place in discrete time intervals on the hour, each hour. CourseNana.COM

a) We can write the number of A-molecules (nA) and B-molecules (nB) as a vector each hour,  CourseNana.COM

[nAnB].
Furthermore, we can recast the problem of finding the vector from one hour to the next, as a single matrix equation, with a linear system of equations. By acting the initial vector of populations on a 2×2 matrix of fixed probabilities, indicating the proportion of molecules which transition between states or remain in the current state, you should be able to find the vector of populations in the second hour to be nA=135 and nB=165.

CourseNana.COM

Write a code cell below, to initialize a numpy array of the appropriate 2×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). 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 nA=135 and nB=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 A- vs. B-molecules, or does one conformer win out? If it is a 'steady state' (when the populations settle down to a constant over time), then what are these steady populations? Note that the transition probabilities remain the same each hour, so we can use the same probability matrix, 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 (nA+nB) is conserved, and equal to the original number (300, to within reasonable numerical precision). Write out the final number of A and Bmolecules. 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

xn+1=a×xn×(1xn) , CourseNana.COM

where xn is the current variable in the range [0,1], xn+1 is the next value in the sequence, and a is the growth rate which we will consider to be in the range [0,4]. This is often used to model systems which grow under a constraint of a finite number of resources, where e.g. xn represents the fraction of the total possible population size at a particular time. Here, the population will grow according to xn, but be constrained by the (1xn) term when xn gets too large. When xn=0, the population is zero, and when xn=1, the population is at its maximum possible size. Indeed, since the resources are limited, the expansion is also proportional to (1xn) and if the civilization reaches the maximum population of x=1 it will have exhausted all its resources and then collapses to x=0. Note that compared to the problem above, this sequence has non-linear (quadratic) terms in xn, which has a profound affect, especially in the long-time limiting behaviour. As a background to this problem, it may be helpful to watch the following video here. CourseNana.COM

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 x0. It should return the convergence point of the sequence. We assume in this problem that the sequence reaches a converged state after n=100iterations, so that the convergence point x can be approximated by the n=100 element of the sequence (x100). [6 marks] CourseNana.COM

b) We now want to consider how this 'fix point', x, varies for different growth rates, a, and different initial conditions, x0. CourseNana.COM

In the code cell below, loop over 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 possible values for x0 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 in an array (found using the function defined in part a), and make a scatter plot of x against a, for a (on the x-axis) in the range 1.5 to 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 for 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 x (horizontal) and y (vertical) motion. We therefore aim to end up with two arrays for the x-coordinates and y-coordinates for each time step that we consider (as well as another set of arrays for the components of the velocity). Finally, to solve differential equations, we will need to specify an initial condition, i.e. the initial x and y position for the projectile, as well as the initial velocity in each direction. Considering the propagation in the y-direction (the x direction is simple, as there is no acceleration and the velocity is therefore constant), we can write the expression for the propagation of the coupled y-position and y-velocity of the particle as CourseNana.COM

y˙(t+Δt)=y˙(t)Δt×g CourseNana.COM

y(t+Δt)=y(t)+Δt×y˙(t) CourseNana.COM

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.8ms2, and the maximum time to integrate, t_max. Calculate the number of timesteps required simulate this maximum time, and initialize numpy arrays to hold the x- and y- positions and velocities for each time step. It will also be worth initializing variables to store the initial speed, height and angle of the trajectory rather than hard coding them, so that these can be simply changed later on. CourseNana.COM

Initialize the projectile as starting at ground level, and fired at a speed of 100ms1 at an angle of 30 above ground level, choosing dt=0.01seconds. 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 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, Δt is changed, and why. What is the fundamental approximation made in the numerical solution we have implemented? [9 marks] CourseNana.COM

Get in Touch with Our Experts

QQ QQ
Wechat WeChat
Whatsapp Whatsapp
UK代写,KCL代写,4CCP1300代写,Mathematics and Computation for Physics代写,Computational Laboratory代写,Python代写,UK代编,KCL代编,4CCP1300代编,Mathematics and Computation for Physics代编,Computational Laboratory代编,Python代编,UK代考,KCL代考,4CCP1300代考,Mathematics and Computation for Physics代考,Computational Laboratory代考,Python代考,UKhelp,KCLhelp,4CCP1300help,Mathematics and Computation for Physicshelp,Computational Laboratoryhelp,Pythonhelp,UK作业代写,KCL作业代写,4CCP1300作业代写,Mathematics and Computation for Physics作业代写,Computational Laboratory作业代写,Python作业代写,UK编程代写,KCL编程代写,4CCP1300编程代写,Mathematics and Computation for Physics编程代写,Computational Laboratory编程代写,Python编程代写,UKprogramming help,KCLprogramming help,4CCP1300programming help,Mathematics and Computation for Physicsprogramming help,Computational Laboratoryprogramming help,Pythonprogramming help,UKassignment help,KCLassignment help,4CCP1300assignment help,Mathematics and Computation for Physicsassignment help,Computational Laboratoryassignment help,Pythonassignment help,UKsolution,KCLsolution,4CCP1300solution,Mathematics and Computation for Physicssolution,Computational Laboratorysolution,Pythonsolution,