Hi all,(adsbygoogle = window.adsbygoogle || []).push({});

I'm having some issues with Matlab.

I'm running ode45 inside a function which is called repeatedly in a finite loop. As it is being called, Matlab is plotting and saving the data externally.

Here's a quick pseudo-code

This is all well and good, but as soon as ode45 is unable to solve a DE (were the solution does not converge), Matlab gets stuck in an (almost?) infinite loop repeatedly calling ode45 until a solution is found. I can obviously stop this using "Ctrl-C" but this will screw up the data I'm trying to gather and plot.Code (Text):

func1 ( )

loop {

data = func2 (variables)

save data

plot data

}

end func1

func2 ( input vars)

--

--

options = odeset('events',@missile_event, 'RelTol',1e-14);

[t, x, te, xe, ie] = ode45 ( @de, [t0 tf], x0, options );

--

--

plot x vs t etc..

--

--

return data;

end

Is there a way to get ode45 to return some value if it takes more than x seconds to find a solution? Or perhaps get it to stop executing func2 and resume func1 (see above code).

I am already using the events function to stop ode45 as soon as it has converged close to the solution.

i.e,

Thanks in advance.Code (Text):

function [lookfor stop direction ] = missile_event(t, x)

r = sqrt(x(1)^2 + x(2)^2) ;

lookfor = r - 0.1;

stop = 1;

direction = 0;

**Physics Forums | Science Articles, Homework Help, Discussion**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Stoping a specific matlab function

**Physics Forums | Science Articles, Homework Help, Discussion**