I try to figure out how to input external variables(changing with time - hormone levels) into ode. I'm thinking about using events. I try to do optimisation (optimilisation of differential equations in Matlab with built-in events)
In order to learn how to use them I've tried to run code in Matlab ode solvers: changing state and specified time However, I do sth wrong. I guess that the problem is with my function myfun, but I don't know why.
I've tried to run following:
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,:));