%% MATLAB CODE FOR SOLVING THE ODE MODEL IN  
%% THE PROJECT ON INVASION OF DESERTS. 
%% WRITTEN BY JONATHAN SHERRATT.

function solvedesertodes

global aparameter bparameter

%% Set parameters
aparameter= ; % FILL IN A VALUE FOR A
bparameter=0.45;

%% Set initial conditions
uic = ; % FILL IN A VALUE FOR u AT t=0
wic = ; % FILL IN A VALUE FOR v AT t=0

%% Solve equations
tmax = 20;
[T,Y] = ode45(@desertodes,[0 tmax],[uic wic]);
u = Y(:,1);
w = Y(:,2); 

%% Plot results
figure;
subplot(2,1,1);
plot(T,u);
xlabel('Time, t');
ylabel('Vegetation biomass, u');
title(strcat('Final values: u=',num2str(u(end)),'  w=',num2str(w(end))));
subplot(2,1,2);
plot(T,w);
xlabel('Time, t');
ylabel('Water density, w');

% -----------------------------------------------------------------------  

function dy = desertodes(t,u)
global aparameter bparameter 
dy = zeros(2,1);
dy(1) = u(1)*u(1)*u(2)-bparameter*u(1);
dy(2) = aparameter-u(2)-u(1)*u(1)*u(2);

% -----------------------------------------------------------------------  

                                  

