Mishal Mohanlal

Compression only spring mass system

Mishal Mohanlal on 13 Nov 2023
Latest activity Reply by John D'Errico on 17 Nov 2023

Hi Guys
Posting this based on a thought I had, so I don't really ahve any code however I would like to know if the thought process is correct and/or relatively accurate.
Consider a simple spring mass system which only allows compression on the spring however when there is tension the mass should move without the effect of the spring distrupting it, thus the mass is just thrown vertically upwards.
The idea which I came up with for such a system is to have two sets of dfferential equations, one which represents the spring system and another which presents a mass in motion without the effects of the spring.
Please refer to the below basic outline of the code which I am proposing. I believe that this may produce relatively decent results. The code essentially checks if there is tension in the system if there is it then takes the last values from the spring mass differential equation and uses it as initial conditions for the differential equation with the mass moving wothout the effects of the spring, this process works in reverse also. The error which would exist is that the initial conditions applied to the system would include effects of the spring. Would there be a better way to code such behaviour?
function xp = statespace(t,x,f,c,k,m)
if (k*x(1)) positive #implying tension
**Use last time step as initial conditions**
**differential equation of a mass moving""
if x(1) negative #implying that the mass in now moving down therefore compression in spring
**Use last time step as initial conditions**
**differential equation for a spring mass system**
John D'Errico
John D'Errico on 17 Nov 2023
Asking this as a question on Answers instead would more likely get a useful response. But even there, this is only marginally a question about MATLAB. And that suggests you might more likely get a useful response by posting on a math forum like those at StackExchange.