4
$\begingroup$

I want to solve a system of differential equations using ode45 , for (many) parameters in MATLAB to investigate the behavior of solutions with coefficients of the equation .I want to find the parameters for which the solution absolute value doesn't get larger than some given number . The script has a for loop and solves the system for given parameters one after another(in some limited time span (independent variable is time)) .

Now,my question is that "how can I set a condition on ode45 to "detect" automatically if the solution for some parameter gets larger than that (given) value", so I can automatically find those parameters for which the solution gets larger than the given value, by running the for loop once?

$\endgroup$
  • 6
    $\begingroup$ You can attach your own monitoring function to ode45, have you consulted the documentation for the routine? $\endgroup$ – Aron Ahmadia Feb 26 '13 at 14:42
2
$\begingroup$

As described in the documentation, one can set the 'Event' property using odeset. The following (in an m-file named ode45EventTest.m) provides a barebones example of your use case, with the trivial ODE $\frac{dx}{dt} = 1, x(0)=0$:

function ode45EventTest
for tMax = [2, 20]
    [~,~,~,~,IE] = ode45(@(t,y) 1, [0 tMax],0,odeset('Event',@myEvent));
    if(isempty(IE))
        fprintf('Threshold not exceeded for tMax = %g\n',tMax);
    else
        fprintf('Threshold exceeded for tMax = %g\n',tMax); 
    end
end

end

function [value,isterminal,direction] = myEvent(~,y)
threshold  = 10;
r          = double(abs(y) > threshold);
value      = r;
isterminal = r;
direction  = 0;
end
$\endgroup$
0
$\begingroup$

I would put a switch in the target function, and allow it to write to a file the parameters of interest then switch the output falsely such that the ode45 truncates the run, possibly with a NaN or other.

Do you need some pseudocode? If so could you provide pseudocode that has some of your info structure and a derivative function that you find useful?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.