confusing ode suits for solving discontinuous odes

12 次查看(过去 30 天)
Hi all! when I use ode suits with event option to deal with the problem about discontinuous odes, here is a ball bouncing on the ground, why are the points of the solution not evenly distributed.
Below is my code.
clc
clear
tic
%options=odeset('Events',@Events,'AbsTol',1e-8,'RelTol',1e-8);
options=odeset('Events',@Events);
y0 = [1;0];
[tout,yout]=ode45(@Tq,[0,7], y0,options);
subplot(1,2,1)
plot(tout,yout(:,1),'k')
subplot(1,2,2)
plot(tout,yout(:,1),'k.')
toc
function f=Tq(~,y)
if y(1)>0
u=0;
else
u=30*y(2)+1e5*y(1);
end
f=[y(2); -9.81-u];
end
function [g,isterminal,direction]=Events(t,y)
g=y(1);
isterminal=0;
direction=0;
end
  1 个评论
Bobby Fischer
Bobby Fischer 2021-1-15
It was nice to see the 'Events' part which I didn't know about.
I could be wrong, but it seems to me one has two options: either you let ode45 see the 'events' part and then don't get equally spaced points, or you tell ode45 the specific times at which you want the calculations to be made, but then don't get to be more acute at the points which would need it the most. In the second case you can always give a lot of points and that would get things done, but that would be less elegant.
I don't know what's your opinion about this.

请先登录,再进行评论。

采纳的回答

Mischa Kim
Mischa Kim 2021-1-15
编辑:Mischa Kim 2021-1-15
Hi, this is because the integrator, ode45, adjusts the integration step size. Broadly speaking where the dynamics is more complex the integrator typically decreases the step size (e.g. when the ball hits the ground), when the dynamics is less complex the integrator tries to increase step size and thereby reduce compute time. See the documentation here for more information. If equally spaced data points are important to you, you can adjust the tspan vector accordingly.

更多回答(1 个)

汉武 沈
汉武 沈 2021-1-15
Okay, grateful for your help!

类别

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