Particle position

This commit is contained in:
ASPP Student 2025-09-25 11:03:48 +03:00
parent 3d3d3913ef
commit 50ae6c84c5

View file

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