What kind of solver should I use for a non-continuous function?
Show older comments
I've been using ode45 to solve for a particular system that is easy to describe as a mass on a linear spring with no friction or other types of properties. It's a pretty simple system, but I want to implement it as being unable to become a negative length, but at the same time conserve energy (like an elastic bounce). I implemented it sort of like:
s = X(1);
v = X(2);
if s <= MinimumSpringLength
v = abs(v)
end
~~~
Xdot = [ v, acceleration ]
My problem is, instead of actually reversing the velocity, my position hovers at MinimumSpringLength while my velocity crawls up from its initial negative state, sort of like:
X = [ 4 -4
2 -3
2 -1
2 1
3 3 ]
These are just values I made up, but the point is that if MinimumSpringLength = 2, my position will go down to 2 and hover at 2, but has to wait for velocity to gradually accelerate to a positive. Instead, I would have preferred something like:
X = [ 4 -4
2 -3
2.5 3
4 4 ]
Is this possible to get with ode45?
Accepted Answer
More Answers (0)
Categories
Find more on Programming 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!