├── LICENSE
├── README.md
├── how-far-can-we-throw a ball on jupiter"
├── how far can we throw a ball on jupiter.ipynb
└── readme.md
├── particle-physcis'
├── README.md
├── plotting a trajectory of a particle.ipynb
└── projectile example.py
└── solar-system"
├── IMG_20200831_123930.jpg
├── Readme.md
├── Screenshot (32).png
├── rotaional-motion-of-planets"
├── Screenshot (31).png
├── rotaional-motion-of-planets.css
└── rotaional-motion-of-planets.html
├── solar-system-from-2010-2020.css
├── solar-system-from-2010-2020.html
├── solar-system-from-2010-2020.js
├── solar-system.css
└── solar-system.html
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Aman Anand
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # coding-for--physics
2 |
3 | ## 📌 Introduction
4 |
5 | In todays world full of computing and technology, scientists utilise the vast power available to them to help accelerate their research.
6 | Programming is extremely important in almost every area of physics. Not every physicist has to be an expert programmer, but many are, and virtually all physicists are at least competent programmers.
7 | In most experiments, the process of data analysis is complex enough to require some programming. More importantly, in many situations, the best (or only) way of telling whether your results are consistent with any given model is to simulate the experiment.so its a collection of codes simulating real world phenomenons or performing computation and much more .This is a place to find or add any new script that can make learning physics much easier and more efficient for you, as a Developer,it's our goal to make solve real world problems by coding .
8 |
9 |
10 |
11 |
12 | ## 📌 Here’s Why You Should Be Coding In Your Physics Course
13 |
14 | like data science, Physics too involves a lot of data analysis. They deal with nuclear data from detectors and astronomical data from telescopes to perform all sorts of analysis and studies needed. So they too need to upskill themselves with programming, at least with the very basic languages useful to them for analysis like Matlab and Python.
15 | If there is someone in this background of Physics who does not know programming, he is really lagging a big time in his field. Even if they think that they know the theory and practical behind their subject of interest, programming does come in handy to for a number of reasons.
16 |
17 | ## 💥 How to Contribute?
18 |
19 | [](http://makeapullrequest.com)
20 | [](https://github.com/ellerbrock/open-source-badges/)
21 |
22 | - Take a look at the Existing issues or create your own Issues!
23 | - Wait for the Issue to be assigned to you after which you can start working on it.
24 | - Fork the Repo and create a Branch for any Issue that you are working upon.
25 | - Create a Pull Request which will be promptly reviewed and suggestions would be added to improve it.
26 | - Add Screenshots to help us know what this Script is all about.
27 |
28 | ## 💻 Languages used in this project
29 |
30 | [](https://pypi.python.org/pypi/ansicolortags/)
31 | [](https://GitHub.com/Naereen/)
32 | [](https://forthebadge.com)
33 |
34 |
35 | ## ❤️ Project Admin
36 |
37 | |
38 | **[Aman Anand]**
39 |
--------------------------------------------------------------------------------
/how-far-can-we-throw a ball on jupiter"/how far can we throw a ball on jupiter.ipynb:
--------------------------------------------------------------------------------
1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"how far can we throw a ball on jupiter","provenance":[{"file_id":"11jjjglbOXUWUBeZBASd0itUkIcL6rME_","timestamp":1598859562901}],"private_outputs":true},"kernelspec":{"name":"python3","display_name":"Python 3"}},"cells":[{"cell_type":"markdown","metadata":{"id":"C0l9uRQg8QiE","colab_type":"text"},"source":["# HOW FAR CAN WE THROW A BALL ON JUPITER?"]},{"cell_type":"markdown","metadata":{"id":"NuYyp0f5vV9a","colab_type":"text"},"source":["# - Acceleration due to Gravity on other planets\n","\n"," You can use the internet to get values for the masses and radii of the planets, be careful about units! equations will expect meters and kilograms...\n","\n","Here, I want to use a loop to work out 'g' for each planet using its mass and radius and plot the trajectories at a fixed angle. \n","\n","I will start off with the values Earth\n"]},{"cell_type":"code","metadata":{"id":"b8T7nkS8ux6N","colab_type":"code","cellView":"both","colab":{}},"source":["# EDIT THIS ONE...\n","import numpy as np\n","\n","# planet mass in kg\n","# planet radius in m\n","# you can use the 'e' notation: a*(10^b) == a e b\n","masses = np.array(5.972e24, ???, ???, ???)\n","radii = np.array(6.371e6, ???, ???, ???)\n","G = 6.674e-11\n","names =('Earth', ???, ???, ???)\n","\n","g = (-G * masses / (radii**2))\n","\n","for i in len(???):\n"," print ('Acceleration due to gravity at the surface of {a} is {b} m/s^2'.format(a=names[?], b=g[?]))"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"0AwbA9fP6-a7","colab_type":"text"},"source":["I've copied the above cell so you can edit your code without breaking the original above:"]},{"cell_type":"code","metadata":{"id":"0h-52BQj7HFj","colab_type":"code","colab":{}},"source":["# KEEP THIS ONE AS BACKUP IN CASE YOU NEED IT!\n","import numpy as np\n","\n","# planet mass in kg\n","# planet radius in m\n","# you can just use the 'e' notation: a*(10**b) == a e b\n","\n","masses = np.array(5.972e24)\n","radii = np.array(6.371e6)\n","G = 6.674e-11\n","names = ['Earth']\n","\n","g = (-G * masses / (radii**2))\n","\n","\n","print ('Acceleration due to gravity at the surface of {a} is {b} m/s^2'.format(a=names, b=g))"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"5N-jtb7eyppU","colab_type":"text"},"source":["Hopefully, when you run your print statement, you have a list of values like this (feel free to add more planets if you like, or make up your own):\n","\n",""]},{"cell_type":"markdown","metadata":{"id":"gjWuhpl24FIv","colab_type":"text"},"source":["# - Plotting trajectories on different planets\n","\n","Now I want to plot a projectile launced at *45* degrees on each of the planets. \n","\n","Be careful when using the values of g , make sure you use the right sign in the right place."]},{"cell_type":"code","metadata":{"id":"bzxfTx4a6ArN","colab_type":"code","colab":{}},"source":["# EDIT THIS ONE...\n","# I'm assuming you've already executed the previous cell...\n","\n","import matplotlib.pyplot as plt\n","\n","v_i = 100 \n","a_x = 0\n","\n","angle = 60\n","\n","\n","# lets loop through each of your planets and pick g at each point, as opposed to 'angles[i]\n","for i in range(len(names)):\n"," \n"," # get the timestamps for each projectile:\n"," t_max = 2 * v_i * np.sin(np.deg2rad(angle)) / -g\n"," t_step = 0.01\n"," timestamps = np.arange(0, t_max, t_step)\n"," \n"," # we then work out the x/y coordinates of our projectile at each timestamp for that angle\n"," x = v_i * timestamps * np.cos(np.deg2rad(angle)) + (0.5 * a_x * timestamps ** 2)\n"," y = v_i * timestamps * np.sin(np.deg2rad(angle)) + (0.5 * g * timestamps ** 2)\n"," \n"," plt.plot(x, y, label = names[i])\n","\n","plt.show()"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"Z-woGRRpiA20","colab_type":"text"},"source":["Below is a copy of the code, use it to practice your answer and leave the cell above so you have something to reference."]},{"cell_type":"code","metadata":{"id":"8YBnZkV6h4PQ","colab_type":"code","colab":{}},"source":["# KEEP THIS ONE AS BACKUP INCASE YOU NEED IT!\n","# I'm assuming you've already executed the previous cell...\n","\n","import matplotlib.pyplot as plt\n","\n","v_i = 100 \n","a_x = 0\n","\n","angle = 60\n","\n","\n","# lets loop through each of your planets and pick g at each point, as opposed to 'angles[i]\n","for i in range(len(names)):\n"," \n"," # get the timestamps for each projectile:\n"," t_max = 2 * v_i * np.sin(np.deg2rad(angle)) / -g\n"," t_step = 0.01\n"," timestamps = np.arange(0, t_max, t_step)\n"," \n"," # we then work out the x/y coordinates of our projectile at each timestamp for that angle\n"," x = v_i * timestamps * np.cos(np.deg2rad(angle)) + (0.5 * a_x * timestamps ** 2)\n"," y = v_i * timestamps * np.sin(np.deg2rad(angle)) + (0.5 * g * timestamps ** 2)\n"," \n"," plt.plot(x, y, label = names[i])\n","\n","plt.show()"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"s6zcUhrUns8K","colab_type":"text"},"source":["Using the four planets I showed above, your plot should look something like this:\n","\n",""]},{"cell_type":"markdown","metadata":{"id":"JaQ0oYLQmxgp","colab_type":"text"},"source":["# - Let's get real\n","\n","So by now we're plotting trajectories of objects on different planets, but our starting velocity has always been 100m/s, is that realistic?\n","\n","Well, according to [Wikipedia](https://en.wikipedia.org/wiki/Aroldis_Chapman), the fastest Baseball pitch ever recorded was 169 km/hr, or 46.9 m/s, under half our initial condition!\n","\n","It's probably safe to assume that the average human couldn't throw a ball faster than half of this, so let's place our initial velocity at 20 m/s.\n","\n","\n","\n","For a) all i need to change the initial velocity, But for part b) we need to save the maximum distance during the plotting loop and use the formatted print statements to see what the answers are:"]},{"cell_type":"code","metadata":{"id":"HOsQFHfnmzRr","colab_type":"code","colab":{}},"source":["# EDIT THIS ONE!\n","# put something like this *outside* your plot loop from Q2\n","\n","max_distance = ???\n","\n","# Put something like this *inside* your plot loop:\n","\n","max_distance.append(x[???])\n","\n","# Then something like this after the plt.show() command, or in a separate cell underneath:\n","\n","for i in range(len(???)):\n"," print ('Projectile launched from planet {a} reached {b} meters'.format(a=names[???], b=(max_distance[???])))"],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"kp1ygDJInvjq","colab_type":"code","colab":{}},"source":["# KEEP THIS ONE AS BACKUP INCASE YOU NEED IT!\n","# put something like this *outside* your plot loop from Q2\n","\n","max_distance = ???\n","\n","# Put something like this *inside* your plot loop:\n","\n","max_distance.append(x[???])\n","\n","# Then something like this after the plt.show() command, or in a separate cell underneath:\n","\n","for i in range(len(???)):\n"," print ('Projectile launched from planet {a} reached {b} meters'.format(a=names[???], b=(max_distance[???])))"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"IRXNTIQuor0L","colab_type":"text"},"source":["In this case you'll need to replace the '???' to something sensible. Here are the target results:\n","\n",""]},{"cell_type":"markdown","metadata":{"id":"D_wbu7kdqyoC","colab_type":"text"},"source":["# Q4 - Why are we doing this?\n","\n","You might be wondering why anyone would bother doing this, when we already know the equations of motion and could easily have worked out these results by hand in just a few seconds...\n","\n","Well, you could imagine that our primitave projectile model can become much more complicated if we started to increase the 'realism' of our simulation. We could add:\n","\n","* Air resistance\n","* Bouncing\n","* Additional forces at launch\n","* 2D or even 3D force vectors\n","* Multiple projectiles\n","* A complex surface for the projectile to encounter\n","* Projectiles that aren't point particles, e.g. something that has a shape\n","* Material properties of the projectile/bouncing etc\n","\n","And before you know it, we could be simulating:\n","\n","* A multistage rocket en-route to Mars\n","* An explosive gas reaching thousands of degrees\n","* Complex astrophysics of objects falling into black holes\n","\n","In every single case, a vast majority of the code will be made of the simple building blocks For anyone aiming to study: Physics, Astronomy, Engineering, Biology, Chemistry, Materials Science, Geography, Psychology or any other science at a graduate level, a basic understanding of programming with a Physics mindset will vastly improve your ability to model and understand your system.\n","\n","we also use programming to *analyse* data where we don't fully know the physics. Instead of using the laws of kinematics to plot trajectories, we might be *given* some noisy trajectories and be asked to figure out the initial conditions. I imagine NASA and Spacex do this for every single launch so that their rockets can be better and more efficient with each successful launch. Even in the ones that fail, it is critical to understand why.\n"]},{"cell_type":"markdown","metadata":{"id":"6XRHqGbc1Yp8","colab_type":"text"},"source":["# Answers:\n","\n","Hopefully you haven't just scrolled down until you found this....\n","\n","**Q1** Printing various accelerations due to gravity:\n"]},{"cell_type":"code","metadata":{"id":"l-urs0m01kUe","colab_type":"code","colab":{}},"source":["import numpy as np\n","\n","# planet mass in kg\n","# planet radius in m\n","# you can just use the 'e' notation: a*(10**b) == a e b\n","\n","masses = np.array((3.285e23, 5.972e24, 6.39e23, 1.898e27))\n","radii = np.array((2.440e6, 6.371e6, 3.390e6, 69.911e6))\n","G = 6.674e-11\n","names = ['Mercury', 'Earth', 'Mars', 'Jupiter']\n","\n","g = (-G * masses / (radii**2))\n","\n","for i in range(len(masses)):\n"," print ('Acceleration due to gravity at the surface of {a} is {b} m/s^2'.format(a=names[i], b=g[i]))"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"uX_hE_E74Tnw","colab_type":"text"},"source":["**Q2** Plotting various trajectories on different planets:"]},{"cell_type":"code","metadata":{"id":"nu3LXzVF1tic","colab_type":"code","colab":{}},"source":["import matplotlib.pyplot as plt\n","\n","v_i = 100 \n","a_x = 0\n","\n","angle = 45\n","\n","\n","# lets loop through each of those angle values and work out the trajectory\n","for i in range(len(masses)):\n"," \n"," # each projectile gets a unique set of timestamps, so that each one is sampled 100 times\n"," t_max = 2 * v_i * np.sin(np.deg2rad(angle)) / -g[i]\n"," t_step = 0.01\n"," timestamps = np.arange(0, t_max, t_step)\n"," \n"," # we then work out the x/y coordinates of our projectile at each timestamp for that angle\n"," x = v_i * timestamps * np.cos(np.deg2rad(angle)) + (0.5 * a_x * timestamps ** 2)\n"," y = v_i * timestamps * np.sin(np.deg2rad(angle)) + (0.5 * g[i] * timestamps ** 2)\n"," \n"," #print (t_max)\n"," # add that data to the plot, give it a label\n"," plt.plot(x, y, label = names[i])\n","\n","\n","plt.legend()\n","plt.xlabel('Distance / m')\n","plt.ylabel('Height / m')\n","plt.title('The trajectory of a particle launched on various planets')\n","plt.show()"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"_UgmtR1Lnz0i","colab_type":"text"},"source":["**Q3**. Plotting a realistic trajectory and printing the maximum distance on each planet."]},{"cell_type":"code","metadata":{"id":"tb7cywbE4szB","colab_type":"code","colab":{}},"source":["import matplotlib.pyplot as plt\n","\n","v_i = 20 \n","a_x = 0\n","\n","angle = 45\n","\n","max_distance = []\n","\n","\n","# lets loop through each of those angle values and work out the trajectory\n","for i in range(len(masses)):\n"," \n"," # each projectile gets a unique set of timestamps, so that each one is sampled 100 times\n"," t_max = 2 * v_i * np.sin(np.deg2rad(angle)) / -g[i]\n"," t_step = 0.01\n"," timestamps = np.arange(0, t_max, t_step)\n"," \n"," # we then work out the x/y coordinates of our projectile at each timestamp for that angle\n"," x = v_i * timestamps * np.cos(np.deg2rad(angle)) + (0.5 * a_x * timestamps ** 2)\n"," y = v_i * timestamps * np.sin(np.deg2rad(angle)) + (0.5 * g[i] * timestamps ** 2)\n"," \n"," max_distance.append(x[-1])\n"," \n"," #print (t_max)\n"," # add that data to the plot, give it a label\n"," plt.plot(x, y, label = names[i])\n","\n","\n","plt.legend()\n","plt.xlabel('Distance / m')\n","plt.ylabel('Height / m')\n","plt.title('The trajectory of a particle launched on various planets')\n","plt.show()\n","\n","for i in range(len(names)):\n"," print ('Projectile launched from planet {a} reached {b} meters'.format(a=names[i], b=(np.round(max_distance[i],2))))"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"y16mEvqwqcmG","colab_type":"text"},"source":["So it turns out that if you can throw a ball at 20 m/s on Earth, that same ball would hit the 'surface' of Jupiter in just 15m! Equally, you'd easily launch it over 100m on Mercury!"]}]}
--------------------------------------------------------------------------------
/how-far-can-we-throw a ball on jupiter"/readme.md:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/particle-physcis'/README.md:
--------------------------------------------------------------------------------
1 | # in this code i have tried to simulate a projectile launched at an angle and how to plot the trajectory along with working out how far the projectile reached
2 | [](https://forthebadge.com)
3 | [](https://forthebadge.com)
4 | [](https://forthebadge.com)
5 | [](https://forthebadge.com)
6 | [](https://forthebadge.com)
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/particle-physcis'/plotting a trajectory of a particle.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "colab_type": "text",
7 | "id": "mug_MpPEExpa"
8 | },
9 | "source": [
10 | "# Plotting a trajectory of a particle\n",
11 | "\n",
12 | "\n",
13 | "\n",
14 | "[Here](http://hyperphysics.phy-astr.gsu.edu/hbase/mot.html) is a link to the Hyperphysics section of kinematics, we will be coding up these equations.\n",
15 | "\n",
16 | "[Here](https://www.khanacademy.org/science/physics/one-dimensional-motion/kinematic-formulas/a/what-are-the-kinematic-formulas) is a link to the derivation of those equations, also worth a read to brush up on your kinematics.\n",
17 | "\n"
18 | ]
19 | },
20 | {
21 | "cell_type": "markdown",
22 | "metadata": {
23 | "colab_type": "text",
24 | "id": "Ve9a2hazbIU7"
25 | },
26 | "source": [
27 | "First, we will import the two libraries we used earlier, Numpy and Matplotlib. These will let us do some basic maths, and set up our plot. "
28 | ]
29 | },
30 | {
31 | "cell_type": "code",
32 | "execution_count": null,
33 | "metadata": {
34 | "colab": {},
35 | "colab_type": "code",
36 | "id": "h2ucdCa8D3J0"
37 | },
38 | "outputs": [],
39 | "source": [
40 | "import numpy as np\n",
41 | "import matplotlib.pyplot as plt"
42 | ]
43 | },
44 | {
45 | "cell_type": "markdown",
46 | "metadata": {
47 | "colab_type": "text",
48 | "id": "pBPGb_4GbtuP"
49 | },
50 | "source": [
51 | "We will then set up some initial parameters. We are going to simulate a projectile launched from the ground at an angle and plot the trajectory. \n",
52 | "\n",
53 | "We will define everything in separate 'x' and 'y' dimensions, and simply sum the results.\n",
54 | "\n",
55 | "Firstly, we define the acceleration due to gravity in the x and y direction in units of m/s^2:"
56 | ]
57 | },
58 | {
59 | "cell_type": "code",
60 | "execution_count": null,
61 | "metadata": {
62 | "colab": {},
63 | "colab_type": "code",
64 | "id": "0ig0QMObcTyM"
65 | },
66 | "outputs": [],
67 | "source": [
68 | "a_x = 0\n",
69 | "a_y = -9.81 # note the sign of acceleration is downwards"
70 | ]
71 | },
72 | {
73 | "cell_type": "markdown",
74 | "metadata": {
75 | "colab_type": "text",
76 | "id": "e0pxp-TDcmOS"
77 | },
78 | "source": [
79 | "Now we will choose an initial velocity in m/s, and an angle we want to launch the projectile from in degrees:"
80 | ]
81 | },
82 | {
83 | "cell_type": "code",
84 | "execution_count": null,
85 | "metadata": {
86 | "colab": {},
87 | "colab_type": "code",
88 | "id": "gm7fXlrecueD"
89 | },
90 | "outputs": [],
91 | "source": [
92 | "v_i = 100\n",
93 | "angle = 60"
94 | ]
95 | },
96 | {
97 | "cell_type": "markdown",
98 | "metadata": {
99 | "colab_type": "text",
100 | "id": "wr3EkLtudKz0"
101 | },
102 | "source": [
103 | "Next, we break down this velocity into an x and y component using trigonometry. Take a look at the figure below and check that you can see the equations in Python matching those in the plot:\n",
104 | "\n",
105 | "\n",
106 | "\n",
107 | "Here is where we call `Numpy`, note that `np.sin(angle)` will assume the angle is in radians but we defined *our* angle in degrees. Luckily `Numpy` *also* has a function to convert degrees into radians called `np.deg2rad(angle)`.\n",
108 | "\n",
109 | "Putting these two functions together:\n",
110 | "\n",
111 | "**Note:** When presented with nested brackets, Python will start on the inside and work outwards."
112 | ]
113 | },
114 | {
115 | "cell_type": "code",
116 | "execution_count": null,
117 | "metadata": {
118 | "colab": {},
119 | "colab_type": "code",
120 | "id": "sXdmydA76iQy"
121 | },
122 | "outputs": [],
123 | "source": []
124 | },
125 | {
126 | "cell_type": "code",
127 | "execution_count": null,
128 | "metadata": {
129 | "colab": {},
130 | "colab_type": "code",
131 | "id": "0KHaItNrdpUg"
132 | },
133 | "outputs": [],
134 | "source": [
135 | "v_ix = v_i * np.cos(np.deg2rad(angle))\n",
136 | "v_iy = v_i * np.sin(np.deg2rad(angle))"
137 | ]
138 | },
139 | {
140 | "cell_type": "markdown",
141 | "metadata": {
142 | "colab_type": "text",
143 | "id": "T2fZgB8oeU3H"
144 | },
145 | "source": [
146 | "We now need to create a list of points, or timestamps, at which to calculate the x/y position of the projectile as time passes.\n",
147 | "\n",
148 | "We work out how long the projectile will fly for in seconds before it hits the ground (`t_max`), and create a list of interval size `t_step` between 0 and that time.\n",
149 | "\n",
150 | "Using the time-of-flight equation: \n",
151 | "\n",
152 | ""
153 | ]
154 | },
155 | {
156 | "cell_type": "code",
157 | "execution_count": null,
158 | "metadata": {
159 | "colab": {},
160 | "colab_type": "code",
161 | "id": "MgV8uHhyevJF"
162 | },
163 | "outputs": [],
164 | "source": [
165 | "t_max = 2 * v_i * np.sin(np.deg2rad(angle)) / -a_y\n",
166 | "t_step = 0.01\n",
167 | "timestamps = np.arange(0, t_max, t_step)"
168 | ]
169 | },
170 | {
171 | "cell_type": "markdown",
172 | "metadata": {
173 | "colab_type": "text",
174 | "id": "NrTYvbIxfVHm"
175 | },
176 | "source": [
177 | "Now, we take those time stamps and plug them into the equation below (once for x and once for y) along with our inital conditions:\n",
178 | "\n",
179 | ""
180 | ]
181 | },
182 | {
183 | "cell_type": "code",
184 | "execution_count": null,
185 | "metadata": {
186 | "colab": {},
187 | "colab_type": "code",
188 | "id": "keA4zv1AfqdV"
189 | },
190 | "outputs": [],
191 | "source": [
192 | "x = v_ix * timestamps + 0.5 * a_x * timestamps**2 \n",
193 | "y = v_iy * timestamps + 0.5 * a_y * timestamps**2"
194 | ]
195 | },
196 | {
197 | "cell_type": "markdown",
198 | "metadata": {
199 | "colab_type": "text",
200 | "id": "HcooVQrKgCda"
201 | },
202 | "source": [
203 | "Lastly, we set up a plot like in the introductory Notebook and plot our results!\n",
204 | "\n"
205 | ]
206 | },
207 | {
208 | "cell_type": "code",
209 | "execution_count": null,
210 | "metadata": {
211 | "colab": {},
212 | "colab_type": "code",
213 | "id": "7Uq53KtggJb2"
214 | },
215 | "outputs": [],
216 | "source": [
217 | "fig, ax = plt.subplots()\n",
218 | "ax.plot(x, y)\n",
219 | "plt.show()"
220 | ]
221 | },
222 | {
223 | "cell_type": "markdown",
224 | "metadata": {
225 | "colab_type": "text",
226 | "id": "XlPfHer4gY7y"
227 | },
228 | "source": [
229 | "The entire script together is shown below. I've added extra comments to remind us what is going on, this is good practice for when we start writing more complicated code! I've also added a few extra lines in the plotting part to make our plot look nicer.\n",
230 | "\n",
231 | "The curly brackets `{}` in the `plt.title()` line is a way to tell Python to expect some formatting after the string, in this case we want to insert the value of `angle` in the title."
232 | ]
233 | },
234 | {
235 | "cell_type": "code",
236 | "execution_count": null,
237 | "metadata": {
238 | "colab": {},
239 | "colab_type": "code",
240 | "id": "g9THFF8Agcqn"
241 | },
242 | "outputs": [],
243 | "source": [
244 | "import numpy as np\n",
245 | "import matplotlib.pyplot as plt\n",
246 | "\n",
247 | "# set up intial conditions, all SI units\n",
248 | "a_x = 0\n",
249 | "a_y = -9.81 # note the sign of acceleration is downwards\n",
250 | "\n",
251 | "v_i = 100\n",
252 | "angle = 45\n",
253 | "\n",
254 | "# work out initial velocities in x/y\n",
255 | "v_ix = v_i * np.cos(np.deg2rad(angle))\n",
256 | "v_iy = v_i * np.sin(np.deg2rad(angle))\n",
257 | "\n",
258 | "# set up a list of timestamps to evaluate the velocity\n",
259 | "t_max = 2 * v_i * np.sin(np.deg2rad(angle)) / -a_y\n",
260 | "t_step = 0.01\n",
261 | "timestamps = np.arange(0, t_max, t_step)\n",
262 | "\n",
263 | "# use kinematic equation to work out the x and y velocities\n",
264 | "x = v_ix * timestamps + (0.5 * a_x * timestamps**2)\n",
265 | "y = v_iy * timestamps + (0.5 * a_y * timestamps**2)\n",
266 | "\n",
267 | "# plot the results!\n",
268 | "fig, ax = plt.subplots()\n",
269 | "ax.plot(x, y)\n",
270 | "plt.xlabel('Distance / m')\n",
271 | "plt.ylabel('Height / m')\n",
272 | "plt.title('The trajectory of a particle launched at {} degrees'.format(angle))\n",
273 | "plt.show()"
274 | ]
275 | },
276 | {
277 | "cell_type": "markdown",
278 | "metadata": {
279 | "colab_type": "text",
280 | "id": "dC8cx8WvJy3Z"
281 | },
282 | "source": [
283 | "# Multiple Projectiles\n",
284 | "\n",
285 | "Lets say we wanted to measure the distance our projectile travelled for a variety of starting conditions such as various angles, heights, gravity, or initial velocities.\n",
286 | "\n",
287 | "We *could* simply run the code over and over and manually change the code each time ... but we can do better than that. Plus it would be nice to plot all the results at once for easy comparison.\n",
288 | "\n",
289 | "Here's how we can adapt the above code to plot a few different angles at once. I'll also save the maximum distance for each angle, and print the results.\n",
290 | "\n",
291 | "As before I'll go through the bits of code one at a time, and then put it all together. It's very similar to the previous example but we're adding a loop so we can plot a few trajectories on one graph."
292 | ]
293 | },
294 | {
295 | "cell_type": "markdown",
296 | "metadata": {
297 | "colab_type": "text",
298 | "id": "q-vFfNk5j58T"
299 | },
300 | "source": [
301 | "As before, we'll start with some imports:"
302 | ]
303 | },
304 | {
305 | "cell_type": "code",
306 | "execution_count": null,
307 | "metadata": {
308 | "colab": {},
309 | "colab_type": "code",
310 | "id": "nZLYzD3aj_Nq"
311 | },
312 | "outputs": [],
313 | "source": [
314 | "import numpy as np\n",
315 | "import matplotlib.pyplot as plt"
316 | ]
317 | },
318 | {
319 | "cell_type": "markdown",
320 | "metadata": {
321 | "colab_type": "text",
322 | "id": "UrvNyAZNkD-y"
323 | },
324 | "source": [
325 | "We then define some physical values for our initial conditions:"
326 | ]
327 | },
328 | {
329 | "cell_type": "code",
330 | "execution_count": null,
331 | "metadata": {
332 | "colab": {},
333 | "colab_type": "code",
334 | "id": "kxbo3RLWkWVB"
335 | },
336 | "outputs": [],
337 | "source": [
338 | "v_i = 100\n",
339 | "a_x = 0\n",
340 | "a_y = -9.81"
341 | ]
342 | },
343 | {
344 | "cell_type": "markdown",
345 | "metadata": {
346 | "colab_type": "text",
347 | "id": "kxh5DW9okdxR"
348 | },
349 | "source": [
350 | "Now for the angles. Before we had a single value, this time we're going to create a list of angles to use. We will use `np.arange()` which creates evenly spaced values between two numbers at a given interval. In this case we start at 0 degrees and end at 90 degrees in intervals of 10. See [here](https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.arange.html) for more information.\n"
351 | ]
352 | },
353 | {
354 | "cell_type": "code",
355 | "execution_count": null,
356 | "metadata": {
357 | "colab": {},
358 | "colab_type": "code",
359 | "id": "jFvE3__Eki1p"
360 | },
361 | "outputs": [],
362 | "source": [
363 | "angles = np.arange(0,90,10)\n",
364 | "\n",
365 | "print (angles)"
366 | ]
367 | },
368 | {
369 | "cell_type": "markdown",
370 | "metadata": {
371 | "colab_type": "text",
372 | "id": "Gg-qe5ZAk9py"
373 | },
374 | "source": [
375 | "Now for the loop. Last time we simply called the equations for our initial conditions along with the timestamps and created the single plot.\n",
376 | "\n",
377 | "*This* time we're going to loop through each value of angle, and create a plot for each one and add it to the graph. \n",
378 | "\n",
379 | "Because this is a loop, we can't break it up into multiple cells, but I've added a lot of comments to help understand each line. "
380 | ]
381 | },
382 | {
383 | "cell_type": "code",
384 | "execution_count": null,
385 | "metadata": {
386 | "colab": {},
387 | "colab_type": "code",
388 | "id": "Eb1py-Vplu5m"
389 | },
390 | "outputs": [],
391 | "source": [
392 | "# lets loop through each of those angle values and work out the trajectory\n",
393 | "for i in range(len(angles)):\n",
394 | " \n",
395 | " # each projectile gets a unique set of timestamps, so that each trajectory curve has 100 samples\n",
396 | " t_max = 2 * v_i * np.sin(np.deg2rad(angles[i])) / -a_y\n",
397 | " t_step = 0.01\n",
398 | " timestamps = np.arange(0, t_max, t_step)\n",
399 | " \n",
400 | " # we then work out the x/y coordinates of our projectile at each timestamp\n",
401 | " # this is identical as before, but this time we're just picking the i-th angle from the list we made earlier\n",
402 | " x = v_i * timestamps * np.cos(np.deg2rad(angles[i])) + (0.5 * a_x * timestamps**2)\n",
403 | " y = v_i * timestamps * np.sin(np.deg2rad(angles[i])) + (0.5 * a_y * timestamps**2)\n",
404 | " \n",
405 | " # add that data to the plot, give it a label\n",
406 | " plt.plot(x, y, label = angles[i])\n",
407 | " # the loop will now repeat for the next angle until we reach the last angle\n",
408 | " \n",
409 | "plt.legend()\n",
410 | "plt.xlabel('Distance / m')\n",
411 | "plt.ylabel('Height / m')\n",
412 | "plt.title('The trajectory of a particle launched at various angles')\n",
413 | "plt.xlim((0,1200))\n",
414 | "plt.show()"
415 | ]
416 | },
417 | {
418 | "cell_type": "markdown",
419 | "metadata": {
420 | "colab_type": "text",
421 | "id": "RUJqy0OYpr6n"
422 | },
423 | "source": [
424 | "You might think that the last line in the loop above will show a new plot each time in the loop, but it simply means 'add this data to the plot'.\n",
425 | "\n",
426 | "We then overwrite the values of `x` and `y` in the next loop iteration for the next angle, and add *that* new data to the plot. Then in the end we plot all the data together.\n",
427 | "\n",
428 | "You may also have noticed the extra bit of code `label = angles[i]`. This gives each line a label, in this case the angle, and we can add these labels to the plot later.\n",
429 | "\n",
430 | "Once the loop is finished we can finally show the plot on the screen with `plt.show()`. I've also added a few extra formatting things like axis labels and a title like before. The `matplotlib` library is clever and auto asigns a new colour to each plot for us.\n",
431 | "\n",
432 | "The line `plt.legend()` simply turns on the legend, and it will display the labels we assigned earlier."
433 | ]
434 | },
435 | {
436 | "cell_type": "markdown",
437 | "metadata": {
438 | "colab_type": "text",
439 | "id": "GiUAyU75q_De"
440 | },
441 | "source": [
442 | "Also as before, I've put everything together in one cell and deleted some of the comments:"
443 | ]
444 | },
445 | {
446 | "cell_type": "code",
447 | "execution_count": null,
448 | "metadata": {
449 | "colab": {},
450 | "colab_type": "code",
451 | "id": "i3JH1_lFKq1e"
452 | },
453 | "outputs": [],
454 | "source": [
455 | "v_i = 100 \n",
456 | "a_y = -9.81\n",
457 | "a_x = 0\n",
458 | "\n",
459 | "angles = np.arange(0,90,10)\n",
460 | "\n",
461 | "# create an empty array, we'll save a value here for each projectile\n",
462 | "max_distance = []\n",
463 | "\n",
464 | "# lets loop through each of those angle values and work out the trajectory\n",
465 | "for i in range(len(angles)):\n",
466 | " \n",
467 | " # each projectile gets a unique set of timestamps, so that each one is sampled 100 times\n",
468 | " t_max = 2 * v_i * np.sin(np.deg2rad(angles[i])) / -a_y\n",
469 | " t_step = 0.01\n",
470 | " timestamps = np.arange(0, t_max, t_step)\n",
471 | " \n",
472 | " # we then work out the x/y coordinates of our projectile at each timestamp for that angle\n",
473 | " x = v_i * timestamps * np.cos(np.deg2rad(angles[i])) + (0.5 * a_x * timestamps ** 2)\n",
474 | " y = v_i * timestamps * np.sin(np.deg2rad(angles[i])) + (0.5 * a_y * timestamps ** 2)\n",
475 | " \n",
476 | " # this little 'if' loop will take the last x=position of each projectile so we can compare how far they landed\n",
477 | " # BUT, the 1st angle is 0 degrees and doesn't go anyway, so I need to explcity put a '0' as the 1st value in 'max_distances'\n",
478 | " # for all the rest I can just take the last item in the list of x-distances with x[-1]\n",
479 | " # 'append' just means add the end of the list\n",
480 | " if angles[i] == 0:\n",
481 | " max_distance.append(0)\n",
482 | " else:\n",
483 | " max_distance.append(x[-1])\n",
484 | " \n",
485 | " # add that data to the plot, give it a label\n",
486 | " plt.plot(x, y, label = angles[i])\n",
487 | "\n",
488 | "\n",
489 | "plt.legend()\n",
490 | "plt.xlabel('Distance / m')\n",
491 | "plt.ylabel('Height / m')\n",
492 | "plt.title('The trajectory of a particle launched at various angles')\n",
493 | "plt.xlim((0,1200))\n",
494 | "plt.show()"
495 | ]
496 | },
497 | {
498 | "cell_type": "markdown",
499 | "metadata": {
500 | "colab_type": "text",
501 | "id": "c6VDcUB8rcww"
502 | },
503 | "source": [
504 | "Lastly, remember we saved how far each projectile went? We can print these results here by looping through that array:"
505 | ]
506 | },
507 | {
508 | "cell_type": "code",
509 | "execution_count": null,
510 | "metadata": {
511 | "colab": {},
512 | "colab_type": "code",
513 | "id": "G8GG3pKrPwvW"
514 | },
515 | "outputs": [],
516 | "source": [
517 | "# print a statement by looping through the list of angles and max_distances\n",
518 | "# we also use another Numpy function to round the distance value to 2 dp for neatness\n",
519 | "for i in range(len(angles)):\n",
520 | " print ('Projectile launched at {a} degrees reached {b} meters'.format(a=angles[i], b=np.round(max_distance[i],2)))"
521 | ]
522 | }
523 | ],
524 | "metadata": {
525 | "colab": {
526 | "collapsed_sections": [],
527 | "name": "Copy of Part_2_Simple_Projectile.ipynb",
528 | "private_outputs": true,
529 | "provenance": [
530 | {
531 | "file_id": "16LxVE0Kmi353HvLBVx1OMj_dISlVxGRr",
532 | "timestamp": 1598850710116
533 | }
534 | ]
535 | },
536 | "kernelspec": {
537 | "display_name": "Python 3",
538 | "language": "python",
539 | "name": "python3"
540 | },
541 | "language_info": {
542 | "codemirror_mode": {
543 | "name": "ipython",
544 | "version": 3
545 | },
546 | "file_extension": ".py",
547 | "mimetype": "text/x-python",
548 | "name": "python",
549 | "nbconvert_exporter": "python",
550 | "pygments_lexer": "ipython3",
551 | "version": "3.7.8"
552 | }
553 | },
554 | "nbformat": 4,
555 | "nbformat_minor": 1
556 | }
557 |
--------------------------------------------------------------------------------
/particle-physcis'/projectile example.py:
--------------------------------------------------------------------------------
1 | ground=box(pos=vector(0,-.2,0),size=vector(10,.4,2),color=color.green)
2 | ball=sphere(pos=vector(-5,1.1,0),radius=.1, color=color.yellow, make_trail=True)
3 | r0=ball.pos
4 | g=vector(0,-9.8,0)
5 | ball.m=0.2
6 | v0=10
7 | theta=70*pi/180
8 | ball.p=ball.m*v0*vector(cos(theta),sin(theta),0)
9 |
10 | t=0
11 | dt=0.001
12 |
13 | while ball.pos.y>=0.1:
14 | rate(1000)
15 | Fnet=ball.m*g
16 | ball.p=ball.p+Fnet*dt
17 | ball.pos=ball.pos+ball.p*dt/ball.m
18 | t=t+dt
19 |
20 | print("dr final = ",ball.pos-r0," m")
21 | print("t final = ",t," s")
22 |
--------------------------------------------------------------------------------
/solar-system"/IMG_20200831_123930.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PulsatingGenius/coding-for--physics/c9929135685c2969acba0997d16c08a598a528f2/solar-system"/IMG_20200831_123930.jpg
--------------------------------------------------------------------------------
/solar-system"/Readme.md:
--------------------------------------------------------------------------------
1 |
5 |
6 |
The Sun is a star, a hot ball of glowing gases at the heart of our solar system. Its influence extends far beyond the orbits of distant Neptune and Pluto. Without the Sun's intense energy and heat, there would be no life on Earth. And though it is special to us, there are billions of stars like our Sun scattered across the Milky Way galaxy.
Sun-scorched Mercury is only slightly larger than Earth's Moon. Like the Moon, Mercury has very little atmosphere to stop impacts and it is covered with craters. Mercury's dayside is super heated by the Sun, but at night temperatures drop hundreds of degrees below freezing. Ice may even exist in craters. Mercury's egg-shaped orbit takes it around the Sun every 88 days.
Venus is a dim world of intense heat and volcanic activity. Similar in structure and size to Earth, Venus' thick, toxic atmosphere traps heat in a runaway 'greenhouse effect.' The scorched world has temperatures hot enough to melt lead. Glimpses below the clouds reveal volcanoes and deformed mountains. Venus spins slowly in the opposite direction of most planets.
Earth is an ocean planet. Our home world's abundance of water - and life - makes it unique in our solar system. Other planets, plus a few moons, have ice, atmospheres, seasons and even weather, but only on Earth does the whole complicated mix come together in a way that encourages life - and lots of it.
Though details of Mars' surface are difficult to see from Earth, telescope observations show seasonally changing features and white patches at the poles. For decades, people speculated that bright and dark areas on Mars were patches of vegetation, that Mars could be a likely place for life-forms, and that water might exist in the polar caps. When the Mariner 4 spacecraft flew by Mars in 1965, many were shocked to see photographs of a bleak, cratered surface. Mars seemed to be a dead planet. Later missions, however, have shown that Mars is a complex member of the solar system and holds many mysteries yet to be solved.
The most massive planet in our solar system, with four large moons and many smaller moons, Jupiter forms a kind of miniature solar system. Jupiter resembles a star in composition. In fact, if it had been about 80 times more massive, it would have become a star rather than a planet.
Saturn was the most distant of the five planets known to the ancients. Like Jupiter, Saturn is made mostly of hydrogen and helium. Its volume is 755 times greater than that of Earth. Winds in the upper atmosphere reach 500 meters (1,600 feet) per second in the equatorial region. These super-fast winds, combined with heat rising from within the planet's interior, cause the yellow and gold bands visible in the atmosphere.
The first planet found with the aid of a telescope, Uranus was discovered in 1781 by astronomer William Herschel. The seventh planet from the Sun is so distant that it takes 84 years to complete one orbit.
Nearly 4.5 billion kilometers (2.8 billion miles) from the Sun, Neptune orbits the Sun once every 165 years. It is invisible to the naked eye because of its extreme distance from Earth. Interestingly, the unusual elliptical orbit of the dwarf planet Pluto brings Pluto inside Neptune's orbit for a 20-year period out of every 248 Earth years
Tiny, cold and incredibly distant, Pluto was discovered in 1930 and long considered to be the ninth planet. But after the discoveries of similar intriguing worlds even farther out, Pluto was reclassified as a dwarf planet. This new class of worlds may offer some of the best evidence of the origins of our solar system.