function f=cstrF(x) % Reactor in series model, the function. % % x = [C(1),C(2),... C(N-1),beta] % f(i) = beta C(i)^2 + C(i) - C(i-1) global N CN N = length(x); % Number of unknowns and number of reactors. C0 = 5.0; % Inlet concentration (mol/L). CN = 0.5; % Outlet concentration (mol/L). % Initialize array (column vector format). f = zeros(N,1); f(1) = x(N)*x(1)^2.0+x(1)-C0; for i=2:N-1 f(i)= x(N)*x(i)^2.0+x(i)-x(i-1); end f(N) = x(N)*CN^2.0+CN-x(N-1);