1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126 | % Copyright (C) 2001, James B. Rawlings and John G. Ekerdt
%
% This program is free software; you can redistribute it and/or
% modify it under the terms of the GNU General Public License as
% published by the Free Software Foundation; either version 2, or (at
% your option) any later version.
%
% This program is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
% General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; see the file COPYING. If not, write to
% the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
% MA 02111-1307, USA.
%
% Revised 8/16/2018
p.k1 = 1;
p.k2 = 2;
p.theta1 = 1;
p.theta2 = 2;
p.caf = 1;
p.cbf = 1;
p.rhotest = 1;
p.n = 2;
p.alpha = 0.1;
%
% one well-mixed reactor
%
p.theta = p.theta1 + p.theta2;
npts = 100;
rho0 = 0;
rhofin = 1;
rhovec = linspace(rhofin,rho0,npts)';
x0 = [0; p.cbf - p.caf; 0; p.cbf - p.caf];
y0 = [0; p.cbf - p.caf];
[y, fval, info] = fsolve(@(x) onereac(x, p), y0);
fsolve_failed = info <= 0;
if (fsolve_failed)
fprintf ('warning, fsolve failed, info = %d\n', info);
p.rho, y0
end
conv1 = (p.alpha*p.caf - (1 + p.alpha)*y(1))/...
(p.alpha*p.caf)*ones(npts,1);
yield1 = (p.cbf - (1 + p.alpha)*y(2))/...
(p.alpha*p.caf - (1 + p.alpha)*y(1))*ones(npts,1);
conv2 = zeros(npts, 1);
yield2 = zeros(npts, 1);
for i = 1:npts
p.rho = rhovec(i);
[x, fval, info] = fsolve(@(x) tworeac(x, p), x0);
fsolve_failed = info <= 0;
if (fsolve_failed)
fprintf ('warning, fsolve failed, info = %d\n', info);
fprintf('i= %g \n',i);
% rho, x0
end
x0 = x;
conv2(i) = (p.alpha*p.caf - (1 + p.alpha)*x(3))/...
(p.alpha*p.caf);
yield2(i) = (p.cbf - (1 + p.alpha)*x(4))/...
(p.alpha*p.caf - (1 + p.alpha)*x(3));
end
table1 = [rhovec yield1 yield2 conv1 conv2];
%
% step test results
%
nts = 100;
tfin = 10*p.theta;
times = linspace(0,tfin,nts)';
y0 = 0;
opts = odeset('AbsTol', sqrt(eps), 'RelTol', sqrt(eps));
[tsolver, y] = ode15s(@(t, x) onestep(t, x, p), times, y0, opts);
impy = onestep(0, y, p);
x0 = [0; 0];
p.rho = 0;
a = [p.alpha/p.theta1; 0];
B = [-(p.alpha + p.rho)/p.theta1, p.rho/p.theta1;
(p.alpha + p.rho)/p.theta2, ...
-(1 + p.alpha + p.rho)/p.theta2];
opts = odeset('AbsTol', sqrt(eps), 'RelTol', sqrt(eps));
[tsolver, x1] = ode15s(@(t, x) twostep(t, x, a, B), times, x0, opts);
impx1 = [diag(a)*ones(2,nts) + B*x1']';
p.rho = 1;
a = [p.alpha/p.theta1; 0];
B = [-(p.alpha + p.rho)/p.theta1, p.rho/p.theta1;
(p.alpha + p.rho)/p.theta2, ...
-(1 + p.alpha + p.rho)/p.theta2];
opts = odeset('AbsTol', sqrt(eps), 'RelTol', sqrt(eps));
[tsolver, x2] = ode15s(@(t, x) twostep(t, x, a, B), times, x0, opts);
impx2 = [diag(a)*ones(2,nts) + B*x2']';
table2 = [times y x1(:,2) x2(:,2) impy impx1(:,2) impx2(:,2)];
save selectivity.dat table1 table2
if (~ strcmp (getenv ('OMIT_PLOTS'), 'true')) % PLOTTING
subplot (3, 1, 1);
plot (table1(:,1), table1(:,4:5));
% TITLE selectivity_1
subplot (3, 1, 2);
plot (table1(:,1), table1(:,2:3));
% TITLE selectivity_2
subplot (3, 1, 3);
plot (table2(:,1), table2(:,2:4));
% TITLE selectivity_3
end % PLOTTING
|