ode45 goes busy endlessly when using the sign of a state variable
2 views (last 30 days)
Show older comments
This term "- fr*Mass*9.8*sign(y(2))" makes ode45 busy forever specifically when using 'sign(y(2))'
I just need to make -fr*Mass*9.8=0 only when y(2)=0
Any explanations are highly welcomed.
[t,y] = myexercise;
function [t,y] = myexercise
tspan = [0 , 10];
y0 = [ 0 ; 5 ];
Mass = 1300;
CD = 0.3;
fr = 0.015;
Af = 1.6;
traction = @(t) (t>3&t<5)*5*t;
[t,y] = ode45(@(t,y) deceleration(t,y) , tspan , y0);
function yp = deceleration(t,y)
yp = [ ...
( -0.5*1.23*CD*Af*y(2)^2 + traction(t) - fr*Mass*9.8*sign(y(2)) )/Mass ...
More Answers (1)
Walter Roberson on 23 Apr 2021
You really should read ballode to see how to use event functions. https://www.mathworks.com/help/matlab/math/ode-event-location.html
Find more on Programming 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!