diff --git a/class_materials/exercises/particle_update_position.ipynb b/class_materials/exercises/particle_update_position.ipynb index b3d829a..6baba13 100644 --- a/class_materials/exercises/particle_update_position.ipynb +++ b/class_materials/exercises/particle_update_position.ipynb @@ -35,51 +35,65 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 6, "metadata": { "pycharm": { "name": "#%%\n" } }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1.6800000000000002\n" - ] - } - ], + "outputs": [], "source": [ "class Particle:\n", - " def __init__(self, mass, velocity):\n", + " def __init__(self, mass=1, velocity=0., 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", - "particle = Particle(mass=2.1, velocity=0.8)\n", - "print(particle.momentum())" + " def update_position(self, dt):\n", + " new_position = self.position + dt * self.velocity\n", + " self.position = new_position\n", + " return" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "8.28\n" + "1.6800000000000002\n", + "0.0\n" ] } ], "source": [ - "position = 8.2\n", - "new_position = update_position(particle.velocity, position, dt=0.1)\n", - "print(new_position)" + "particle = Particle(mass=2.1, velocity=0.8, position=0.)\n", + "print(particle.momentum())\n", + "print(particle.position)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.08000000000000002\n" + ] + } + ], + "source": [ + "particle.update_position(dt=0.1)\n", + "print(particle.position)" ] }, { @@ -118,7 +132,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.11" + "version": "3.13.6" }, "toc": { "nav_menu": { @@ -142,5 +156,5 @@ } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 }