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.
clccleartic %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.')tocfunction 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
Best Answer