MATLAB: What does this ODE error mean

entries must strictly increase or decreaseode error

Hello,
I don't understand why I am getting the following error:
Error using odearguments (line 87)
The entries in tspan must strictly increase or decrease.
Error in ode15s (line 150)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in trajecttest (line 39)
[T,S] = ode15s(@bdipuniodefun, tspan, icv);
For this for loop:
spart = [0.05 0.05 0.];
vpart = [-1.7585E+7 -1.7585E+7 0.];
tstep = 1E-7; %Defining time step

tfin = 1.1E-6; %Defining final time

intspan = [0:tstep:tfin]; %Total time span

[introw,intcol] = size(intspan);
W = zeros((3*intcol),6); %Generates matrix of zeros that the trajectory solver will populate later
for t = 0:1:intcol/2-1
x = spart(1);
y = spart(2);
z = spart(3);
vx = vpart(1);
vy = vpart(2);
vz = vpart(3);
icv = [x; y; z; vx; vy; vz];
%Time span
tspan = [intspan(2*t+1) intspan(2*t+2)/2 intspan(2*t+2)];
[T,S] = ode15s(@bdipuniodefun, tspan, icv);
[rownum,colnum] = size(S);
W((1+3*t):(3+3*t),(1:6)) = S;
vparts(1) = S(rownum,4);
vparts(2) = S(rownum,5);
vparts(3) = S(rownum,6);
sparts(1) = S(rownum,1);
sparts(2) = S(rownum,2);
sparts(3) = S(rownum,3);
end
The ODE solver accepts the inputs if there is no for loop invovled like this:
x = 0.05;
y = 0.05;
z = 0.;
vx = -1.7585E+7;
vy = -1.7585E+7;
vz = 0.;
tstep = 0.5E-8; %Defining time step
tfin = 1E-8; %Defining final time
intspan = [0:tstep:tfin]; %Total time span
[introw,intcol] = size(intspan);
icv = [x; y; z; vx; vy; vz]; %Format: [x; y; z; vz; vy; vz]
%Time Span (sec)
tspan = [intspan];
[T,W] = ode15s(@bdipuniodefun, tspan, icv);
[rownum,colnum] = size(W);
So why is it that adding the for loop causes this error? I know that the numbers that the "tspan" array is taking in are exactly the same since I tested it in the command window.

Best Answer

Hi,
the message is clear. See what happens if you inspect some lines of your code - therefore lets assume t=1 which is the second step of your loop in:
for t = 0:1:intcol/2-1
So with t=1 what do we get as tspan?
t = 1
tstep = 1E-7;
tfin = 1.1E-6;
intspan = [0:tstep:tfin];
tspan = [intspan(2.*t+1) intspan(2.*t+2)/2 intspan(2.*t+2)]
And the result is:
tspan =
1.0e-06 *
0.2000 0.1500 0.3000
The error message tells us:
Error using odearguments (line 87)
The entries in tspan must strictly increase or decrease.
Since your values first decrease and then increase you get this error.
Best regards
Stephan
Related Question