- #1
ryan.j
Gold Member
- 9
- 0
How to use Matlab ODE solver "events" to stop an integration
I'm using Matlab's ODE solver (specifically ode15s) to solve a system of equations. The sum of the values of the equations eventually arrive at a steady state, but the time at which that occurs is dependent on several things, not known beforehand, and is one of the things I'm studying.
Consequently, I'd like to set tf in the call to the ODE solver to a value that I'm confident is beyond that time, and cause the integration to stop once a certain convergence criteria is met.
I have been unable to use 'Events' to do this effectively. Here is the function that is called by 'Events':
function [value,isterminal,direction] = Tprime_converger(t,T)
if length(t) == 1 %convergence can only be checked for t>1
value = 1;
else
value = abs(sum(T(length(t)-1,;)) - sum(T(length(t),;))) - 2*eps;
end
isterminal = 1;
direction = 0;
endAny help would be greatly appreciated.
Thanks.
-ryan
I'm using Matlab's ODE solver (specifically ode15s) to solve a system of equations. The sum of the values of the equations eventually arrive at a steady state, but the time at which that occurs is dependent on several things, not known beforehand, and is one of the things I'm studying.
Consequently, I'd like to set tf in the call to the ODE solver to a value that I'm confident is beyond that time, and cause the integration to stop once a certain convergence criteria is met.
I have been unable to use 'Events' to do this effectively. Here is the function that is called by 'Events':
function [value,isterminal,direction] = Tprime_converger(t,T)
if length(t) == 1 %convergence can only be checked for t>1
value = 1;
else
value = abs(sum(T(length(t)-1,;)) - sum(T(length(t),;))) - 2*eps;
end
isterminal = 1;
direction = 0;
endAny help would be greatly appreciated.
Thanks.
-ryan
Last edited: