Reputation: 79
I'm having a problem with the events locator in Matlab. I'm looking at a coupled ODE which represents two interfaces going unstable. I have no problems solving it, all I'm trying to do is find the radius (R_2v
) when a certain amplitude (10^2
) is reached for each interface. Av
is a matrix of two column vectors, which are the radial (or time) evolutions of the amplitudes of the two interfaces.
The problem being reported is 'Nonscalar arrays of function handles are not allowed; use cell arrays instead.'
n.b. 2
, mu_2_0
, mu_2_f
, R_gel
, and V
are all parameters for funsys
options = odeset('Events',[@eventsA,@eventsB]);
[R_2v,Av,R_2Ae,Ae,Aie,R_2Be,Be,Bie] = ode15s(@funsys_back_Vg1,[1 R_max],[1;1],options,2,mu_2_0,mu_2_f,R_gel,V);
function [valueA,isterminalA,directionA] = eventsA(R_2v,Av)
valueA = Av(1) - 10^2;
isterminalA = 0;
directionA = 0;
function [valueB,isterminalB,directionB] = eventsB(R_2v,Av)
valueB = Av(2) - 10^2;
isterminalB = 0;
directionB = 0;
Upvotes: 1
Views: 607
Reputation: 18484
The error is pretty clear: arrays of function handles aren't allowed in Matlab. You may be able to use cell arrays in some cases. See this question. I'm not sure that the ODE suite functions support the evaluation of separate events functions in a cell array (R2013b gives me an error).
However, I'm not sure you need to be doing what you're doing. Event functions can be rather complex and can be written to do many things including detecting multiple events. See this answer of mine for example. Or this one. You should be able to write just one function:
function [value,isterminal,direction] = events(R_2v,Av)
value = Av - 10^2;
isterminal = 0;
direction = 0;
And then your Aie
(see below) will tell you the index, 1 or 2, of AV
that triggered a particular event at R_2Ae
and Ae
.
options = odeset('Events',@events);
fun = @(R_2v,Av)funsys_back_Vg1(R_2v,Av,2,mu_2_0,mu_2_f,R_gel,V);
[R_2v,Av,R_2Ae,Ae,Aie] = ode15s(fun,[1 R_max],[1;1],options);
You had too many output arguments so I removed the extra ones. I also "fixed" your call to ode15s
to pass parameter via the anonymous function, which has be the preferred and most efficient way to do things for many years now. I may have messed things up relative to you your actual code though because you didn't provide a working example.
Upvotes: 1