Matlab ODE solvers: inconsistent time vector output

Click For Summary
SUMMARY

The discussion focuses on the inconsistency of time vector outputs when using the Matlab ODE solver ode113 with different final time values. Users observed that even with identical initial conditions, the time vectors for solutions A and B diverged significantly, especially in stiff scenarios. The inconsistency arises when not specifying the time step (dt) in the time vector input, leading to unexpected results. The recommended approach for consistent time vector output is to explicitly define the time vector using the format [ti:dt:tf].

PREREQUISITES
  • Familiarity with Matlab ODE solvers, specifically ode113
  • Understanding of time vector definitions in numerical simulations
  • Knowledge of stiff vs. nonstiff differential equations
  • Experience with data visualization in Matlab using imagesc
NEXT STEPS
  • Research the differences between stiff and nonstiff ODE solvers in Matlab
  • Learn how to properly define time vectors in Matlab for ODE solvers
  • Explore the implications of using infinitesimal time steps in numerical simulations
  • Investigate best practices for visualizing ODE outputs in Matlab
USEFUL FOR

Matlab users, numerical analysts, and engineers working with ordinary differential equations who need to ensure consistent time vector outputs in their simulations.

Pythagorean
Science Advisor
Messages
4,430
Reaction score
327
If I produce two different sets of data with ode113, that are based on the exact same inputs, but one is longer than the other (i.e. tf is larger for one set, we'll call it A. Both A and B have the same ti).

If I compare the two plots with imagesc(A) (so that the vertical axis represents the indices themselves, which are the time steps of integration) everything is fine.

If I try to append the time vector with:

imagesc(xvalues,[0 (max(TA))]m A]

for both A and B (and TA and TB respectively), I suddenly have a mismatch on the axes. This indicates to me, that the time vectors are inconsistent, but why? What's the point of them then?

For a nonstiff solution (which ode113 is designed for) the difference is small (the same event is at TAe = 2220 and TBe = 2255

but in a different parameter point, where the solution terminates to stability rather quickly (stiff) the difference between TAe and TBe are on the order of thousands.
 
Physics news on Phys.org
Solved it (or at least mended...)

Matlab gives the option of inputing your time vector as [ti tf] OR as [ti:dt:tf]. Supposedly, if you don't specify dt, it just reports it's 'infinitesimal' time steps to the gnitty gritty detail. But that shouldn't lead to errors, should it? Well it does.

Apparently, ti:dt:tf is the way to do it for consistent T vector out. Not sure why they allow the erroneous option.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
7K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 1 ·
Replies
1
Views
6K
  • · Replies 2 ·
Replies
2
Views
7K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
10K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
1
Views
3K