Mercurial > octave-nkf
comparison scripts/ode/private/integrate_adaptive.m @ 20636:43822bda4f65
fix indexing bug introduced with a22d8a2eb0e5
* scripts/ode/private/integrate_adaptive.m: add offset to indices
into tspan.
author | Carlo de Falco <carlo.defalco@polimi.it> |
---|---|
date | Sun, 11 Oct 2015 19:20:27 +0200 |
parents | a22d8a2eb0e5 |
children | 756b052037fb |
comparison
equal
deleted
inserted
replaced
20635:a22d8a2eb0e5 | 20636:43822bda4f65 |
---|---|
138 ## if output time steps are fixed | 138 ## if output time steps are fixed |
139 if (fixed_times) | 139 if (fixed_times) |
140 | 140 |
141 t_caught = find ((tspan(iout:end) > t_old) | 141 t_caught = find ((tspan(iout:end) > t_old) |
142 & (tspan(iout:end) <= t_new)); | 142 & (tspan(iout:end) <= t_new)); |
143 t_caught = t_caught + iout - 1; | |
144 | |
143 if (! isempty (t_caught)) | 145 if (! isempty (t_caught)) |
144 t(t_caught) = tspan(t_caught); | 146 t(t_caught) = tspan(t_caught); |
145 iout = max (t_caught); | 147 iout = max (t_caught); |
146 x(:, t_caught) = interpolate ([t_old, t_new], [x_old, x_new], | 148 x(:, t_caught) = ... |
147 t(t_caught)); | 149 ode_rk_interpolate (order, [t_old t_new], [x_old x_new], |
150 tspan(t_caught), new_k_vals, dt, | |
151 options.vfunarguments{:}); | |
148 | 152 |
149 istep++; | 153 istep++; |
150 | 154 |
151 if (options.vhaveeventfunction) | 155 if (options.vhaveeventfunction) |
152 ## Call event on each dense output timestep. | 156 ## Call event on each dense output timestep. |
272 endwhile | 276 endwhile |
273 | 277 |
274 ## Check if integration of the ode has been successful | 278 ## Check if integration of the ode has been successful |
275 if (dir * t(end) < dir * tspan(end)) | 279 if (dir * t(end) < dir * tspan(end)) |
276 if (solution.vunhandledtermination == true) | 280 if (solution.vunhandledtermination == true) |
277 error ("integrate_adaptive: InvalidArgument", | 281 error ("integrate_adaptive:unexpected_termination", |
278 ["Solving has not been successful. The iterative", | 282 [" Solving has not been successful. The iterative", |
279 " integration loop exited at time t = %f", | 283 " integration loop exited at time t = %f", |
280 " before endpoint at tend = %f was reached. This may", | 284 " before endpoint at tend = %f was reached. This may", |
281 " happen if the stepsize grows too small. ", | 285 " happen if the stepsize grows too small. ", |
282 " Try to reduce the value of 'InitialStep'", | 286 " Try to reduce the value of 'InitialStep'", |
283 " and/or 'MaxStep' with the command 'odeset'.\n"], | 287 " and/or 'MaxStep' with the command 'odeset'.\n"], |
284 t(end), tspan(end)); | 288 t(end), tspan(end)); |
285 else | 289 else |
286 warning ("integrate_adaptive: InvalidArgument", | 290 warning ("integrate_adaptive:unexpected_termination", |
287 ["Solver has been stopped by a call of 'break' in the main", | 291 ["Solver has been stopped by a call of 'break' in the main", |
288 " iteration loop at time t = %f before endpoint at tend = %f ", | 292 " iteration loop at time t = %f before endpoint at tend = %f ", |
289 " was reached. This may happen because the @odeplot function", | 293 " was reached. This may happen because the @odeplot function", |
290 " returned 'true' or the @event function returned", | 294 " returned 'true' or the @event function returned", |
291 " 'true'.\n"], | 295 " 'true'.\n"], |
292 t(end), tspan(end)); | 296 t(end), tspan(end)); |
293 endif | 297 endif |
294 endif | 298 endif |
295 | 299 |
296 ## Remove not-requested values of time and solution | 300 ## Set up return structure |
297 solution.t = t; | 301 solution.t = t(:); |
298 solution.x = x.'; | 302 solution.x = x.'; |
299 | 303 |
300 endfunction | 304 endfunction |
301 | 305 |