Prev: Truncating/getting rid of values in a vector
Next: Finding Surface Area of Cluster of Ones in 3D Matrix
From: Eike Wolgast on 26 Mar 2010 04:46 Hello, for solving a differntial equation I'm using ode15i. During the integration 'outputfcn' computes further values. When using tspan = [istart iend] the size of 't' passed to the output function is always equal to one. But for tspan = [istart : delta : iend] the size of 't' passed to the output function is 2, so there occurs an error in my outputfcn. I'm talking just about the values of t for ~strcmp(flag, 'init') && ~strcmp(flag, 'done'). I hope somebody can help me how to handle outputfcn for length(tspan) > 2 Thanks Eike
From: Steven Lord on 26 Mar 2010 10:08 "Eike Wolgast" <eike.wolgast(a)googlemail.com> wrote in message news:afa91cae-9d94-46d5-abf1-b59c07f9edfa(a)q23g2000yqd.googlegroups.com... > Hello, > > for solving a differntial equation I'm using ode15i. During the > integration 'outputfcn' computes further values. When using tspan = > [istart iend] the size of 't' passed to the output function is always > equal to one. > > But for tspan = [istart : delta : iend] the size of 't' passed to the > output function is 2, so there occurs an error in my outputfcn. > > I'm talking just about the values of t for ~strcmp(flag, 'init') && > ~strcmp(flag, 'done'). > > I hope somebody can help me how to handle outputfcn for length(tspan) >> 2 The documentation for the OutputFcn option in the reference page for ODESET indicates when t could be nonscalar: http://www.mathworks.com/access/helpdesk/help/techdoc/ref/odeset.html#f92-1016858 Basically, what I believe it's describing is the situation where the ODE solver takes multiple steps between two times at which you've requested (via tspan) output. For example, if you requested that the ODE solver use a tspan of 0:1:10 and the solver took steps to t = 0.2, t = 0.4, t = 0.5, t = 0.7, and t = 0.9 before stepping past t = 1, I believe your OutputFcn will be called with a 5-element t vector ([0.2, 0.4, 0.5, 0.7, 0.9]) and a 5-column y matrix. How to handle this nonscalar t value is up to you, depending on what you want your OutputFcn to do. I would likely loop over the elements of t and call a helper function to generate whatever output I wanted using that element of t and the corresponding column of y. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
From: Eike Wolgast on 29 Mar 2010 04:42
Hello Steve, this is what I also thougt. But when I call ode15i with tspan = 1:1:10, the values passed to the outputfcn are for example t = [3 4], so there are no steps in between. As a workaround I used 'MaxStep', which yields me to the points I need. Eike |