MATLAB: Steady state criterion

steady stateurgent

Hi, I have a system of 4 ODE's and I solved it by using ode15s solver. But I want to stop simulations when the steady state is reached. Can someone tell me how to do it? I need to know this urgent!! Thanks and regards.

Best Answer

By "steady state" do you mean an equilibrium solution, or some non-equilibrium state that the solution settles to after an initial transient (eg a periodic solution)? If the latter, I don't know off the top of my head how you'd do that. If the former, you can use an event.
Write an event function, where, in your case the event should be something like the norm of the derivatives is zero (or, realistically, close to zero).
function [x,isterm,dir] = eventfun(t,y)
dy = copy-n-paste-from-your-ode-equation-function;
x = norm(dy) - 1e-5;
isterm = 1;
dir = 0; %or -1, doesn't matter
This defines an event for the integration to be whenever the norm of the derivatives is less than 10^-5. You can tweak that definition according to your knowledge of the system (and the likely values of the derivatives, in particular). The value of isterm will tell ode45 to stop integrating once the event occurs. The direction shouldn't matter, because there's really no way for the norm of the derivatives to increase to 1e-5.
Once you've done this, add the event to your ode options:
opts = odeset('Events',@eventfun);
Then call ode15s with that option structure. You can use an infinite integration time (or just very big), and the integration will stop when (if!) the event occurs:
[t,z] = ode15s(@odefun,[0 Inf],y0,opts);