diff --git a/class_materials/exercises/particle_update_position.ipynb b/class_materials/exercises/particle_update_position.ipynb index b3d829a..0a2772c 100644 --- a/class_materials/exercises/particle_update_position.ipynb +++ b/class_materials/exercises/particle_update_position.ipynb @@ -17,7 +17,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 10, "metadata": { "ExecuteTime": { "end_time": "2018-07-27T15:05:51.531289Z", @@ -35,7 +35,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 11, "metadata": { "pycharm": { "name": "#%%\n" @@ -52,20 +52,25 @@ ], "source": [ "class Particle:\n", - " def __init__(self, mass, velocity):\n", + " def __init__(self, mass, velocity, position):\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", + " 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, position=8.2)\n", "print(particle.momentum())" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -84,10 +89,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "8.28" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dt=0.1\n", + "particle.update_position(dt)" + ] }, { "cell_type": "code", @@ -104,7 +123,7 @@ "metadata": { "hide_input": false, "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -118,7 +137,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.11" + "version": "3.13.7" }, "toc": { "nav_menu": {