%% MCHI, cv2, file 2 (cv2_2) - SODE
%
% Example of a dynamical system defined via stoechiometric matrix
%
% Author:       Martin Isoz
% Organisation: ICT Prague
% Date:         20. 09. 2014
%
% License: This code is published under MIT License, please do not abuse
% it.
%

function main                                                               %this is "script", but allows us to keep all the functions in the same file
% prepare system parameters
k = 1;
pars = k;

% get IC
x0 = [1;1];

% define tspan
tspan = [0 1];

% solve the system
[t,x] = ode45(@(t,x) model(t,x,pars),tspan,x0);

% plot the results
plot(t,x)
title('\bf Concetration profiles')
xlabel('time');ylabel('concetration')
legend('A','B')
end

function dxdt = model(~,x,pars)
% function defining the reaction system
% A     ... x(1)
% X     ... x(2)
% k     ... pars(1)
% A + 2X -> 3X
% r = k*x(1)*x(2)^2

k    = pars(1);                                                             %get system parameters
nuMat= [-1;1];                                                              %system stoechiometric matrix
vVec = k*x(1).*x(2).^2;                                                     %reaction speed 'vector'

dxdt = nuMat*vVec;                                                          %define system

end