Calculating Final Positions & Velocities for M1, M2 & Spring After DeltaT

In summary: That's a really good point - maybe I should try that.Numerical is totally fine and probably desirable!
  • #1
mikejm
40
2
Let's say you have two masses on either side of a spring. Mass 1 is connected to the end of a spring. The spring itself has no mass. Mass 2 is free in space. So you have:

Code:
[M1]-[spring]           [M2]
So it's more descriptive, I'll name the variables like you might in programming. Let's define each element as follows.

Mass 1:
  • m1Mass = mass of M1
  • m1PosInit = initial position of M1
  • m1PosFinal = final position of M1
  • m1VelInit = initial velocity of M1
  • m1VelFinal = final velocity of M1

Mass 2:
  • m2Mass = mass of M2
  • m2PosInit = initial position of M2
  • m2PosFinal = final position of M2
  • m2VelInit = initial velocity of M2
  • m2VelFinal = final velocity of M2
Spring:
  • springLengthAtRest = natural length of spring when not compressed at rest
  • springLengthInit = initial length of spring
  • springLengthFinal = final length of spring
  • springCompressionInit = springLengthAtRest - springLengthInit
  • springCompressionFinal = springLengthAtRest - springLengthFinal
  • springForce = force of the nonlinear spring based on spring compression (eg. from a simple equation like F(x) = -k x^{c})

Time:
  • deltaT = amount of time that passes from initial state to final state

At the initial state, mass 2 is already in contact with the end of the spring (or is just about to contact it) with a given momentum. Mass 1 is traveling with a given momentum as well. The spring has a given amount of initial compression (which could be zero or non-zero).

How do you calculate the final positions and velocities after a certain increment of time (deltaT) for all the elements?

I'm trying to simulate a collision in a program I'm writing just for fun but stuck on this. If it's easier to give the spring some mass that's fine too. Whatever works. Thanks a bunch.
 
Last edited:
Physics news on Phys.org
  • #2
The problem is appreciably harder if the spring has some mass - don’t do that if you can avoid it.

How much calculus do you know? The equations for the position and velocity of each mass are the solutions to differential equations.
 
  • #3
Nugatory said:
The problem is appreciably harder if the spring has some mass - don’t do that if you can avoid it.

How much calculus do you know? The equations for the position and velocity of each mass are the solutions to differential equations.

Thanks. Yeah I was figuring giving the spring mass would make it much harder. We'll leave it with no mass then.

I can try to know as much as I need to know. :smile: I never knew how to do imaginary math with Euler's formula or Laplace transforms last year and now to a limited extent I can (had to learn similarly to solve some problems). Two years ago I didn't know a line of C++ and now I code freely. I need to solve this problem now or my program design is stuck on it. So it's non-negotiable for me to figure it out.

I have looked at as many websites and textbook examples as I can for collisions but they all only talk about mass-mass, not mass-spring-mass. Also most don't focus on the goal of finding the resulting positions/momentums after a given increment of time from an initial given state.

Without any further help or direction I'm totally stuck on this. Any help or guidance would be very much appreciated.
 
  • #4
Do you need an analytical solution or are numerical solutions ok?
 
  • #5
Dale said:
Do you need an analytical solution or are numerical solutions ok?
Numerical is totally fine and probably desirable!

FYI, if you're curious, this is for simulating the collision of a piano hammer or guitar plectrum (both of which are typically modeled as a mass (ie. hand/hammer) connected to a spring (ie. plectrum/felt) impacting another mass (ie. string segment)). It's a real time audio synthesiser I'm designing that needs to be calculated sample-by-sample so it needs to be efficient and doesn't need to be exactly precise.

Thanks.
 
  • #6
mikejm said:
It's a real time audio synthesiser I'm designing that needs to be calculated sample-by-sample so it needs to be efficient and doesn't need to be exactly precise.
Then you should probably calculate it numerically using something like Euler’s method.

Basically, you know the initial positions, velocities, and forces, and with any set of positions you can calculate the forces. So you break your time into small steps, maybe 1/10 of a sample or less. Then ##t_n=n * dt## and then you calculate the next steps based on the current values:
##x(t_{n+1})=x(t_n)+v(t_n)dt ##
##v(t_{n+1})=v(t_n)+F(t_n,x_n,...)dt/m##
 
  • #7
Dale said:
Then you should probably calculate it numerically using something like Euler’s method.

Basically, you know the initial positions, velocities, and forces, and with any set of positions you can calculate the forces. So you break your time into small steps, maybe 1/10 of a sample or less. Then tn=n∗dt and then you calculate the next steps based on the current values:
x(tn+1)=x(tn)+v(tn)dt
v(tn+1)=v(tn)+F(tn,xn,...)dt/m

Thanks Dale. That's sort of what I tried doing already but I didn't think about the possibility of doing it with even finer detail than per sample in the way you suggest. The problem is the "hammer/hand" was moving so quickly relative to the sample rate it was collapsing the spring almost fully on the first contact which then threw things off because in reality the spring force would have prevented such a great collapse. I was ending up with major spring collapses with massive spring forces that never would have been generated in real life.

So I will at each step:
  • Increment the two masses' positions based on their velocities.
  • Calculate the force of the spring based on their new positions.
  • Calculate their new velocities based on their old velocity and the spring force.
I can subdivide the sample into enough increments to get this done with finer detail to avoid the problem I'm having. Thanks that's really really helpful and I never would have thought of "oversampling" in this way to fix the problem. I also wasn't sure if my method I was already using was correct - I just thought it made sense and was making it up as I went. Glad to hear it's actually the right way to deal with it. :smile:

Can I ask you just two small follow up questions?

Spring force when calculated by compression as in F(x) = kx^c (where x is total amount of spring compression) is applied equally to both masses right? Ie. It's not divided into 2 is it and half applied to one mass, half to the other?

Also, how would I implement damping on my spring if I wanted to? I understand springs can oscillate if not damped. It shouldn't oscillate in my case because the spring/hammer/plectrum will release quickly then be reset, but I'm just curious. I think the equation for a nonlinear damped spring is:

F(x) = k*x^c - d*v

Where k is the spring constant, c is a constant for the nonlinear property, and d is a damping coefficient. Is this typically correct?

If so, how would I integrate that into the solution? What exactly does the "v" term represent velocity of?

Would the "v" term be based on the velocity of the mass at that end? Or the velocity of one mass minus the other to get the "net" velocity? Would it be the same for both masses or different?

Thanks again. You've been super helpful.
 
Last edited:

FAQ: Calculating Final Positions & Velocities for M1, M2 & Spring After DeltaT

How do I calculate the final position of M1 and M2 after a given time interval?

To calculate the final position of M1 and M2 after a given time interval, you will need to use the equations of motion. The equations of motion for position are: x = x0 + v0t + 1/2at^2 for M1, and x = x0 + v0t + 1/2at^2 for M2. Here, x0 represents the initial position, v0 represents the initial velocity, a represents the acceleration, and t represents the time interval.

How do I calculate the final velocity of M1 and M2 after a given time interval?

To calculate the final velocity of M1 and M2 after a given time interval, you will need to use the equations of motion. The equations of motion for velocity are: v = v0 + at for M1, and v = v0 + at for M2. Here, v0 represents the initial velocity, a represents the acceleration, and t represents the time interval.

How do I calculate the final position of the spring after a given time interval?

To calculate the final position of the spring after a given time interval, you will need to use the equation x = x0 + v0t + 1/2at^2. Here, x0 represents the initial position, v0 represents the initial velocity, a represents the acceleration, and t represents the time interval. However, since the spring is not subject to acceleration, the final position will simply be equal to the initial position plus the displacement caused by the initial velocity.

What is the significance of calculating final positions and velocities for M1, M2, and the spring?

Calculating final positions and velocities for M1, M2, and the spring is important for understanding the motion of the system. It allows us to predict the position and velocity of each component at any given time, and to analyze the behavior of the system over time. This information is crucial for studying the dynamics of the system and making predictions about its future behavior.

Can I use these calculations to determine the energy of the system?

Yes, you can use these calculations to determine the energy of the system. The total energy of the system is the sum of the kinetic energy of M1 and M2, and the potential energy of the spring. The kinetic energy can be calculated using the equation KE = 1/2mv^2, where m is the mass and v is the velocity. The potential energy of the spring can be calculated using the equation PE = 1/2kx^2, where k is the spring constant and x is the displacement from the equilibrium position.

Back
Top