update the class constructor to include update_position method #7

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

View file

@ -24,7 +24,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 2,
"metadata": { "metadata": {
"ExecuteTime": { "ExecuteTime": {
"end_time": "2018-07-27T15:05:51.531289Z", "end_time": "2018-07-27T15:05:51.531289Z",
@ -48,7 +48,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 3,
"metadata": { "metadata": {
"ExecuteTime": { "ExecuteTime": {
"end_time": "2018-07-27T15:05:51.905235Z", "end_time": "2018-07-27T15:05:51.905235Z",
@ -420,21 +420,13 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12, "execution_count": 4,
"metadata": { "metadata": {
"pycharm": { "pycharm": {
"name": "#%%\n" "name": "#%%\n"
} }
}, },
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"9.0\n"
]
}
],
"source": [ "source": [
"class Particle:\n", "class Particle:\n",
" def __init__(self, mass, velocity):\n", " def __init__(self, mass, velocity):\n",
@ -443,9 +435,38 @@
"\n", "\n",
" def momentum(self):\n", " def momentum(self):\n",
" return self.mass * self.velocity\n", " return self.mass * self.velocity\n",
"\n", " \n",
"particle1 = Particle(10.0, 0.9)\n", " def update_position(self, position, dt):\n",
"print(particle1.momentum())" " return position + self.velocity * dt"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"particle1 = Particle(10.0, 0.9)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"5.5"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"particle1.update_position(1, 5)"
] ]
}, },
{ {
@ -562,7 +583,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.11.3" "version": "3.12.4"
}, },
"toc": { "toc": {
"nav_menu": { "nav_menu": {