So I have written a system of equations and used ode45 to solve it. I was just wondering if there is a more efficient way to do it. I am creating an ODE model and will later use certain methods to find the unknown parameters, but for now I am just guessing random values.
I have written my model as
function dydt = ODE_Model(t,y,p_1,p_2,p_3,d_1,d_2,d_3,a,b,Tau)dydt = zeros(3,1); dydt(1) = p_1*(a*cos(t*2*pi/365-Tau)+b)-d_1*y(1); dydt(2) = p_2*(a*cos(t*2*pi/365-Tau)+b)-d_2*y(2); dydt(3) = p_3*y(1)-d_3*y(2)*y(3); end
and then solved it using
tspan = [0 5];y0 = [4 5 6];p_1 = 1;p_2 = 1;p_3 = 1;d_1 = 1;d_2 = 1;d_3 = 1;a=1;b=1;Tau=1;SolExp = ode45(@(t,y) ODE_Model(t,y,p_1,p_2,p_3,d_1,d_2,d_3,a,b,Tau), tspan, y0);TimePoints = 0:0.1:2;y = deval(SolExp, TimePoints);clfplot(TimePoints, y)
I wanted to do P and D as a combined vector, so i would have P(1) .. P(6) and then i could just write something like P = [1 1 1 1 1 1], but reading about ode45 it seems I can only use one variable? I am not sure. Is there a neater way to do what I want to do, or is this as neat it gets?
Thanks
Best Answer