Ed, If I am understanding your use cases, within Sympy I think you want the sympy.physics module. See the documentation https://docs.sympy.org/latest/reference/public/physics/index.html#module-sympy.physics
Jonathan On Tuesday, January 20, 2026 at 4:45:46 AM UTC-6 [email protected] wrote: > Hello, > > Here's example 4.5 from the book University Physics 15th edition: > > # A waitress shoves a ketchup bottle with mass 0.45 kg > # to her right > # along a smooth, level lunch counter. > # > # The bottle leaves her hand moving at 2.0 m/s, > # then slows down as it slides because of a constant horizontal > # friction force exerted on it by the countertop. > # > # It slides for 1.0 m before coming to rest. > # > # What are the magnitude and direction > # of the friction force acting on the bottle? > > > The diagram: > > [image: diagram.png] > > A full symbolic and numeric solution in Python/sympy is shown at the end. > > First I setup the equations for the bottle: > > b = make_states_model('b', 2) # bottle > > b0, b1 = b.states > > b01 = b.edges[0] > > eqs = kinematics_fundamental(b, axes=['x']) > > display_equations_(eqs) > > The equations in `eqs`: > > # dt_b_0_1 = -b_0_t + b_1_t > # v_av_x_b_0_1 = (-b_0_x + b_1_x)/dt_b_0_1 > # a_x_b_0_1 = (-b_0_v_x + b_1_v_x)/dt_b_0_1 > # v_av_x_b_0_1 = b_0_v_x/2 + b_1_v_x/2 > > The values we know: > > values = {} > > values[b0.t] = 0 > values[b0.pos.x] = 0 > values[b1.pos.x] = 1.0 # m > values[b0.vel.x] = 2.0 # m/s > values[b1.vel.x] = 0.0 # m/s > > Setup the forces: > > # forces: normal, weight, friction > > n = make_point("n") # normal force > w = make_point("w") # weight > f = make_point("f") # friction force > > m = sp.symbols("m") # mass > a = make_point("a") # acceleration > > eqs += newtons_second_law([n, w, f], m, a) > > eqs += eq_flat( > a.x, b01.a.x > ) > > values[n.x] = 0 > values[w.x] = 0 > values[m] = 0.45 # kg > > > Now, let's display the full system of equations. > green : values we know > red : value we want > > [image: Untitled.png] > > Solve the system symbolically and numerically: > > [image: Untitled.png] > > Question: > > I'm using some of my own libraries for this. > Are there existing libraries for stuff like this? > > Would you recommend a different approach? > > Ed Cavazos > > Full program: > > > https://github.com/dharmatech/combine-equations.py/blob/master/examples/up/ch4/up-example-4.5-001-one-step.py > > > # A waitress shoves a ketchup bottle with mass 0.45 kg > # to her right > # along a smooth, level lunch counter. > # > # The bottle leaves her hand moving at 2.0 m/s, > # then slows down as it slides because of a constant horizontal > # friction force exerted on it by the countertop. > # > # It slides for 1.0 m before coming to rest. > # > # What are the magnitude and direction > # of the friction force acting on the bottle? > > # ---------------------------------------------------------------------- > > from pprint import pprint > import sympy as sp > > from combine_equations.kinematics_states import * > from combine_equations.solve_system import * > from combine_equations.display_equations import display_equations_ > from combine_equations.solve_and_display import solve_and_display_ > from combine_equations.misc import eq_flat > from combine_equations.newtons_laws import * > > # ---------------------------------------------------------------------- > > b = make_states_model('b', 2) # bottle > > b0, b1 = b.states > > b01 = b.edges[0] > > eqs = kinematics_fundamental(b, axes=['x']) > > display_equations_(eqs) > # dt_b_0_1 = -b_0_t + b_1_t > # v_av_x_b_0_1 = (-b_0_x + b_1_x)/dt_b_0_1 > # a_x_b_0_1 = (-b_0_v_x + b_1_v_x)/dt_b_0_1 > # v_av_x_b_0_1 = b_0_v_x/2 + b_1_v_x/2 > # ---------------------------------------------------------------------- > values = {} > > values[b0.t] = 0 > values[b0.pos.x] = 0 > values[b1.pos.x] = 1.0 # m > values[b0.vel.x] = 2.0 # m/s > values[b1.vel.x] = 0.0 # m/s > # ---------------------------------------------------------------------- > > # forces: normal, weight, friction > > n = make_point("n") # normal force > w = make_point("w") # weight > f = make_point("f") # friction force > > m = sp.symbols("m") # mass > a = make_point("a") # acceleration > > eqs += newtons_second_law([n, w, f], m, a) > > eqs += eq_flat( > a.x, b01.a.x > ) > > values[n.x] = 0 > values[w.x] = 0 > values[m] = 0.45 # kg > > display_equations_(eqs, values, want=f.x) > # dt_b_0_1 = -b_0_t + b_1_t > # v_av_x_b_0_1 = (-b_0_x + b_1_x)/dt_b_0_1 > # a_x_b_0_1 = (-b_0_v_x + b_1_v_x)/dt_b_0_1 > # v_av_x_b_0_1 = b_0_v_x/2 + b_1_v_x/2 > # f_x + n_x + w_x = m*a_x > # f_y + n_y + w_y = m*a_y > # a_x = a_x_b_0_1 > > solve_and_display_(eqs, values, want=f.x) > # f_x = (b_0_v_x**2*m/2 - b_0_x*n_x - b_0_x*w_x - b_1_v_x**2*m/2 + > b_1_x*n_x + b_1_x*w_x)/(b_0_x - b_1_x) > # f_x = -0.900000000000000 > > -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/sympy/485e0913-7b34-4563-96e0-b2d6c2d296ecn%40googlegroups.com.
