Problem Statement: I have a system of differential equation and out of which few has time dependent coefficients and in my case i have piecewise time dependence. I am unable to add the time dependence and solve the equation.
Simplified Differential Equation:
My time span runs from 0 to 360 days and my aim is to have certain nonzero value for for half a day and zero for other half.
My unsuccessful attempt:
Function definition: MWE_fn.m
function rk1 = MWE_fn(t,y)r2=0.5;b2=1;d_A=0.05; c=0.5;rk1(1)=r2*y(1)*(1-b2*y(1))-c*y(1)*y(2);rk1(2)= A0(t)- d_A*y(2);rk1=rk1(:);endfunction fa=A0(t) if rem(t,1)==0 fa=0.04 else fa=0 endend
Function Body: MWE_body.m
timerange= 0:0.5:360;IC= [0.1,0];%initial conditions
[t,y] =ode45(@(t,y) MWE_fn(t,y),timerange, IC);plot(t,y(:,1),'b');hold onplot(t,y(:,2),'r');
I was aiming to write some kind of conditional statement for the function to take those values but that didn't go correct. The thing i had in mind was that for half a day we have time at integer values and for other half i have time at 0.5 , so i used a rem function to check that, but i was wrong and it didn't work.
Anyhelp would be appreciated.
Thank You.
Best Answer