From 19dcbeea5ceca39810fa148103b991c0a9b98d54 Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Thu, 25 Sep 2025 10:36:51 +0300 Subject: [PATCH] update integration method to be inside the particle class --- .../exercises/particle_update_position.ipynb | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/class_materials/exercises/particle_update_position.ipynb b/class_materials/exercises/particle_update_position.ipynb index b3d829a..43e5e97 100644 --- a/class_materials/exercises/particle_update_position.ipynb +++ b/class_materials/exercises/particle_update_position.ipynb @@ -35,7 +35,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": { "pycharm": { "name": "#%%\n" @@ -52,20 +52,24 @@ ], "source": [ "class Particle:\n", - " def __init__(self, mass, velocity):\n", + " def __init__(self, mass, velocity, position=0):\n", " self.mass = mass\n", " self.velocity = velocity\n", + " self.position = position\n", "\n", " def momentum(self):\n", " return self.mass * self.velocity\n", "\n", + " def update_position(self, dt):\n", + " self.position += self.velocity * dt\n", + "\n", "particle = Particle(mass=2.1, velocity=0.8)\n", "print(particle.momentum())" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -77,8 +81,10 @@ } ], "source": [ - "position = 8.2\n", - "new_position = update_position(particle.velocity, position, dt=0.1)\n", + "\n", + "particle = Particle(mass=2.1, velocity=0.8, position = 8.2)\n", + "particle.update_position(dt=0.1)\n", + "new_position = particle.position\n", "print(new_position)" ] }, @@ -104,7 +110,7 @@ "metadata": { "hide_input": false, "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "env", "language": "python", "name": "python3" }, @@ -118,7 +124,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.11" + "version": "3.13.6" }, "toc": { "nav_menu": { -- 2.39.5