Asymmetric spring with two different stiffnesses
Show older comments
I'm trying to model a mass spring damper system and I want to describe the spring with two different values of k in bump and in rebound. I wrote the system made by the free body equations and what now what I want to do is to solve it with ode45, but I cannot find the way to compare y(t) and y(t-1) and to understand what stifness I have to use. I tried to define a vector in the function I wrote to solve the differential system, and the idea was to write in the i position the current value of the displacement but I don't know the lenght of the vector and at the beginning of every new iteration it goes zeros(n,1). Is there any solution to save and compare different values from different iterations in this case?
5 Comments
Alan Stevens
on 6 Jul 2020
Upload what you have done so far.
Paolo Alloisio
on 6 Jul 2020
darova
on 6 Jul 2020
Maybe you are looking for persistent
Paolo Alloisio
on 6 Jul 2020
darova
on 6 Jul 2020
remember about clearing persistent variable before each run
clear functions % clear persistent variables from functions
Accepted Answer
More Answers (1)
Bjorn Gustavsson
on 6 Jul 2020
ODE45 takes a function, f(t,y), describing the differential equation.
You have a differential equation something like this
where k has one value if the spring moves in one direction (dy/dy < 0) and another value when the spring moves in the other direction - how you connect those forces at the points where the velocity is zero I do not know.
ODE45 takes functions describing first-order odes, so the way to implement equations of motions is to convert the second-order ODE to 2 coupled first-order odes. That way we get something like this:
function dydtdvdt = your_ode(t,y)
k_p = 12; % Or whatever your spring-constants over mass are...
k_n = 10;
if y(2) > 0
a = -k_p * y(1);
else
a = -k_n * y(1);
end
dydtdvdt = [y(2);
a];
end
Then you call ODE45 with this function the time-period of interest and the initial conditions (y(0) and v(0)), and then you get the numerical solution to your ODE. If you have a damper you'll have to add that force-term too.
HTH
9 Comments
Paolo Alloisio
on 6 Jul 2020
Bjorn Gustavsson
on 6 Jul 2020
OK, then I misinterpreted your description. I read your description as if you had one spring-constant when the velocity, y(2), was in different directions. If you want the spring-constant different depending on whether the spring is extended or compressed you have to make the test for that - i.e. y(1).
Paolo Alloisio
on 6 Jul 2020
Bjorn Gustavsson
on 6 Jul 2020
But then you want my initial solution. If the velocity is positive then the spring is stretching (possibly from a compressed state, but if the velocity is positive you know that the spring-length will increase), and the other way around.
You cannot use persistent here since there is no guarantee that ODE45 will only ever evaluate your ode-function in increasing order with constant step-size. Typically it might have to refine its step-size around points where the trajectory is "interesting".
Paolo Alloisio
on 6 Jul 2020
Bjorn Gustavsson
on 6 Jul 2020
There's two points you have to make clear. The first is what your force is supposed to be as a function of
and
. Write it clearly as equations, then you can think about how to implement them. The second is that you have to familiarise yourself with ODE-integrating methods, for example Runge-Kutta (both the basics and the adaptive section).
Small point to make is that you will only get "a harmonic response" if your acceleration term is of the form:
with k constant if you start to modify the constant with respect to sign of y or
you will have a more complex response.
Paolo Alloisio
on 7 Jul 2020
Bjorn Gustavsson
on 8 Jul 2020
So that characteristic you should be able to implement as a combination of checks on the velocity, and the sign of y, you get four cases to check for.
However, this model will have an assymetry around the turning-points where
changes sign. That is where the |ky| will be at its maximum. How you see this connected to the physics of the springs is up to you, but to me it looks peculiar.
changes sign. That is where the |ky| will be at its maximum. How you see this connected to the physics of the springs is up to you, but to me it looks peculiar.ODE45 uses a 4-5 version of Runge-Kutta, so the Wikipedia-page should be a good introduction. If you need to get into the details the function is implemented in plain .m-code so you can read it, there are also references to publications in the ode45.m file.
Paolo Alloisio
on 8 Jul 2020
Categories
Find more on General Applications in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





