我試圖弄清楚如何將外部變量(隨時間變化 - 激素水平)輸入到模型中。 我正在考慮使用事件。我嘗試做優化(微分方程optimilisation在Matlab與內置事件)使用事件將外部變量輸入方程
爲了學習如何使用他們,我一直在努力,在Matlab ode solvers: changing state and specified time 但是運行的代碼,我做某事錯了。我想這個問題與我的功能myfun有關,但我不知道爲什麼。
我試過以下運行:
function ydot=myfun(t,y,a)
S1 = 2 *a* 2 * y(2) - 2 * 3 * y(1)*y(1);
S2 = 3 * y(1)*y(1) + a - 5 * y(2);
ydot = [S1; S2];
y_0=[0,0];
%[t,y]=ode45(@myfun,[0:0.1:Tfinal],y_0);
and run following with nested myfun function:
%function events=events_in_Matlab(a)
dt=0.01;
T=0:dt:30;
y_0=[0 0];
Y=zeros(length(T),length(y_0));
%t=0 to t=10, pass parameter a=0 to add to ODEs
a=0;
[~,Y(1:10/dt+1,:)]=ode45(@(t,y)myfun(t,y,a),T(1:10/dt+1),y_0);
%t=10 to t=20, pass parameter a=10 to add to ODEs
a=10;
[~,Y(10/dt+1:20/dt+1,:)]=ode45(@(t,y)myfun(t,y,a),T(10/dt+1:20/dt+1),
Y(10/dt+1,:));
%t=20 to t=30, pass parameter a=20 to add to ODEs
a=20;
[~,Y(20/dt+1:end,:)]=ode45(@(t,y)myfun(t,y,a),T(20/dt+1:end),(20/dt+1,:));
您需要執行插值,因爲步長在ode45中不固定。 – CroCo