implement update position #11
1 changed files with 26 additions and 8 deletions
|
@ -52,15 +52,19 @@
|
||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"class Particle:\n",
|
"class Particle:\n",
|
||||||
" def __init__(self, mass, velocity):\n",
|
" def __init__(self, mass, velocity, position = 0):\n",
|
||||||
" self.mass = mass\n",
|
" self.mass = mass\n",
|
||||||
" self.velocity = velocity\n",
|
" self.velocity = velocity\n",
|
||||||
|
" self.position = position\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def momentum(self):\n",
|
" def momentum(self):\n",
|
||||||
" return self.mass * self.velocity\n",
|
" return self.mass * self.velocity\n",
|
||||||
"\n",
|
"\n",
|
||||||
"particle = Particle(mass=2.1, velocity=0.8)\n",
|
" def update_position(self, dt):\n",
|
||||||
"print(particle.momentum())"
|
" self.position = self.position + self.velocity * dt\n",
|
||||||
|
"\n",
|
||||||
|
"particle = Particle(mass=2.1, velocity=0.8, position = 8.2)\n",
|
||||||
|
"print(particle.momentum())\n"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -84,10 +88,24 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": 4,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [
|
||||||
"source": []
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"8.28"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 4,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"particle.update_position(0.1)\n",
|
||||||
|
"particle.position"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
|
@ -118,7 +136,7 @@
|
||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.10.11"
|
"version": "3.13.6"
|
||||||
},
|
},
|
||||||
"toc": {
|
"toc": {
|
||||||
"nav_menu": {
|
"nav_menu": {
|
||||||
|
@ -142,5 +160,5 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
"nbformat_minor": 2
|
"nbformat_minor": 4
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue