Added update position to class #13
1 changed files with 16 additions and 10 deletions
|
@ -17,7 +17,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 1,
|
"execution_count": 12,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2018-07-27T15:05:51.531289Z",
|
"end_time": "2018-07-27T15:05:51.531289Z",
|
||||||
|
@ -35,7 +35,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 2,
|
"execution_count": 10,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"pycharm": {
|
"pycharm": {
|
||||||
"name": "#%%\n"
|
"name": "#%%\n"
|
||||||
|
@ -46,26 +46,32 @@
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
"output_type": "stream",
|
"output_type": "stream",
|
||||||
"text": [
|
"text": [
|
||||||
"1.6800000000000002\n"
|
"8.28\n"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"class Particle:\n",
|
"class Particle:\n",
|
||||||
" def __init__(self, mass, velocity):\n",
|
" def __init__(self, mass, velocity, position):\n",
|
||||||
" self.mass = mass\n",
|
" self.mass = mass\n",
|
||||||
" self.velocity = velocity\n",
|
" self.velocity = velocity\n",
|
||||||
"\n",
|
" self.position = position\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())"
|
" self.position = self.position + self.velocity * dt\n",
|
||||||
|
"\n",
|
||||||
|
"particle = Particle(mass=2.1, velocity=0.8, position=8.2)\n",
|
||||||
|
"\n",
|
||||||
|
"particle.update_position(0.1)\n",
|
||||||
|
"print(particle.position)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 3,
|
"execution_count": 13,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
|
@ -118,7 +124,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 +148,5 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
"nbformat_minor": 2
|
"nbformat_minor": 4
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue