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
답변 (1개)
Frederik Falk
2018년 3월 24일
0 개 추천
Did you try changing the tolerence of error of ode45? Try googling TolSet
카테고리
도움말 센터 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!