Skip to content

Commit

Permalink
fix: improve docs and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
CallumJHays committed Jul 2, 2023
1 parent e4b9faf commit 32f953b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
14 changes: 6 additions & 8 deletions mathpad/mech.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from typing import Type, cast
from mathpad import *


Expand All @@ -15,10 +14,10 @@ def kinetic_energy(*, m: X[Mass], v: X[Velocity]) -> Energy:
Kinetic energy of the particle in joules
Example:
>>> kinetic_energy(m=1 * kg, v=2 * m/s)
2 joules
>>> kinetic_energy(m="m" * kg, v="v" * m/s)
0.5*mv**2 joules
>>> kinetic_energy(m=1 * kg, v=2 * m/s)
2 joules
"""
return (m * v ** 2 / 2).in_units(joules) # type: ignore
Expand Down Expand Up @@ -46,11 +45,10 @@ def euler_lagrange(
Euler-Lagrange equation for a system of particles.
Arguments:
sum_KE: sum of kinetic energies of particles
sum_PE: sum of potential energies of particles
sum_NCF: sum of net contact forces on particles
KE: sum of kinetic energies of particles
PE: sum of potential energies of particles
NCF: sum of net contact forces on particles
var: variable you are interested in finding the dynamics for
"""
L = KE - PE
return diff(diff(L, wrt=diff(var)), wrt=t) - diff(L, wrt=var) == NCF # type: ignore
Expand All @@ -62,7 +60,7 @@ def impulse_momentum(
m: X[Mass], # mass
v1: X[Velocity], # initial velocity
F: X[Force], # impulse force required
t: X[Time], # impulse duration in seconds
t: X[Time], # impulse duration
v2: X[Velocity], # final velocity
) -> Equation:
"The force required during an instant to change an object's velocity"
Expand Down
4 changes: 2 additions & 2 deletions mathpad/simulate_dynamic_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def simulate_dynamic_system(
]

# outputs are highest of input derviatives plus recorded data
# ie [dddx, record[0], record[1]]
# ie [ddx, ddy, record[0], record[1]]
lambdified = lambdify([x_axis.expr, inputs], solution_vec, 'numpy')

data = []
Expand Down Expand Up @@ -285,7 +285,7 @@ def step(x: float, state: np.ndarray):
"yanchor": "top",
},
},
).show("svg" if plot_static else None)
).show("svg" if plot_static else None) # type: ignore

all_data.extend(data)

Expand Down

0 comments on commit 32f953b

Please sign in to comment.