ODE45, simple events
Show older comments
I'm trying to understand 'Events" and how to trigger them. But I'm not quite understanding how it works because my graph still runs past y = 0, and when I output the [t,y,te,ye,ie], I get empty sets. When I change check to = (y>=0), I get some negative number for ye.
h = 1000;
g = 9.8;
k = 1/10;
y0 = h;
t0 = 0; tfinal = 30;
tspan = [t0,tfinal];
options = odeset('Events',@landing);
v = @(t,y) -g*t;
ode45(v,tspan,y0,options);
function [check,stop,direction]=landing(t,y)
check = (y~=0);
stop = 1;
direction=0;
end
If somebody help me with what I'm missing. Thanks. I'd like the the integration to stop when it hits the ground. (ignore unused variables, I actually have to add drag force to this equation with k but I'm trying to learn the basics first).
Accepted Answer
More Answers (1)
Alex Mcaulley
on 29 Oct 2019
function [check,stop,direction]=landing(t,y)
check = y;
stop = 1;
direction=0;
end
1 Comment
Stevon Kline
on 29 Oct 2019
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!