How do I pass known variables into my ODE45 function?

Hi,
I am attempting to pass a set of variables (a1,a2,a3,...an - these numbers can be integers,vectors and arrays) into an ODE function to avoid having to call these variables on each iteration of the ODE as the call function is quiet slow. I want to make it so that I call the variables (from excel files) before the ODE and use these variables as inputs to the ODE, therefore avoiding the need to call the function in the ODE function itself, but do not know how to do this.
Could anybody help with letting me know the syntax to read these variables into the ODE?
The set up of my ODE code is shown here:
at = 1e-5*ones(Neqn,1); % Absolute tolerance for ODE
tE = 0; % Start time for ODE
endtime = 50e3; % End time for ODE
span = [tE endtime]; % ODE time span
options = odeset('RelTol',1e-4,'AbsTol',at);
[t,y] = ode45(@Reactor_simple_ODE,span,init,options);

 採用された回答

Walter Roberson
Walter Roberson 2016 年 2 月 6 日

0 投票

5 件のコメント

Bobby H
Bobby H 2016 年 2 月 8 日
編集済み: Bobby H 2016 年 2 月 8 日
Hi Walter, Thank you for the link. I'm still not sure how to implement this for an ODE. Would you be able to clarify the syntax?
Lets say a I have variables as shown: a1 = [1, 2, 3, 4]; a2 = 10000; a3 = [ 1 1 1, 2 2 2, 3 3 3];
And I wish to pass these values to the ODE, could you show me a sample syntax?
I have tried: * [t,y] = ode45(@Reactor_simple_ODE,span,init,options, a1, a2, a3); * [t,y,a1, a2, a3] = ode45(@Reactor_simple_ODE,span,init,options); * I also tried putting the variables in the options of the ODE.
Torsten
Torsten 2016 年 2 月 8 日
[T,Y] = ode45(@(t,y)Reactor_simple_ODE(t,y,a1,a2,a3),span,init,options);
Best wishes
Torsten.
Bobby H
Bobby H 2016 年 2 月 8 日
This works perfectly, much more efficient now.
Thank you Torsten and Walter
Yokesh
Yokesh 2019 年 6 月 23 日
It works, I appreciate it @Torsten
Bilal Tahseen
Bilal Tahseen 2020 年 8 月 30 日
It works, Thanks @Torsten

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

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by