2

I'm working on the numerical integration to a discontinuous ODE in MATLAB, but I'm not getting the results I intended to get.
I have a 2-dof system of two masses connected via springs. (see 2-dof system)

My function in MATLAB is of the form:

function [ xdot ] = two_springs(t, x, m1, m2, c, g, k)
% x(1) = x1
% x(2) = x1'
% x(3) = x2
% x(4) = x2'
delta = max(x(3,1) - x(1,1), 0); % (Discontinuous)
F = k * delta^(3 / 2);
xdot(1,1) = x(2,1);
xdot(2,1) = (-F + m1 * g) / m1;
xdot(3,1) = x(4,1);
xdot(4,1) = (F - c * x(3,1) + m2 * g) / m2;
end

Afterwards I plot force F over time.

But no matter which solver I use ( ode45, ode23, ode113, ode15s, ode23s,...) I get a failure because the step size was reduced below the smallest value allowed. The topic: MATLAB- ode solver: Unable to meet integration tolerances did unfortunately not help me.

Does anyone have an idea what else I could try?

Thank you very much for your help!
tine-lore

Community
  • 1
  • 1
tine-lore
  • 21
  • 2
  • 2
    ODEs by their very nature assume a certain degree of continuity. Inserting a discontinuity will result in a [stiff](http://en.wikipedia.org/wiki/Stiff_equation) system that can be difficult to integrate numerically and even lead to errors like you have. Instead, you should simulate the two cases and use [event detection](http://mathworks.com/help/matlab/math/ode-event-location.html) to switch between them. See [this](http://stackoverflow.com/q/13755352/2278029) or [this](http://stackoverflow.com/a/22819748/2278029). – horchler Mar 28 '16 at 17:16
  • Thank you, I will have a look at that! – tine-lore Mar 28 '16 at 18:34
  • Your function is continuous, just not differentiable. The maximum of continuous functions is continuous. – Lutz Lehmann Mar 28 '16 at 20:01
  • What can you say about the part of the solution that it does compute? What kind of singularity do you observe at the break-point? – Lutz Lehmann Mar 29 '16 at 21:33

0 Answers0