OutputFcn option in odesolver ode15s behaving strangely??!
2 views (last 30 days)
Show older comments
I am using ode15s to integrate a set of ODEs and using the OutputFcn option to move some extra data into arrays at the end of each successful time step. The call statement is
[t,y] = ode15s(@f,tspan,y0,options)
with
options = odeset('OutputFcn',@f2);
Function f2 is supposed to be called at the end of each step in tspan (which has multiple points). It looks like this:
function status = f2(t,y,flag)
% FACE value function
switch flag
case 'init'
face(1,1)=y1feed; face(1,2)=yinitial;
face(1,3:6)=1.0;
otherwise
ij=ij+1;
face(ij,1)=y_face(1); face(ij,2)=y_face(N+1);
face(ij,3)=c_face(1); face(ij,4)=c_face(N+1);
face(ij,5)=t_face(1); face(ij,6)=t_face(N+1);
end
status=0;
end
Its basically just moving data around which I need to save for later (I dont want to recreate the y_face, c_face and t_face arrays). It works fine for a while (about half of the integration period) and when I look in f2 in debug mode it is bringing in t (a 1x1) and y (a Nx1) but then for no apparent reason it starts to bring in multiple columns of t and Y which dont correspond to the successful time step. Has anyone seen this behaviour before? Is it related to ode15s taking variable step times etc. I have tried to use ode45 but that does not run (problem is stiff).
0 Comments
Answers (1)
Paul
on 17 Apr 2012
Hi Paul,
I'm pretty sure you defined a timestep within your tspan. See Steve's response to a similar problem in this topic
I ran into the same problem as I use global variables to save some of the derived variables in my ODE to my outputfcn. Unfortunately, these are only calculated at the timesteps the ODE actually used and not interpolated. Therefore, the variables in my output function will have different sizes. I have no idea how to automatically interpolate these values as well, but you could do it manually afterwards of course.
0 Comments
See Also
Categories
Find more on Assembly in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!