ODE time vector plot does not correspond to the time vector values

조회 수: 9 (최근 30일)
Afonso
Afonso 2025년 2월 10일
이동: Walter Roberson 2025년 2월 13일
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
Mike Croucher
Mike Croucher 2025년 2월 13일
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.

댓글을 달려면 로그인하십시오.

답변 (2개)

Star Strider
Star Strider 2025년 2월 10일
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.

Sam Chak
Sam Chak 2025년 2월 13일
이동: Walter Roberson 2025년 2월 13일
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')
Warning: Imaginary parts of complex X and/or Y arguments ignored.
%% 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);
Error using odezero (line 49)
odezero: an event disappeared (internal error)

Error in ode45 (line 393)
odezero(@ntrp45,eventFcn,eventArgs,valt,t,y,tnew,ynew,t0,h,f,idxNonNegative);
plot(t, x), grid on, xlabel('Time')

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by