Exercise 3: separate context map from walker #14

Open
simoneci wants to merge 2 commits from simoneci/2025-plovdiv-scientific-patterns:ex1 into main
Showing only changes of commit 50ae6c84c5 - Show all commits

View file

@ -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
}