function ODE23_Example()
%This function uses ode23 to solve the following system of differential
%equations
% dx/dt = -0.20*x; x(t=0)=20
% dy/dt = -0.07*y; y(t=0)=30
% in Matrix form:
%    dQ/dt = [-0.20 0; 0 -0.07]*Q, where Q = [x; y]


%Set Parameters
t_start = 0; %s -- the point when your simulation starts
t_end = 100; %s -- the point when your simulation ends


% ODE Solver 
Initials = [20; 30]; % Your initial values of x and y are stored in a column vector
[t,Q] = ode23(@get_derivs_solver, [t_start; t_end], Initials);
% ode23 outputs the time, and the values of the variables in Q
% ode23 takes an input of a function handle that computes the derivatives
% of the variables stored in Q, a vector with the start and end
% times of the simulations, and a vector of the initial conditions
% Q is a matrix where the first column represents x, and the second column
% represents y as a function of time - which is varied along the rows of Q
plot(t, [Q(:,1) Q(:,2)],'LineWidth',2); %Plots each column of Q vs. time
xlabel('time (s)');
ylabel('Value');
title('Time (s)');
ylim([0 35]);
xlim([0 t_end]);
legend('x','y');

return

% Function to Calculate Derivatives
function derivatives = get_derivs_solver(t,Q)

x = Q(1); %unpack - Q(1) is passed from ode23 above - it is the value of the x-variable
y = Q(2);

dxdt = -0.20*x; % compute the derivatives
dydt = -0.07*y;

derivatives = [dxdt; dydt]; %pass back the derivatives in a column vector
return