- #1
DrWahoo
- 53
- 0
Use the code as needed, its free to all!
Please note this code is only for one mfile, you will need to add them all to the same file path for it to work. Others will be in the next post. They have to run simultaneously to work and give output.
Please note this code is only for one mfile, you will need to add them all to the same file path for it to work. Others will be in the next post. They have to run simultaneously to work and give output.
Code:
function dydt = rhs_both_age(~,y,flag,p,eRP,eCP,eRC,aRP,aCP,aRC,hRP,hCP,hRC,mP,mC,nP,r,K,mJ)
%--------------------------------------------------------------------------
% Simultaniously computes the right hand sides of the state and sensitivity
% equations for the age structure omnivory model.
%
% Input: t = time. Not used, but needed by ode45
% flag = (not used) placeholder for compatibility with ode45 y =
% column vector (length 6) of states and sensitivities
% y(1) = adult predator density, y(2) = juvenile predator
% density y(3) = consumer density, y(4) = resource density,
% y(5) = adult predator sensitivity, y(6) = juvenile predator
% sensitivity y(7) = consumer sensitivity y(8) = resource
% sensitivity
% p = integer that tells which parameter sensitivity to compute
% eRP, eCP, ... , r, K are model parameters
%
% Output: dydt = column vector (length 8) of dy/dt values
%--------------------------------------------------------------------------
%---the column vector of four zeros on top and the partials of f with
% respect to the model parameters.
if p == 1 %eRP
partial = [0;
0;
0;
0;
0;
(aRP*y(4)*y(1))/(1+aRP*hRP*y(4)+aCP*hCP*y(3));
0;
0];
elseif p == 2 %eCP
partial = [0;
0;
0;
0;
0;
(aCP*y(3)*y(1))/(1+aRP*hRP*y(4)+aCP*hCP*y(3));
0;
0];
elseif p == 3 %eRC
partial = [0;
0;
0;
0;
0;
0;
(aRC*y(4)*y(3))/(1+aRC*hRC*y(4));
0];
elseif p == 4 %aRP
partial = [0;
0;
0;
0;
0;
(eRP*y(4)*y(1)*(1+aCP*hCP*y(3))-eCP*aCP*hRP*y(4)*y(3)*y(1))/((1+aRP*hRP*y(4)+aCP*hCP*y(3))^2);
(aCP*hRP*y(4)*y(3)*y(1))/((1+aRP*hRP*y(4)+aCP*hCP*y(3))^2);
-(y(4)*y(2))/((1+aRP*hRP*y(4))^2)-(y(4)*y(1)*(1+aCP*hCP*y(3)))/((1+aRP*hRP*y(4)+aCP*hCP*y(3))^2)];
elseif p == 5 %aCP
partial = [0;
0;
0;
0;
0;
(eCP*y(3)*y(1)*(1+aRP*hRP*y(4))-eRP*aRP*hCP*y(4)*y(3)*y(1))/((1+aRP*hRP*y(4)+aCP*hCP*y(3))^2);
-(y(3)*y(1)*(1+aRP*hRP*y(4)))/((1+aRP*hRP*y(4)+aCP*hCP*y(3))^2);
(aRP*hCP*y(4)*y(3)*y(1))/((1+aRP*hRP*y(4)+aCP*hCP*y(3))^2)];
elseif p == 6 %aRC
partial = [0;
0;
0;
0;
0;
0;
(eRC*y(4)*y(3))/((1+aRC*hRC*y(4))^2);
-(y(4)*y(3))/((1+aRC*hRC*y(4))^2)];
elseif p == 7 %hRP
partial = [0;
0;
0;
0;
0;
-(aRP*y(4)*y(1)*(eRP*aRP*y(4)+eCP*aCP*y(3)))/((1+aRP*hRP*y(4)+aCP*hCP*y(3))^2);
(aRP*aCP*y(4)*y(3)*y(1))/((1+aRP*hRP*y(4)+aCP*hCP*y(3))^2);
(((aRP)^2)*((y(4))^2)*y(2))/((1+aRP*hRP*y(4))^2)+(((aRP)^2)*((y(4))^2)*y(1))/((1+aRP*hRP*y(4)+aCP*hCP*y(3))^2)];
elseif p == 8 %hCP
partial = [0;
0;
0;
0;
0;
-(aCP*y(3)*y(1)*(eRP*aRP*y(4)+eCP*aCP*y(3)))/((1+aRP*hRP*y(4)+aCP*hCP*y(3))^2);
(((aCP)^2)*((y(3))^2)*y(1))/((1+aRP*hRP*y(4)+aCP*hCP*y(3))^2);
(aRP*aCP*y(4)*y(3)*y(1))/((1+aRP*hRP*y(4)+aCP*hCP*y(3))^2)];
elseif p == 9 %hRC
partial = [0;
0;
0;
0;
0;
0;
-(eRC*((aRC)^2)*((y(4))^2)*y(3))/((1+aRC*hRC*y(4))^2);
(((aRC)^2)*((y(4))^2)*y(3))/((1+aRC*hRC*y(4))^2)];
elseif p == 10 %mPA
partial = [0;
0;
0;
0;
-y(1);
0;
0;
0];
elseif p == 11 %mC
partial = [0;
0;
0;
0;
0;
0;
-y(3);
0];
elseif p == 12 %nP
partial = [0;
0;
0;
0;
y(2);
-y(2);
0;
0];
elseif p == 13 %r
partial = [0;
0;
0;
0;
0;
0;
0;
y(4)*(1-(y(4)/K))];
elseif p == 14 %K
partial = [0;
0;
0;
0;
0;
0;
0;
((r*(y(4))^2)/(K)^2)];
elseif p == 15 %mPJ
partial = [0;
0;
0;
0;
0;
-y(2);
0;
0];
end
dydt_temp = [
nP*y(2)-mP*y(1);
((eRP*aRP*y(4)+eCP*aCP*y(3))/(1+aRP*hRP*y(4)+aCP*hCP*y(3)))*y(1)-(nP+mJ)*y(2);
y(3)*((eRC*aRC*y(4))/(1+aRC*hRC*y(4))-(aCP*y(1))/(1+aRP*hRP*y(4)+aCP*hCP*y(3))-mC);
y(4)*(r*(1-(y(4)/K))-(aRC*y(3))/(1+aRC*hRC*y(4))-(aRP*y(2))/(1+aRP*hRP*y(4))-(aRP*y(1))/(1+aRP*hRP*y(4)+aCP*hCP*y(3)));
-mP*y(5)+nP*y(6);
((eRP*aRP*y(4)+eCP*aCP*y(3))/(1+aRP*hRP*y(4)+aCP*hCP*y(3)))*y(5)-(nP+mP)*y(6)+((eCP*aCP*y(1)*(1+aRP*hRP*y(4))-eRP*aRP*aCP*hCP*y(4)*y(1))/((1+aRP*hRP*y(4)+aCP*hCP*y(3))^2))*y(7)+((eRP*aRP*y(1)*(1+aCP*hCP*y(3))-eCP*aRP*aCP*hRP*y(3)*y(1))/((1+aRP*hRP*y(4)+aCP*hCP*y(3))^2))*y(8);
-((aCP*y(3))/(1+aRP*hRP*y(4)+aCP*hCP*y(3)))*y(5)+((eRC*aRC*y(4))/(1+aRC*hRC*y(4))-(aCP*y(1)*(1+aRP*hRP*y(4)))/((1+aRP*hRP*y(4)+aCP*hCP*y(3))^2)-mC)*y(7)+((eRC*aRC*y(3))/((1+aRC*hRC*y(4))^2)+(aCP*aRP*hRP*y(3)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