I have a function called initial which takes an argument funname and performs some integration. I wanted to pass multiple arguments to events function. So I did this:
odeopt=odeset('RelTol',1e-5,'AbsTol',1e-5,'Events',@(t,y) events(t,y,prm,funname));
fun=str2func(funname);
[t,y]=ode15s(fun,[0 3600],z,odeopt,prm);
prm is a structure and funname is a string.
This is the events function:
function [value,isterminal,direction] = events(t,y,prm,funname)
isterminal=1;
direction=0;
v=feval(funname,1,y,prm);
value=~all(v<1e-10);
funname is basically the ode function.
It still says too many input arguments.:
??? Error using ==> initial>@(t,y)events(t,y,prm,funname)
Too many input arguments.
Error in ==> odeevents at 29
eventValue = feval(eventFcn,t0,y0,eventArgs{:});
Error in ==> ode15s at 263
[haveEventFcn,eventFcn,eventArgs,valt,teout,yeout,ieout] = ...
Error in ==> initial at 10
[t,y]=ode15s(fun,[0 3600],z,odeopt,prm);
Can't be a problem of version (was using 7.6) because this post which addresses this issue was on 2006.
Any Idea?
Since
prmis passed as the last argument inode15s, it will result in theeventArgscell passing the value to the event handle. In other words, the lineis really doing
So if
prmis needed as an extra parameter in the ODE system, just makeprman input in the event handle:Also, since the events function is design to locate solutions passing through zeros, the
valueshould be a double such that MATLAB'ssignfunction works properly.