implemented updateing position of particle #6

Open
giovannife wants to merge 1 commit from giovannife/2024-heraklion-scientific-patterns:dev into main

View file

@ -52,20 +52,25 @@
], ],
"source": [ "source": [
"class Particle:\n", "class Particle:\n",
" def __init__(self, mass, velocity):\n", " def __init__(self, mass, velocity, position):\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",
" def update_position(self, dt):\n",
" self.position = self.position + self.velocity * dt\n",
" return self.position\n",
"\n",
"particle = Particle(mass=2.1, velocity=0.8)\n", "particle = Particle(mass=2.1, velocity=0.8)\n",
"print(particle.momentum())" "print(particle.momentum())"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -78,7 +83,8 @@
], ],
"source": [ "source": [
"position = 8.2\n", "position = 8.2\n",
"new_position = update_position(particle.velocity, position, dt=0.1)\n", "particle = Particle(2.1, 0.8, position)\n",
"new_position = particle.update_position(dt=0.1)\n",
"print(new_position)" "print(new_position)"
] ]
}, },