# Matlab ODE solvers: inconsistent time vector output

• MATLAB
• Pythagorean
In summary, the conversation discusses the issue of inconsistent time vectors produced by the ode113 function in MATLAB. It explores how using the imagesc function to compare plots of two sets of data with different time vectors leads to a mismatch on the axes. The solution to this issue is to input the time vector as [ti:dt:tf] instead of [ti tf]. The reason for this discrepancy and why the erroneous option is allowed is not clear.
Pythagorean
Gold Member
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.

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.

## 1. What is an "ODE solver" in Matlab?

An ODE solver in Matlab is a built-in function that solves ordinary differential equations (ODEs) numerically. It uses numerical methods to approximate the solution of the ODE at different time points.

## 2. Why am I getting an "inconsistent time vector output" when using an ODE solver in Matlab?

This error occurs when the time vector used in the ODE solver is not consistent with the solution output. This can happen if the time vector does not have the same number of points as the solution, or if the time vector is not evenly spaced.

## 3. How can I fix the "inconsistent time vector output" error in Matlab?

To fix this error, make sure that the time vector used in the ODE solver has the same number of points as the solution output. Additionally, the time vector should be evenly spaced. You can use the "linspace" function to create a time vector with evenly spaced points.

## 4. Can I use a non-uniform time vector in an ODE solver in Matlab?

Yes, you can use a non-uniform time vector in an ODE solver in Matlab. However, the time vector should still have the same number of points as the solution output, and the points should be in ascending order.

## 5. Why is it important to use a consistent time vector in an ODE solver in Matlab?

A consistent time vector is important because the ODE solver uses this time vector to determine the time points at which the solution is calculated. If the time vector is not consistent with the solution output, the solver will not be able to accurately calculate the solution at the desired time points, resulting in the "inconsistent time vector output" error.

Replies
2
Views
3K
Replies
1
Views
2K
Replies
1
Views
6K
Replies
1
Views
2K
Replies
2
Views
2K
Replies
1
Views
3K
Replies
1
Views
5K
Replies
1
Views
6K
Replies
2
Views
7K
Replies
2
Views
3K