collisioni.py

Created by gianfranco-oddenino

Created on March 07, 2025

573 Bytes

Lo script risolve un problema di urto unidimensionale. I dati richiesti sono le masse e le velocità iniziali di due oggetti. Vengono calcolate le velocità finali, le energie cinetiche totali iniziali e finali e la variazione di energia cinetica relativa. Il grado di elasticità dell’urto può essere selezionato mediante il coefficiente di restituzione.


from math import *

print("Masse dei corpi")
m1=float(input("m1: "))
m2=float(input("m2: "))
print("Velocita' iniziali")
v1i=float(input("v1: "))
v2i=float(input("v2: "))
print("Coefficiente di restituzione")
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);
ei=0.5*m1*v1i*v1i+0.5*m2*v2i*v2i;
ef=0.5*m1*v1f*v1f+0.5*m2*v2f*v2f;
de=(ef-ei)/ei;

print("Velocita' finali")
print("v1:", v1f)
print("v2:", v2f)
print("Energie cinetiche")
print("Ei:", ei)
print("Ef:", ef)
print("(Ef-Ei)/Ei:", de)

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.