PHAS0007 Computing Final Assignment


Hello, if you have any need, please feel free to consult us, this is my wechat: wx91due


PHAS0007 Computing Final Assignment
2024-25: Simulating Planetary Orbits
Dr Ben Waugh, Dr Rebecca Chislett, Dr Louise Dash
Revision date: December 6, 2024

1 Introduction

You will take the programming skills you have developed throughout the course and use them, combined with your knowledge of classical mechanics, to create

animations of planets orbiting a star.

The assignment is divided into two parts:

• You can ask questions and get advice from us on part A in the sessions in the last week of term. However, the work you submit must be your own, and you must not collaborate with anyone else.
• Part B must be completed independently. You must work on this entirely on your own, without the assistance of other students, course staff or anyone else.

This is an ”open-book” assessment. Although you must complete it without assistance or collaboration, you are free to refer to the course materials, your own work from earlier units, web sites, books and other resources. You may if you wish use AI tools as long as these are available free of charge to anyone.

It is essential that you properly reference any source you use though. See the section below on referencing and academic integrity for further details.

Everything in your submission must be either completely your own work, or have the source explicitly acknowledged and suitably referenced. We will be using several methods to check for similarities between work submitted by different students, and investigating any indications of plagiarism or collusion.

You will submit a single notebook for this assignment, and in order to keep to the size limit for uploaded files, you will need to restart the kernel and clear all output before saving and uploading your work.

2 The physics

2.1 Newton’s law of universal gravitation

Newton’s law of universal gravitation [1] states that the gravitational force between any two objects is proportional to their masses, and inversely proportional to the square of the distance between them:


Figure 1: Illustration of Newton’s law of gravitation. Created by Dennis Nilsson, CC BY 3.0 https://creativecommons.org/licenses/by/3.0, via Wikimedia Commons.


In SI units, the gravitational constant G = 6.674 × 10−11 Nm2kg−2 . This is very small: gravity is a very weak force compared to electromagnetic and
nuclear forces.

Figure 1 illustrates Newton’s law of universal gravitation. A point mass m1 attracts another point mass m2 by a force F2 pointing along the line intersecting both points. In the same way, m2 attracts m1 with an equal force F1 pointing in the opposite direction.

Consider two masses m1 and m2, as shown in the figure. The gravitational force exerted on m2 due to m1 will be

where r21 is the position vector of m2 relative to m1, i.e. r2 − r1

Similarly, the force exerted on m1 due to m2 will be


and clearly F12 = −F21: the forces are equal and opposite, as they should be according to Newton’s third law.

From Newton’s second law, we also have F = ma, so therefore we can see that the accelerations experienced by m1 due to m2 and vice versa will be

These accelerations will not be equal in magnitude unless the objects have equal masses.

2.2 Converting Newton’s laws to a numerical model

Let’s consider a system with two objects: a star with mass M and a planet with mass m. In a solar system like ours M  m and so the acceleration experienced by the star due to the planet will be small compared to the acceleration experienced by the planet due to the star. The gravitational force on the planet due to the star is
 
To keep things simple, we will assume the acceleration on the star due to the planet is small enough that we can neglect it, and put the star in a fixed position at the origin of our co-ordinate system. Thus rmM = rm − rM becomes rm. We’ll drop the now unnecessary subscript on rm, and replace the unit vector rˆ with r/|r|, to give a simpler-looking expression:

We can work out the motion of the planet straight from this, just by using the laws of motion:

In order to calculate the motion of the planet around the star, we need to integrate this differential equation with respect to time, with the initial position and velocity of the planet as boundary conditions. Here we will not do this exactly but use a numerical method to get an approximate result. This approach is particularly useful in cases where it is not possible to find an exact solution, e.g. when we are taking general relativity into account or dealing with more than two bodies. Here we use Euler’s method, as in unit 9. This is the simplest, most naive method and definitely not the most accurate, as you will learn in later computing courses.
We replace the differentials to small finite differences and rewrite the force
as
and then rearrange this to give the change in velocity of the planet in the time

where δv and δt are very small finite quantities. We can define δt (usually known as the timestep) in our code as a parameter. Similarly, we can write the change in the planet’s position over the same δt as
δr = vδt
Given our starting point of the initial position and velocity of the planet, and a fixed timestep δt, we can calculate how r and v change:
We can use these equations to calculate the path of the planet, and create an animation of this, just as we simulated the path of a projectile with air resistance in unit 9.

3 Task instructions

For this assignment you will submit a single notebook including your solution to both parts A and B. You can use the template provided for part A, but will have to add your own code and text cells for the rest of the assignment.

3.1 Part A (40% of marks)

• Download the template notebook provided.
• Complete and edit this template to create your own self-contained note book, completing the tasks described.
• The template includes code cells and functions for you to complete to
– calculate the gravitational force between two objects;
– update the position of the planet in each time step;
– loop over a number of steps to calculate the trajectory of the planet;
– display an animation of a planet orbiting a star.
• You will also need to complete the introduction text cell, and add further code and text cells in the “investigation” section.
• The template also includes some additional code to help you ensure each function is working correctly. You should leave the code in these cells unchanged. You may add your own tests if you wish, but these should be in separate cells.

3.2 Part B

3.2.1 Two non-interacting planets (10% of marks)

• By copying and adapting code from the supplementary notebook, create an animation of two planets orbiting a single star. Use the following parameters:
– mass of star: 2.5 × 1030 kg
– initial position of first planet: (2, 0) × 1011 m
– initial velocity of first planet: (0, 2.89) × 104 m/s
– initial position of second planet: (1.56, 1.56) × 1011 m
– initial velocity of second planet: (−1.95, 1.95) × 104 m/s
• Describe and comment on the behaviour in a text cell.

3.2.2 Two planets with gravitational interactions (35% of marks)

• Create a new function, similar to move planet, but this time updating the positions of two planets and taking into account the gravitational attraction between the planets as well as between each planet and the star.

In addition to the positions and velocities of the two planets, this function will need to take two more arguments to represent the masses of the planets. It will need to return the updated position and velocity of both planets.

Your function should call the force function from part A: you do not need to repeat or change this function.

• Create a new function, similar to trajectory, but this time calculating the trajectories of two planets, using the function you have written in the previous section to update the position and velocity of the planets taking into account the gravitational attraction between the planets.
• Using these functions, and any others you need, create an animation showing the trajectories of two planets with the same starting parameters as those in section 3.2.1, and using a mass of 6 × 1024 kg for each planet.
• Create another animation showing the trajectories of two planets with the same starting parameters, but this time increasing the mass of the second planet by a factor of 100.

3.2.3 Further investigation (15% of marks)

Extend your notebook to simulate some further scenarios and investigate the resulting behaviour. Add a few relevant animations and text cells to describe and explain what you observe, along with a conclusion. There are many aspects of orbits you could look into, but you should pick one or two to investigate in detail. Some ideas that you could consider, of varying levels of difficulty, are:
• vary the masses of the star and planets;
• vary the starting positions and velocities of the planets;
• calculate the required velocity to achieve a stable circular orbit with a given radius, and see how close or how massive the planets have to be to have a significant effect on each other’s orbits;
• turn one of the planets into a moon orbiting the other, by careful choice of masses and initial conditions;
• simulate a solar system with more than two planets;
• use a different procedure to calculate the trajectories, instead of Euler’s method.

4 Strategies and hints

You are recommended to break each problem down into small steps. It is easier to get a small, simple piece of code working and then build on it than to write a larger section in one go and then have to debug it. In part A we have helped by splitting the overall task into three functions for you to complete one at a time. In part B it is up to you how you manage the process.

Make sure you explain all choices you make in your implementation, especially in the comments. If you use an unusual coding approach, you must explain it clearly in the comments, and state why you have chosen this approach, otherwise you may not receive full credit for it. You must also ensure that if you reuse or repurpose any code from another source (including your own coursework submissions) you include a reference to this in both the comments and the bibliography.

As usual, you are recommended to comment your code as you go along, as this forms an essential part of the debugging procedure. You may also find it useful to enable line numbering in your code cells (press ESC-L in a code cell).

Before you submit your code, make sure that you have tested it fully.

You are strongly advised not to attempt to complete this assignment in a single coding session. Plan your working time sensibly to allow enough time for completion before the published deadline.

5 Assessment

Everything in your submission must be either completely your own work, or have the source explicitly acknowledged and suitably referenced. We will be using several methods to check for any plagiarised or copied assignments.

5.1 Referencing and academic integrity

All the information given about referencing and academic integrity in the instructions for the mid-term assignment is also valid here, and you should consult those notes.

As noted there, we permit but do not recommend the use of AI tools in an assistive role, but you may only use tools that are available free of charge to everyone. For the sake of fairness, we do not allow the use of tools that require payment to use.

5.2 Use of Python modules

You may import and use functions from the libraries we have used in the course, namely NumPy, SciPy and Matplotlib. Do not import or use other libraries. If your code relies on libraries that our markers do not have installed, we may be unable to mark part or all of your work, and you will lose marks.

5.3 Anonymity

As for the mid-term assignment, this assignment will be graded anonymously.
Please ensure that
• your name does not appear anywhere in your submission;
• if you need to include a reference to one of your own submissions in your notebook, you should replace your name with your student number in the

reference.

It is your responsibility to ensure that you submit the correct file. After uploading your notebook, you should download it again and run the downloaded version right through to ensure it works as expected.

Your work will be graded using a mark scheme based on the following as sessment criteria:

• whether your calculations are correct;
• the quality of your code, including structure, layout, style, and comments;
• the quality and presentation of your notebook including referencing, dis cussion, and any conclusions you have drawn from your results;
• the appearance of your animations;

• any improvements or extensions that are relevant to the task but go be yond what is required (up to 5%).

Remember that this is a formal assignment: your document should be clearly laid out in sections, with complete, grammatically correct sentences and paragraphs rather than bullet point lists.

You must a bibliography, as for the mid-term assignment, referencing sources using the approach documented in the section ”Referencing in PHAS0007 - how to avoid plagiarism” on the PHAS0007 Hub page (https://moodle.ucl. ac.uk/course/view.php?id=39139#section-7). As a minimum, this should include a reference to this script, but you should also include any and all external sources you referred to in order to complete this assignment.

References
[1] Wikipedia contributors. Newton’s law of universal gravitation — Wikipedia, The Free Encyclopedia; 2023. [Online; accessed 7-December- 2023]. https://en.wikipedia.org/w/index.php?title=Newton%27s_law_of_universal_gravitation&oldid=1188388630.

发表评论

电子邮件地址不会被公开。 必填项已用*标注