Function ode45 event handler is missing event

I'm writing a function to plot the position and velocity of a charged particle being affected by gravity and a charged plate beneath it. I have the acceleration formula, so I'm using ode45 to solve the differential equation. In addition the function must also catch when the particle hits the plate and restart the ode45 function from that time at a new initial position and velocity. When testing the case where the particle has 0 charge, the function catches when it bounces about 24 times; however, after the last bounce the ode45 event handler doesn't seem to catch when position is 0 and the particle falls through the plate. Any ideas on why the event function seems to stop working?
Here's the loop that solves the equation:
while isempty(t) || t(end) < 100
[t1, z1] = ode45(@odefun, [t0, 100], [z0, v0], options);
t = [t; t1]; %time
z = [z; z1]; %Position and velocity matric
z0 = 0; %new initial position
v0 = abs(z(end, 2).*cR); %new initial velocity
t0 = t(end); %new start time
nBounce = nBounce + 1; %Track the number of bounces
if v0 < 1e-4 %Break if initial veloctiy goes below a certain tolerance
break
end
end

Answers (1)

Did you try changing the tolerence of error of ode45? Try googling TolSet

Tags

Asked:

on 22 Apr 2016

Answered:

on 24 Mar 2018

Community Treasure Hunt

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

Start Hunting!