ode45 goes busy endlessly when using the sign of a state variable

1 回表示 (過去 30 日間)
Diaa
Diaa 2021 年 4 月 23 日
回答済み: Diaa 2021 年 4 月 23 日
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.
clearvars
clc
close all
[t,y] = myexercise;
plot(t,y(:,2))
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 = [ ...
y(2) ;...
( -0.5*1.23*CD*Af*y(2)^2 + traction(t) - fr*Mass*9.8*sign(y(2)) )/Mass ...
];
end
end
  2 件のコメント
James Tursa
James Tursa 2021 年 4 月 23 日
Please explain the physical problem and post the differential equation you are trying to solve so we can understand why you think you need the sign function.
Diaa
Diaa 2021 年 4 月 23 日
It is a moving vehicle subjected to traction force and resistive aerodynamic drag and rolling resistance. Your comment made me realize that I forgot dividing the whole second equation by Mass. After fixing it, fr*Mass*9.8)*(y(2)>0) was enough to make it work.

サインインしてコメントする。

採用された回答

Diaa
Diaa 2021 年 4 月 23 日
Thanks to the explanation of Star Strider, the use of sign() can be replaced by fr*Mass*9.8)*(y(2)>0) to make it work.

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 4 月 23 日
You really should read ballode to see how to use event functions. https://www.mathworks.com/help/matlab/math/ode-event-location.html

カテゴリ

Help Center および File ExchangeNumerical Integration and Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by