% LVConservedQuant % % Module solves the Conserved Quanity for the Lotka Volterra System. % % Script delivers a vector of conserved quanity as a function of time steps % for the Lokta Volterra System solved in one patch % % Inputs: % Interruption Time in loop (InterruptionTime) % Number of generations (looplength) % Intial Condtions (HA PA HB PB) % % Geneva Mottet UAF 6-28-18 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% alpha = .01; beta = 0.02; gamma = 1; g = @(s,x)[x(1)*(1-alpha*x(2)); x(2)*(beta*x(1)-gamma)];%system of diff eqs x(1)=x(t), x(2)=y(t), ect. XAtotal = []; SAtotal = []; XBtotal = []; SBtotal = []; for j = 1:looplength [sA,xA] = ode45(@(s,x) g(s,x),[InterruptionTime*(j-1) InterruptionTime*(j)],[HA, PA]); [sB,xB] = ode45(@(s,x) g(s,x),[InterruptionTime*(j-1) InterruptionTime*(j)],[HB, PB]); XAtotal = [XAtotal;xA(1:length(xA) - 1,:)]; XBtotal = [XBtotal;xB(1:length(xB) - 1,:)]; SAtotal = [SAtotal;sA(1:length(sA) - 1,:)]; SBtotal = [SBtotal;sB(1:length(sB) - 1,:)]; HA = xA(end,1); PA = xA(end,2); HB = xB(end,1); PB = xB(end,2); if mod(j, MigInterval) == 0 % Migration HA =(1-HostMig)*HA + HostMig*HB;% Sets a new HA with contributions from hosts in both patches HB =(HostMig)*HA + (1-HostMig)*HB;% Sets a new HB with contributions from hosts in both patches PA =(1-ParaMig)*PA + ParaMig*PB;% Sets a new PA with contributions from parasites in both patches PB =(ParaMig)*PA + (1-ParaMig)*PB;% Sets a new PB with contributions end end conquantA = log(XAtotal(:,2)) - alpha.*XAtotal(:,2) - beta.*XAtotal(:,1) + gamma.*log(XAtotal(:,1)); conquantB = log(XBtotal(:,2)) - alpha.*XBtotal(:,2) - beta.*XBtotal(:,1) + gamma.*log(XBtotal(:,1));