State-Space model of spring-mass system

AI Thread Summary
The discussion focuses on deriving the state-space model for a spring-mass-damper system, neglecting external forces like friction and gravity. The equations of motion are established using Newton's law, leading to a state-space representation with defined matrices A, B, C, and D. A MATLAB simulation is utilized to test the model with a sine-wave input, revealing an unexpected initial slow-frequency response alongside the expected output. Participants discuss the transient behavior observed, attributing it to the combination of natural and forced responses, and confirm the accuracy of the state-space implementation. The conversation concludes with reflections on the choice of state vector and the effectiveness of the simulation method used.
Number2Pencil
Messages
204
Reaction score
1

Homework Statement



Derive the state space model of a spring-mass-damper system. Neglect friction, wind resistance, etc. Neglect the force of gravity. Assume the spring's equilibrium point is at y=0 and there is an arbitrary

Homework Equations



[X'] = AX + BU
y = CX + DU

The Attempt at a Solution



Newton's law:
<br /> F_{NET}=ma = m\ddot{y}<br />

The sum is an arbitrary input force, u, the recoil force that works in the direction towards the spring's equilibrium point, and the dampening coefficient which works against velocity:
<br /> u-c\dot{y}-ky=m\ddot{y}<br />

Rearranging terms:
<br /> \ddot{y} = \frac{1}{m}u - \frac{c}{m}\dot{y}-\frac{k}{m}y<br />

Setting up state-space integral form:
<br /> y = \int( -\frac{c}{m}y + \int (-\frac{k}{m}y + \frac{1}{m}u) dt) dt&#039;<br />I call the entire outer integral X1 and the inner integral X2, using this nomenclature:

<br /> y = X_1<br />

<br /> \dot{X_1} = -\frac{c}{m}X_1 + X_2<br />

<br /> \dot{X_2} = -\frac{k}{m}X1 + \frac{1}{m}u<br />

<br /> \left[<br /> \begin{array}{cc}<br /> \dot{X1}\\<br /> \dot{X2}\\<br /> \end{array}<br /> \right] = \left[<br /> \begin{array}{cc}<br /> -\frac{c}{m}&amp;1\\<br /> -\frac{k}{m}&amp;0\\<br /> \end{array}<br /> \right]<br /> \left[<br /> \begin{array}{cc}<br /> X1\\<br /> X2\\<br /> \end{array}<br /> \right] + <br /> \left[<br /> \begin{array}{cc}<br /> 0\\<br /> \frac{1}{m}<br /> \end{array}<br /> \right]u<br /><br /> y = <br /> \left[<br /> \begin{array}{cc}<br /> 1&amp;0<br /> \end{array}<br /> \right]\left[<br /> \begin{array}{cc}<br /> X1\\<br /> X2\\<br /> \end{array}<br /> \right] + 0u<br />So now I wanted to test it using a sine-wave input force to the system. Intuitively, I would expect a sine-wave output as the mass should be bobbing up and down on the spring. What I actually get is at the beginning, there is a much slower frequency component than my input sine-wave, as well as the input-frequency component, almost like the sum of two different sine waves. This slower-component then dies off and I am left with something that matches more closely to my input sine-wave. What is strange is that during that initial slow-frequency response, the amplitude gets quite large, much larger than when it is finally settled.

My question is: What is going on? Is my intuition just wrong and truly this mass has a large initial "push"? Is there an error in my state-space model? Or something I am forgetting to take into account. I tested that having a zero-force input, the spring remains at zero.

Edit: Also, my test constant values were m= 0.72kg, k = 0.5, c =1
 
Last edited:
Physics news on Phys.org
Seems fine to me, you're solving it numerically I guess? MATLAB/Simulink?

Maybe you could post the code you're running etc.

I'm off to bed..
 
Sure. Here is the MATLAB code I used to produce the time-domain plots. I had trouble with simulink...so I really can't verify if this is implementing state-space correctly.

Code:
%Physical Inputs
mass = 0.72;
springK = 1;
damperC = 0.5;

%Input Parameters
sineWaveAmp = 1;
sineWaveFreq = 0.5;

%Timing Parameters
timeStart=0;
timeStop=50;
dt = 0.001;

%Create State-Space Matrices
A=[-damperC/mass, 1; -springK/mass, 0];
B=[0; 1/mass];
C=[1,0];
D=[0];
stateSpace = [0;0];

%Loop Variables
numSamps = (timeStop-timeStart)/dt;
currTime = timeStart;

%Create Storage Elements
posVals(1:numSamps) = 0;
timeVals(1:numSamps) = 0;
u(1:numSamps) = 0;


%Step 1, create sine wave input values
sineWavePeriod = 1/sineWaveFreq;
for n=1:numSamps
	cycleTime = mod(currTime,sineWavePeriod);
	u(n) = sineWaveAmp*sin(2*pi*sineWaveFreq*cycleTime);
	currTime = currTime + dt;
end

%Step 2, simulate state space
currTime = timeStart;
for n = 1:numSamps

	% Y = Cx' + Du
	posVals(n) = (C*stateSpace)+(D*u(n));
	integratorInput = (A*stateSpace)+(B*u(n));
	
	%Integrate. x' = int(A*x + B*u)
	stateSpace = stateSpace+(integratorInput*dt);

	%Prepare next iteration
	timeVals(n) = currTime;
	currTime = currTime + dt;
end


%Step 3, plot
figure(1);
plot(timeVals,posVals);
title('Mass-Spring Position over time');
ylabel('Meters');
xlabel('Seconds');

figure(2);
plot(timeVals,u);
title('Mass-Spring External Input over time');
ylabel('N');
xlabel('Seconds');
 
I did a quick comparison of your solution with that of the Dormand-Prince solver in the MATLAB Control Systems Toolbox and everything checks out, so good job :smile:

The transient you see at the start is the sum of the decaying natural response and the forced response.

Is there a reason for using that particular state vector? I'd have thought that \begin{bmatrix}y &amp; \dot{y}\end{bmatrix}^T would be more convenient.
 
Alright, thanks miles. I guess my intuition was just off :p

For choosing that state vector, it's simply a product of me being very methodical on solving these kinds of things.

I'll check out this Dormand-Prince toolbox you mentioned, thank again
 
Back
Top