collisions.py

Created by gianfranco-oddenino

Created on April 10, 2020

564 Bytes

The script solves a one-dimensional impact problem. The input data are the masses and the initial velocities of two objects. The final velocities, the initial and final total kinetic energies and the relative energy variation are calculated. The degree of elasticity of the impact can be selected by means of the return coefficient.


from math import *

print("Masses of objects")
m1=float(input("m1: "))
m2=float(input("m2: "))
print("Initial velocities")
v1i=float(input("v1: "))
v2i=float(input("v2: "))
print("Return coefficient")
cr=float(input("cr: "))

v1f=(m1*v1i+m2*v2i+cr*m2*(v2i-v1i))/(m1+m2);
v2f=(m1*v1i+m2*v2i+cr*m1*(v1i-v2i))/(m1+m2);
ki=0.5*m1*v1i*v1i+0.5*m2*v2i*v2i;
kf=0.5*m1*v1f*v1f+0.5*m2*v2f*v2f;
dk=(kf-ki)/ki;

print("Final velocities")
print("v1:", v1f)
print("v2:", v2f)
print("Kinetic energies")
print("Ki:", ki)
print("Kf:", kf)
print("(Kf-Ki)/Ki:", dk)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.