Really simple Python program to simulate inelastic collision

In summary, the conversation discusses a Python program that simulates an inelastic collision between two objects. There is confusion about how to calculate the heat released during the collision. The program works for the most part but needs clarification on the concept of friction. The solution is to consider the total energy, which includes both kinetic and thermal energy, to be conserved. The released heat can be calculated by finding the difference between the initial and final kinetic energy.
  • #1
remote
8
1
I'm trying to write this Python program that simulates a completely inelastic collision between two objects. The program seems to work for the most part, but I'm completely lost on the "heat released" part at the end. I have no idea if I'm calculating this right, or if I'm completely wrong. Can anyone give me some insight?

Code:
frameRate = 4000.0
mass = 1.0
velocity = 1.0
distance = 0.0
mass2 = 1.0
velocity2 = 0.0
distance2 = 0.0

maxTime = 50
resistance = 1.0
time = 0.0
print "total kinetic energy:    ", .5 * mass * velocity * velocity + .5 * mass2 * velocity2 * velocity2

#now we collide two objects, and see how long it takes them to reach the same speed
while True:
	distance += velocity / frameRate
	distance2 += velocity2 / frameRate
	velocity2 -= (resistance * (velocity2 - velocity)/ mass2) / frameRate
	velocity -= (resistance * (velocity - velocity2) / mass) / frameRate
	time += 1 / frameRate
	if time > maxTime:
		break
	if velocity <= velocity2 + .01:
		break
print "colliding\n\n"
print "time elapsed:               ", time
print "object 1 distance traveled: ", distance
print "object 2 distance traveled: ", distance2
print "object 1 velocity:          ", velocity
print "object 2 velocity:          ", velocity2
print "heat released:              ", (distance - distance2) * resistance
 
Technology news on Phys.org
  • #2
Total energy, the sum of kinetic and thermal energy, is conserved. The released heat is just the difference between initial and final kinetic energy.
 
  • #3
Thanks. That gave me the hint I needed to fix the program.

I'm still a bit confused about how friction works, but I think I can ask about that in another thread.
 

1. What is an inelastic collision?

An inelastic collision is a type of collision in which kinetic energy is not conserved. This means that some of the energy is lost in the form of heat, sound, or deformation, and the total kinetic energy after the collision is less than the total kinetic energy before the collision.

2. How is a Python program used to simulate inelastic collisions?

A Python program can be used to simulate inelastic collisions by using the laws of conservation of momentum and energy. The program will input the initial velocities and masses of the objects involved, and then calculate the final velocities using the equations for inelastic collisions.

3. Can this program be used for all types of inelastic collisions?

No, this program is designed specifically for simple inelastic collisions between two objects. It may not accurately simulate more complex collisions, such as those involving multiple objects or objects with varying shapes.

4. How accurate are the results of the simulation?

The accuracy of the results depends on the accuracy of the input data and the assumptions made in the simulation. In real-world scenarios, there may be other factors at play that could affect the outcome of the collision, making the results of the simulation less accurate.

5. Can this program be modified for use in other programming languages?

Yes, the principles used in this program can be applied to other programming languages to simulate inelastic collisions. However, the specific syntax and structure of the program may vary depending on the language being used.

Similar threads

  • Programming and Computer Science
Replies
1
Views
2K
  • Introductory Physics Homework Help
Replies
10
Views
1K
  • Programming and Computer Science
Replies
17
Views
2K
  • Programming and Computer Science
Replies
10
Views
3K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
4
Views
6K
  • Special and General Relativity
Replies
8
Views
1K
  • Programming and Computer Science
Replies
2
Views
16K
Replies
1
Views
1K
  • Introductory Physics Homework Help
Replies
3
Views
2K
Back
Top