combining ODE_FUNC and EVENT_FUNC for ODE solvers

I'm solving a non-stiff non-linear ODE problem using matlab's ODE23/ODE45 solvers. I have a transition in the model which I handle with an EVENT_FUNC. The value X that the EVENT_FUNC checks requires a sizable calculation.
My problem is that I already need to calculate X in my ODE_FUNC. Because the EVENT_FUNC is a separate thing, I have to calculate X twice which is not efficient.
My question is; is there any way to combine the ODE_FUNC and EVENT_FUNC such that the ODE_FUNC returns X together with all the other 2 parameters required by the EVENT_FUNC such that I don't have to perform the same computation twice.
Any suggestions / solutions are much appreciated.

回答 (1 件)

Torsten
Torsten 2015 年 7 月 6 日

0 投票

Define X as global in ODE_FUNC and EVENT_FUNC.
Then check whether you can use the (last) value for X calculated in ODE_FUNC also in EVENT_FUNC (i.e. whether t and y as input parameters are the same).
Best wishes
Torsten.

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

製品

タグ

質問済み:

2014 年 2 月 21 日

回答済み:

2015 年 7 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by