how to stop ode45 when one of states reach certain value

311 ビュー (過去 30 日間)
Mohamed Aburakhis
Mohamed Aburakhis 2016 年 5 月 4 日
コメント済み: Walter Roberson 2023 年 10 月 20 日
[x_dot] =derivative(t, x)
x is states [x(1).....x(4)] I need to stop the integration when x(3) reaches 0.1 when the integration stop record (t)

採用された回答

Jan
Jan 2016 年 5 月 4 日
Opt = odeset('Events', @myEvent);
[T, Y] = ode45(@YourFun, T, Y0, Opt);
function [value, isterminal, direction] = myEvent(T, Y)
value = (Y(3) == 0.1);
isterminal = 1; % Stop the integration
direction = 0;
  7 件のコメント
James Gilliam
James Gilliam 2023 年 10 月 20 日
What is T in this senario and how is it defined? Thanks
Walter Roberson
Walter Roberson 2023 年 10 月 20 日
In the call
[T, Y] = ode45(@YourFun, T, Y0, Opt);
the input T is the timespan to integrate over. It is a vector that must have at least two elements, but may have more. If it has two elements then ode45() will decide by itself what times to output information at; if it has more than two elements then ode45() will output information at the times given in the vector.

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

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2016 年 5 月 4 日
編集済み: Walter Roberson 2017 年 9 月 13 日
  1 件のコメント
Mohamed Aburakhis
Mohamed Aburakhis 2016 年 5 月 4 日
I found a lot of options , which one should I use?

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


Gustavo Lunardon
Gustavo Lunardon 2020 年 8 月 17 日
This is confusing. In matlab help it says: An event occurs when value(i) is equal to zero. All answers in this post make it value = 1 for the event to happen. Are the answers outdated somehow?
  1 件のコメント
Walter Roberson
Walter Roberson 2020 年 8 月 19 日
This is a valid concern.
value = (X(8) == 0.05 ) and (Y(3) == 0.1) would happen rarely, when the values were bit-for-bit identical to the representation of 0.05 and 0.1 . One bit different in the representation and the condition will not fire. Better is to write x(8) - 0.05 or 0.05 - x(8), and Y(3)-0.1 or 0.1-Y(3) -- zero crossings can be detected for those.

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

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by