ODE time vector plot does not correspond to the time vector values
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi! When I solve an ODE using ode23 I get a time vector and my state. In the time vector everything seems fine however when I plot the states agaisnt the time, the time appears completely skewed(it should be from 0-5 and its from 0-0.09.....)
How can I solve this?

1 Commento
Mike Croucher
il 13 Feb 2025
It is very difficult to help here without all of the code in a runnable form. We'll need your ode_arm function and it would also help a lot if you copied and pasted the code as text rather than a screenshot. That way, we can easily run it ourselves.
Risposte (2)
Star Strider
il 10 Feb 2025
We don’t have your ‘ode_arm’ function, however it may be that ode23 is encountering a singularity (
) at about 0.9 time units, and then stops, probably also throwing an error message.
0 Commenti
Sam Chak
il 13 Feb 2025
Spostato: Walter Roberson
il 13 Feb 2025
Hi @Afonso
The simulation will stop when the ODE solver encounters NaN or Inf situations, or when the solver can no longer reduce the integration step size. Here is an example of an ODE involving the logarithm function. Ideally, the state should reach zero and stop, similar to the water tank level, where negative values are undefined.
oldparam = sympref("HeavisideAtOrigin", 1);
%% System for Cases 1 & 3
function dx = ode1(t, x)
b = 1.5;
dx = (x.^(2 - b)).*log(x);
end
%% System for Case 2
function dx = ode2(t, x)
b = 1.5;
dx = ((x.*heaviside(x)).^(2 - b)).*log(x.*heaviside(x));
end
%% Stop simulation when the state x reaches 0
function [position,isterminal,direction] = touchZeroEventFcn(t, x)
position = x; % The state variable that we want to be zero
isterminal = 1; % Halt integration
direction = -1; % The zero can be approached when x is decreasing
end
%% Settings
tspan = linspace(0, 3, 3001);
x0 = 0.9;
options = odeset('Events', @touchZeroEventFcn);
%% Case 1: Original dynamics without EventFcn
[t, x] = ode45(@ode1, tspan, x0);
plot(t, x), grid on, xlabel('Time')
%% Case 2: Modified for non-negative value of x
[t, x] = ode45(@ode2, tspan, x0);
plot(t, x), grid on, xlabel('Time')
%% Case 3: Original dynamics with EventFcn
[t, x] = ode45(@ode1, tspan, x0, options);
plot(t, x), grid on, xlabel('Time')
0 Commenti
Vedere anche
Categorie
Scopri di più su Ordinary Differential Equations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

