% ODE solver
% https://www.mathworks.com/help/matlab/math/choose-an-ode-solver.html
% https://www.mathworks.com/help/matlab/ref/ode45.html
% http://www.scholarpedia.org/article/Predator-prey_model
% Methods
% ode23: https://en.wikipedia.org/wiki/Bogacki%E2%80%93Shampine_method
% ode45: https://en.wikipedia.org/wiki/Dormand%E2%80%93Prince_method

b=1;p=1;r=1;d=1;
[t,x]=ode45(@(t,x) predator_prey(t,x,b,p,r,d),[0 20],[0.5; 0.5]);

%

plot(t,x(:,1),'-o',t,x(:,2),'-o')
title('Predator prey model with ODE45');
xlabel('Time t');
ylabel('Solution x');
legend('x_1','x_2')

%

plot(x(:,1),x(:,2))
title('Predator prey model with ODE45');
xlabel('x_1');
ylabel('x_2');

%
% Rovnováhy

syms x1 x2
sys=predator_prey(t,[x1, x2],b,p,r,d)
S=solve(sys);
S.x1
S.x2

%

function dydt = predator_prey(t,x,b,p,r,d)
dydt = [b*x(1)-p*x(1)*x(2); r*x(1)*x(2)-d*x(2)];
end