-
Notifications
You must be signed in to change notification settings - Fork 2
/
.ipynb
99 lines (99 loc) · 2.47 KB
/
.ipynb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt \n",
"import matplotlib.animation as ani\n",
"import matplotlib.cm as cm \n",
"\n",
"# allows animation features within notebook\n",
"%matplotlib notebook"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"timesteps = np.arange(-1,1,0.01)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"class particle:\n",
" def __init__(self, timesteps, mass = 1, charge = 1, force = np.zeros(timesteps.size), dt = timesteps.size/1000):\n",
" \n",
" self.mass = mass\n",
" self.charge = charge\n",
" self.timesteps = timesteps\n",
" self.force = force\n",
" self.dt = dt\n",
" \n",
" self.pos = np.zeros((self.timesteps.size, 3))\n",
" self.vel = np.zeros((self.timesteps.size, 3))\n",
" self.accel = np.zeros((self.timesteps.size, 3))\n",
" \n",
" def update(self,force):\n",
" self.accel - self.forcce/self.mass\n",
" self.vel = self.accel*dt\n",
" self.pos = self.vel*dt\n",
" \n",
" "
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"# now we set up an array of particle objects\n",
"N = 3\n",
"Particle_list = []\n",
"for i in range(N):\n",
" Particle_list.append(particle)\n",
"#abc = particle(timesteps)\n",
"\n",
"def calc_forces(particle):\n",
" for i in range(N):\n",
" for j in range(N):\n",
" if i == j:\n",
" Particle_list[i].force+=0\n",
" else:\n",
" Particle_list[i].force+= 1/(np.linalg.norm(Particle_list[i].pos - Particle_list[j].pos))**2\n",
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}