Using event function in ode45

1 回表示 (過去 30 日間)
g618034
g618034 2011 年 6 月 16 日
回答済み: Richard Buckalew 2016 年 2 月 29 日
Hi Everyone!
I'm solving a physical pendulum using ode45. I only want to solve it for one period, and I've chosen to use the event function to complete this task. In here a(2) would be the angular velocity of the pendulum. Right at the moment that the pendulum completes one period, the angular velocity would be zero. However, it would be the second zero point of angular velocity, while the integration stops at the first zero point.
Is there any way I could make the event occur twice before it stops? Here's what I've tried--but it's not working right.
function[value, isterminal, direction] = event(t,a)
persistent count;
value = a(2);
direction = 0;
while count<=2
value = a(1);
direction = 0;
count = count+1;
isterminal = 0;
end
isterminal = 1;
end
Any suggestions would be appreciated. Thank you!

回答 (2 件)

Richard Buckalew
Richard Buckalew 2016 年 2 月 29 日
The easiest solution is to integrate it, catch the event, and then let your end Y become a new initial condition and integrate again. The next time it stops will be the second time the event occurs.

Walter Roberson
Walter Roberson 2011 年 6 月 16 日
There was a discussion about event functions in ode45 a few days ago; see here

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by