function fx=fx_chemreac(t,x)
%fx_chemreac
% fx=fx_chemreac(t,x)
% Define the right hand side of the state equation dot(x)=f(x)
% for the chemical reactor model in Exercise 3 in the SCE1106 course.
% ON INPUT
% t- time. t=0 for this example. Dummy parameter here.
% x- state vector with values to linearize arond. Nominal vales x=[2.5;1]
%    for this example
% u- Control input to linearize around. u=25 nominal. Usu "global u" in
% MATLAB
% before calculating the jacobian matrix as:
%
%   global u
%   u=25
%   A=jacobi('fx_chemreac',0,[2.5;1])

global u
k1=50; k2=100; k3=10;  % Reaction rate coefficients
%u=25;                 % Nonimal control entered as Global variable
x10=10;                % Composition of substance A in feed flow

fx=zeros(2,1);         % Define clean space for dot(x)=f(x,u)=[f1;f2]
fx(1)=-k1*x(1)-k3*x(1)^2+(x10-x(1))*u;
fx(2)=k1*x(1)-k2*x(2)-x(2)*u;
% END fx_chemreac