SlideShare une entreprise Scribd logo
1  sur  156
Process Optimization
Chapter 6
06Process Optimization
 to introduce the optimization commands
 describe how to use them to solve diversified
optimization problems that arose from the field of
chemical engineering.
introduce a population-based real-coded genetic
algorithm (RCGA)
2
06Process Optimization
6.1 The optimization problem and the relevant
MATLAB commands
 6.1.1 Optimization problems of a single decision
variable
[x, fval]= fminbnd('fun', a, b, options)
3
Output
argument
Description
x The obtained optimal solution in the feasible range [a b]
fval
The objective function value corresponding to the
obtained optimal point x
06Process Optimization
4
Input
argument
Description
fun
The name of the function file provided by the user, and the
format of the function is as follows:
function f=fun(x)
f= ... % objective function
Besides, if the objective function is not complicated it can be
directly given by the inline command, see Example 6-1-1 for
detailed usage.
a Lower limit of the decision variable
b Upper limit of the decision variable
options
Solution optional parameters provided by the users, such as
the maximal iteration number, the accuracy level and the
gradient information, and so on. Refer to the command
‘optimset’ for its usage.
06Process Optimization
Example 6-1-1
Solve the following optimization problem
5
Ans:
>> f=inline('x.^3+x.^2-2*x-5'); % use inline to provide the objective
function
>> x=fminbnd(f, 0, 2)
x=
0.5486
>> y=f(x)
y=
-5.6311
06Process Optimization
6.1.2 Multivariate optimization problems without
constraints
[x, fval]= fminunc('fun', x0, options)
6
06Process Optimization
Example 6-1-2
Solve the following unconstrained optimization problem of
two variables
7
Step 1: Provide the objective function file
Ans:
06Process Optimization
──────────────── ex6_1_2f.m ────────────────
function f=fun(x)
xl=x(1);
x2=x(2);
f=3*xl^2+2*xl*x2+5*x2^2; % objective function
─────────────────────────────────────
8
Ans:
Step 2: Provide the objective function file
>> x0= [1 1]; % initial guess value
>> [x, fval]=fminunc('ex6_1_2f', x0)
x=
1.0e-006 *
-0.2047 0.2144
fval =
2.6778e-013
06Process Optimization
──────────────── ex6_1_2f2.m ───────────────
function [f, G]=fun(x)
x1=x(1);
x2=x(2);
f=3*x1^2+2*x1*x2+5*x2^2; % objective function
if nargout > 1 % the number of the output arguments is more than 1
G=[6*x1+2*x2 % partial differentiation with respect to x1
2*x1+10*x2]; % partial differentiation with respect to x2
end
─────────────────────────────────────
9
Ans:
06Process Optimization
10
Ans:
>> options=optimset('GradObj', 'on'); % declare a gradient has been provided
>> x0=[1 1]; % initial guess
>> [x, fval]=fminunc('ex6_1_2f2', x0, options)
x =
1.0e-015 *
-0.2220 0.1110
fval =
1.6024e-031
[x, fval]=fminsearch('fun', x0, options)
06Process Optimization
6.1.3 Linear programming problems
11
s.t.
[x, fval]=linprog(f, A, b, Aeq, beq, xL, xU, x0, options)
06Process Optimization
Example 6-1-3
Solve the following linear programming problem
12
s.t.
06Process Optimization
Example 6-1-3
13
Ans:
and
06Process Optimization
14
Ans:
>> f=[-5 -4 -3]';
>> A=[1 -1 2; 3 2 1; 2 3 0];
>> b=[30 40 20]';
>> Aeq=[ ];
>> beq=[ ];
>> xL=[0 0 0]';
>> xU=[ ];
>> [x, fval]=linprog(f, A, b, Aeq, beq, xL, xU)
x=
0.0000
6.6667
18.3333
fval =
-81.6667
06Process Optimization
6.1.4 Quadratic programming problem
[x, fval] =quadprog(H, f, A, b, Aeq, beq, xL, xU, x0, options)
15
s.t.
06Process Optimization
Example 6-1-4
16
s.t.
06Process Optimization
17
Ans:
where
A=[1 -1 ; -1 2; 2 1], b=[l 2 3]', Aeq=[ ] and beq=[ ].
06Process Optimization
18
Ans:
>> H=[1 -1 ; -1 2];
>> f=[-6 -2]';
>> A=[1 -1; -1 2; 2 1]; % inequality coefficient matrix
>> b=[1 2 3]'; % inequality vector
>> xL=[0 0]'; % lower limit of the variable
>> [x, fval]=quadprog(H, f, A, b, [ ], [ ], xL, [ ])
x=
1.3077
0.3846
fval =
-8.1154
06Process Optimization
NOTES:
The determination of the H matrix of the quadratic objective
function (6.1-11) can be easily accomplished by using the
Symbolic Math operations as follows.
19
Ans:
>> syms x1 x2 % declare x1 and x2 as symbolic variables
>> f=1/2*x1^2+x2^2-x1*x2; % define the quadratic function
>> H=jacobian(jacobian(f)) % calculate the H matrix
H =
[ 1, 1]
[ 1, 2]
06Process Optimization
6.1.5 The constrained nonlinear optimization
problems
[x, fval]= fmincon('fun', x0, A, b, Aeq, beq, xL, xU, 'nonlcon', options)
20
s.t.
06Process Optimization
• the objective function,
21
function f=fun(x)
f= ... % the objective function
• The nonlinear constraints, c(x) and ceq(x),
function [c, ceq]=nonlcon(x)
c=... % the nonlinear inequality constraints
ceq=... % the nonlinear equality constraints
• the gradient information
options=optimset('Gradconstr', 'on')
06Process Optimization
22
function [c, ceq, Gc, Gceq]=nonlcon(x)
c=... % nonlinear inequality constraints
ceq=... % nonlinear equality constraints
if nargout > 2 % since gradients are provided
Gc=... % the gradients of the inequality constraints (in vector form)
Gceq=... % the gradient of the equality constraints (in vector form)
end
06Process Optimization
Example 6-1-5
23
s.t.
06Process Optimization
─────────────── ex6_1_5.m ───────────────
function ex6_1_5
%
% Example 6-1-5 Solve an optimization problem with fmincon
%
clear
clc
%
% initial guess values
%
x0=[10 10 10]';
%
% coefficients for the inequality constraints
%
A=[-1 -2 -2; 1 2 2];
b=[0 72]';
%
% solving the optimization problem with fmincon
24
Ans:
06Process Optimization
─────────────── ex6_1_5.m ───────────────
%
[x, fval]=fmincon(@objfun, x0, A, b, [ ], [ ], [ ], [ ], @nonlcon);
x1=x(1);
x2=x(2);
x3=x(3);
fprintf('n The optimal solution is x1=%.3f, x2=%.3f, x3=%.3f,…
,n and the minimum objective function is f=%.3fn', x1, x2, x3, fval)
%
% objective function
%
function f=objfun(x)
x1=x(1);
x2=x(2);
x3=x(3);
f=-x1*x2^2*x3;
%
% nonlinear constraints
25
Ans:
06Process Optimization
─────────────── ex6_1_5.m ───────────────
%
function [c, ceq]=nonlcon(x)
x1=x(1);
x2=x(2);
x3=x(3);
c=x1*x3-0.5*x2^2-380;
ceq=x2*x3-144;
─────────────────────────────────────
26
Ans:
06Process Optimization
Execution results:
>> ex6_1_5
The optimal solution is x1=20.000, x2=18.000, x3=8.000,
and the minimum objective function is f=-51840.000
27
06Process Optimization
6.1.6 The multi-objective goal attainment problem
[x, fval, r]=fgoalattain('fun', x0, goal, w, A, b, Aeq, beq, xL, xU, 'nonlcon', options)
28
s.t.
06Process Optimization
Example 6-1-6
Design of a pole placement controller
29
06Process Optimization
feedback control law u=Ky
the closed-loop system
To avoid aggressive control inputs, the absolute value of each
element in the gain matrix K is required to be less than 4.
Determine the controller’s gain matrix K if the desired closed-
loop poles, i.e., the eigenvalues of the matrix A+BKC, are
located at 5, 3, and 1.
30
06Process Optimization
Problem formulation and MATLAB program design:
goal = [-5, -3, -1]
F=sort(eig(A+B*K*C))
w=abs(goal)
and
31
06Process Optimization
──────────────── ex6_1_6 ───────────────
function ex6_1_6
%
% Example 6-1-6 Design of a pole placement controller
%
clear
clc
%
global A B C % declared as the global variables
%
% system matrices
%
A=[-0.5 0 0 ; 0 -2 10 ; 0 1 -2];
B=[1 0 ; -2 2 ; 0 1 ];
C=[1 0 0 ; 0 0 1 ];
%
% initial guess values of the controller parameter
%
K0=[-1 -1 ; -1 -1 ];
%
32
06Process Optimization
──────────────── ex6_1_6 ───────────────
% the desired poles and the weighting vector
%
goal=[-5 -3 -1]; % vector of the desired poles
w=abs(goal); % weighting vector
%
% the lower and upper bounds of the decision parameters
%
xL=-4*ones(size(K0)); % lower limit of the controller parameters
xU=4*ones(size(K0)); % upper limit of the controller parameters
%
% solving the multi-objective goal attainment problem
%
% options=optimset('GoalsExactAchieve',3);
% [K,fval,r]=fgoalattain(@eigfun,K0,goal,w,[ ],[ ],[ ],[ ],xL,xU,[ ],options)
[K,fval,r]=fgoalattain(@eigfun,K0,goal,w,[ ],[ ],[ ],[ ],xL,xU)
%
% multi-objective function vector
%
33
06Process Optimization
──────────────── ex6_1_6 ───────────────
function f=eigfun(K)
global A B C
f=sort(eig(A+B*K*C));
─────────────────────────────────────────────────
34
06Process Optimization
Execution results:
>> ex6_1_6
35
K=
-4.0000 -0.2564
-4.0000 -4.0000
fval =
-6.9313
-4.1588
-1.4099
r=
-0.3863
06Process Optimization
Execution results:
>> ex6_1_6
replace the original command of fgoalattain with the following
two lines:
36
options=optimset (‘GoalsExactAchieve', 3);
[K, fval, r]=fgoalattain(@eigfun, K0, goal, W, [ ], [ ], [ ], [ ], xL, xU, [ ], options)
06Process Optimization
Execution results:
>> ex6_1_6
37
K =
-1.5953 1.2040
-0.4201 -2.9047
fval =
-5.0000
-3.0000
-1.0000
r =
4.1222e-021
06Process Optimization
6.1.7 Semi-infinitely constrained optimization
problem
s.t.
c(x) = 0
c eq (x) = 0
Ax = b
Aeq x = beq
xL ≤ x ≤ xU
k1 (x, w1) ≤ 0
k2 (x, w2) ≤ 0
⁞
kn (x, wn) ≤ 0
38
06Process Optimization
39
[x, fval]=fseminf('fun' , x0, n, 'seminfcon' , A, b, Aeq, beq, xL, xU, options)
function f = fun(x)
f = ... % objective function
options=optimset(‘GradObj , 'on ')
function [f, G]=fun(x)
f= ... % the objective function
if nargout >1 % due to the gradient information is provided
G =... % the gradient formula
end
06Process Optimization
40
function [c, ceq, k1, k2, ... , kn, S]=seminfcon(x, S)
%
% given S matrix
%
if isnan(S(l, l))
S =... % S is a matrix with n rows and 2 columns
end
%
% mesh points of wi based on S matrix
%
w1=… ; %
w2= … ; %
…
06Process Optimization
41
wn= … ; %
%
% calculate the semi-infinite inequalities
%
k1=…%
k2=…%
…
kn=…%
%
% other nonlinear constraints
%
c = … % inequality constraints
ceq= …% equality constraints
06Process Optimization
Example 6-1-7
Solve the following semi-infinite optimization problem
(MATLAB User’s Guide, 1997)
42
s.t.
where the values of w1 and w2 both lie in the range of 1 and 100.
06Process Optimization
Example 6-1-7
Step 1: Prepare the objective function file:
function f=fun6_1_7(x)
f=sum((x-0.5).^2);
Step 2: Prepare a function file that contains the semi-infinite
constraints:
function [c, ceq, k1 , k2, S]=seminfcon6_1_7(x, S)
%
% S matrix: distance between meshes
%
if isnan(S(l, l))
43
Ans:
06Process Optimization
S=[0.1 0
0.1 0]; % NOTE: the second column is a zero
vector
end
%
% meshes for wi
%
w1=1:S(1,1):100;
w2=1:S(2,1):100;
%
% semi-infinite constraints
%
k1=sin(w1*x(1)).*cos(w1*x(2))-1/1000*(wl-50).^2-
sin(w1*x(3))-x(3)-1;
44
Ans:
06Process Optimization
k2=sin(w2*x(2)).*cos(w2*x(l) )-1/1000*(w2-50).^2-
sin(w2*x(3))-x(3)-1;
%
% other nonlinear constraints
%
c= [ ]; % no other nonlinear constraints
ceq=[ ];
Step 3:Combine the subroutines
45
Ans:
06Process Optimization
──────────────── ex6_7.m ───────────────
function ex6_1_7
%
% Example 6-1-7 Semi-infinite optimization
%
clear
clc
%
x0=[0.5 0.2 0.3]'; % initial guess values
%
% solve the semi-infinite optimization problem
%
[x, fval]=fseminf(@fun6_1_7, x0, 2, @seminfcon6_1_7)
%
% objective function
%
function f=fun6_1_7(x)
f=sum((x-0.5).^2);
%
% constraints
46
06Process Optimization
──────────────── ex6_7.m ───────────────
%
function [c, ceq, k1, k2, S]=seminfcon6_1_7(x, S)
%
% S matrix: distance between meshes
%
if isnan(S(l, l))
S=[0.1 0
0.1 0]; % NOTE: the second column is a zero vector
end
%
% meshes for wi
%
w1=1:S(1,1):100;
w2=1:S(2,1):100;
%
% semi-infinite constraints
%
k1=sin(w1*x(1)).*cos(w1*x(2))-1/1000*(wl-50).^2-sin(w1*x(3))-x(3)-1;
k2=sin(w2*x(2)).*cos(w2*x(l))-1/1000*(w2-50).^2-sin(w2*x(3))-x(3)-1;
47
06Process Optimization
──────────────── ex6_7.m ───────────────
%
% other nonlinear constraints
%
c= [ ]; % no other nonlinear constraints
ceq=[ ];
─────────────────────────────────────────────────
48
06Process Optimization
Step 4: Execute the program to get the optimal solution
>> ex6_1_7
x =
0.6581
0.2972
0.3962
fval =
0.0769
49
Ans:
06Process Optimization
Example 6-1-8
Solve the following two-dimensional semi-infinite
optimization problem (MATLAB User’s Guide, 1997)
50
where w =[w1 w2 ] with 1 ≤ w1 ≤ 100 and 1 ≤ w2 ≤ 100 .
s.t.
06Process Optimization
Example 6-1-8
─────────────── ex6_1_8.m ───────────────
function ex6_1_8
%
% Example 6-1-8 Two-dimensional semi-infinite optimization
%
clear; close all;
clc
%
x0=[0.5 0.5 0.5]'; % initial guess values
%
% solve the 2D semi-infinite optimization problem
%
[x, f]=fseminf(@fun6_1_8, x0, 1, @seminfcon6_1_8);
%
[c, ceq, k]=seminfcon6_1_8(x, [0.2 0.2]);
kmax=max(max(k)); % the maximum value in the constraint
51
Ans:
06Process Optimization
─────────────── ex6_1_8.m ───────────────
function ex6_1_8
%
% Example 6-1-8 Two-dimensional semi-infinite optimization
%
clear; close all;
clc
%
x0=[0.5 0.5 0.5]'; % initial guess values
%
% solve the 2D semi-infinite optimization problem
%
[x, f]=fseminf(@fun6_1_8, x0, 1, @seminfcon6_1_8);
%
[c, ceq, k]=seminfcon6_1_8(x, [0.2 0.2]);
kmax=max(max(k)); % the maximum value in the constraint
%
% Results printing
%
52
Ans:
06Process Optimization
─────────────── ex6_1_8.m ───────────────
fprintf('n if x1=%.3f, x2=%.3f, x3=%.3f, minimal value is…
f=%.3e',x(1),x(2),x(3),f)
fprintf('n the maximal value in the constraint is %.3fn', kmax)
%
% objective function
%
function f=fun6_1_8(x)
f=sum((x-0.5).^2);
%
% constraints
%
function [c, ceq, k, S]=seminfcon6_1_8(x, S)
%
% S matrix: distance between meshes
%
if isnan(S(1, 1))
S=[0.2 0.2];
53
Ans:
06Process Optimization
─────────────── ex6_1_8.m ───────────────
end
%
% meshes
%
w1=1:S(1,1):100;
w2=1:S(1,2):100;
[W1, W2]=meshgrid(w1, w2); % meshgrid for interlacing meshes in 2D
%
% semi-infinite constraints
%
k=sin(W1*x(1)).*cos(W1*x(2))-1/1000*(W1-50).^2-sin(W1*x(3))+...
sin(W2*x(2)).*cos(W1*x(1))-1/1000*(W2-50).^2-sin(W2*x(3))-2*x(3)-1.5;
%
c=[ ]; % no other nonlinear constraints
ceq=[ ];
%
% plotting during execution
%
54
Ans:
06Process Optimization
─────────────── ex6_1_8.m ───────────────
m=surf(W1, W2, k, 'edgecolor', 'non', 'facecolor', 'interp');
camlight headlight
xlabel('w1')
ylabel('w2')
zlabel('k')
title('semi-infinite constraint')
─────────────────────────────────────────────────
55
Ans:
06Process Optimization
Execution results:
>> ex6_1_8
if x1=0.503, x2=0.506, x3=0.492, minimal value is f=9.803e005
the maximal value in the constraint is -0.147
56
06Process Optimization
6.1.8 The minimax problem
[x, f, maxf] =fminimax('fun', x0, A, b, Aeq, beq, xL, xU, 'nonlcon', options)
57
s.t.
06Process Optimization
• objective functions
58
function f=fun(x)
f(l) =… % the first objective function
f(2) =… % the second objective function
⁞
f(n) =… % the n-th objective function
options = optimset('GradObj', 'on', 'GradConstr', 'on')
function [f, G] = fun(x)
f=[ ... % the first objective function
… % the second objective function
⁞
… % the n-th objective function
]
06Process Optimization
59
if nargout > 1
G=[ … % ∂f1 / ∂x
… % ∂f2 / ∂x
⁞
… % ∂fn / ∂x
]
end
function [c, ceq, Gc, Gceq] =nonlcon(x)
c =... % the nonlinear inequality constraints
ceq =... % the nonlinear equality constraints
if nargout > 2
Gc=… % gradients for inequality constraints
Gceq=… % gradients for equality constraints
end
06Process Optimization
Example 6-1-9
60
where
06Process Optimization
Example 6-1-9
─────────────── ex6_1_9.m ───────────────
function ex6_1_9
%
% Example 6-1-9 Minimax optimization
%
clear
clc
%
% initial guess values
%
x0=[2 2];
%
% solving the minimax optimization problem
%
[x, fval, fmax]=fminimax(@objfun, x0)
61
Ans:
06Process Optimization
─────────────── ex6_1_9.m ───────────────
%
% objective functions
%
function f=objfun(x)
x1=x(1);
x2=x(2);
f=[x1^2+x2^4
(2-x1)^2+(2-x2)^2
2*exp(x2-x1)];
─────────────────────────────────────────────────
62
Ans:
06Process Optimization
Execution results:
>> ex6_1_9
x =
1.1390 0.8996
fval =
1.9522
1.9522
1.5741
fmax =
1.9522
63
06Process Optimization
6.1.9 Binary integer programming problem
[x, fval]=bintprog(f, A, b, Aeq, beq, x0, options)
64
s.t.
06Process Optimization
Example 6-1-10
s.t.
6x1 + 3x2 + 5x3 + 2x4 ≤ 9
x3 + x4 ≤ 1
–x2 + x4 ≤ 0
x1 + x2 + x3 + x4 = 2
xi = 0 or 1, i = 1, 2, 3, 4
65
06Process Optimization
Example 6-1-10
66
Ans:
06Process Optimization
and
beq = 2
67
Ans:
>> f=[-9 -5 -6 -4]';
>> A=[6 3 5 2
0 0 1 1
-1 0 1 0
0 -1 0 1];
>> b=[9 1 0 0]';
>> Aeq=[1 1 1 1];
>> beq=2;
>> [x, fval]=bintprog(f,A, b,Aeq, beq)
Optimization terminated.
06Process Optimization
68
Ans:
x=
1
1
0
0
fval =
-14
06Process Optimization
6.1.10 A real-coded genetic algorithm for
optimization
 6.1.10.1 Fundamental principles of the real-coded
genetic algorithm
 Genetic algorithm (GA) is a kind of population-based
stochastic approach that mimics the natural selection and
survival of the fittest in the biological world.
 Let θ = [θ1, θ2, …, θn ] be a set of possible solutions
 The feasible solution Ωθ is expressed as follows:
69
06Process Optimization
6.1.10.1 Fundamental principles of the real-
coded genetic algorithm
I. Reproduction
• the reproduction is an evolutionary process to determine which
chromosome should be eliminated or reproduced in the
population.
• Using the scheme, pr × N chromosomes having worst
objective function values will be discarded and at the same
time other rp × N chromosomes that have better objective
functions are reproduced.
70
06Process Optimization
II. Crossover
• Crossover operation, which acts as a scheme to blend the
parents’ information for generating the offspring chromosomes,
is well recognized as the most important and effective
searching mechanism in RCGAs.
• if obj (θ1) < obj (θ2)
θ1 ← θ1 + r (θ1–θ2)
θ2 ← θ2 + r (θ1–θ2)
else
θ1 ← θ1 + r (θ2–θ1)
θ2 ← θ2 + r (θ2–θ1)
end
71
06Process Optimization
III. Mutation
• Mutation serves as a process to change the gene of a
chromosome (solution) randomly in order to increase the
population diversity and thus prevent the population from
premature convergence to a suboptimal solution.
θ ← θ + s × Φ
• The operational procedure of the RCGA
Step 1:Set the number of chromosomes in the population N, and the
relevant probability values pr, pc, and pm. Meanwhile, the
maximum number of generations G is also assigned.
Step 2:Randomly produce N chromosomes from the feasible domain Ωθ.
Step 3:Evaluate the corresponding objective function value for each
chromosome in the population.
72
06Process Optimization
III. Mutation
Step 4:The genetic evolution terminates once the computation process has
reached the specified maximum number of generations or the
objective function has attained an optimal value.
Step 5:Implement the operations of reproduction, crossover, and mutation
in the genetic evolution. Note that if the chromosomes of the
offspring produced exceed the feasible range Ωθ, the chromosomes
before the evolution are retained.
Step 6:Go back to Step 3.
73
06Process Optimization
6.1.10.2 Application of the real-coded genetic
algorithm to solve optimization problems
s.t.
c(x) ≤ 0
c eq (x) = 0
Ax ≤ b
Aeq x = beq
xL ≤ x ≤ xU
74
06Process Optimization
75
[x , fval]=rcga('fun', A, b, Aeq, beq, xL, xU, 'nonlcon', param)
Param Description
param(1) Number of chromosomes in the population, N
param(2) Reproduction probability, pr
param(3) Crossover probability threshold, pc
param(4) Mutation probability, pm
param(5) Maximum number of generations, G
06Process Optimization
Example 6-1-11
s.t.
0 ≤ 85.334407 + 0.0056858x2 x5+ 0.00026x1 x4 – 0.0022053x3 x5 ≤ 92
90 ≤ 80.51249 + 0.0071317x2 x5+ 0.0029955x1 x2+ 0.0021813x2
3 ≤ 110
20 ≤ 9.300961+ 0.0047026x3 x5+ 0.0012547x1 x3+ 0.0019085x3 x4 ≤ 25
78 ≤ x1 ≤ 102
33 ≤ x2 ≤ 45
27 ≤ x3, x4, x5 ≤ 45
76
06Process Optimization
MATLAB program design:
N= 200, Pr = 0.2, Pc = 0.3, Pm = 0.7 and G = 500.
─────────────── ex6_1_11 ───────────────
function ex6_1_11
%
% Example 6-1-11 Optimization with the real-coded genetic algorithm
%
clear
clc
%
% the RCGA parameters
%
N=200; % Number of populations
Pr=0.2; % Reproduction probability
Pc=0.3; % Crossover probability threshold
Pm=0.7; % Mutation probability
G=500; % Maximum generation numbers
77
06Process Optimization
MATLAB program design:
─────────────── ex6_1_11 ───────────────
% the linear constraints
%
A=[ ];
b=[ ];
Aeq=[ ];
beq=[ ];
%
% the upper and lower bounds of the decision variables
%
xL=[78 33 27 27 27]; % lower bound
xU=[102 45 45 45 45]; % upper bound
%
% rearrange the RCGA parameters into param
%
param=[N Pr Pc Pm G]; % RCGA parameter vector
%
% solving with the real-coded genetic algorithm
78
06Process Optimization
MATLAB program design:
─────────────── ex6_1_11 ───────────────
%
[x, f]=rcga(@fun, A, b, Aeq, beq, xL, xU, @nonlcon, param);
[c, ceq]=nonlcon(x) % check the satisfaction of the constraints
%
% results printing
%
fprintf('n The optimal solution is x_%i=%.3fn',[1:length(x); x])
fprintf('n The minimum objective function = %.3fn', f)
%
% Objective function
%
function f=fun(x)
x1=x(1); x2=x(2); x3=x(3); x4=x(4); x5=x(5);
f=5.3578547*x3^2+0.8356891*x1*x5+37.293239*x1-40792.141;
%
% nonlinear constraints
%
79
06Process Optimization
MATLAB program design:
─────────────── ex6_1_11 ───────────────
function [c, ceq]=nonlcon(x)
x1=x(1); x2=x(2); x3=x(3); x4=x(4); x5=x(5);
f1=85.334407+0.0056858*x2*x5+0.00026*x1*x4-0.0022053*x3*x5;
f2=80.51249+0.0071317*x2*x5+0.0029955*x1*x2+0.0021813*x3^2;
f3=9.300961+0.0047026*x3*x5+0.0012547*x1*x3+0.0019085*x3*x4;
c=[-f1; f1-92; 90-f2; f2-110; 20-f3; f3-25];
ceq=[ ];
─────────────────────────────────────────────────
80
06Process Optimization
Execution results:
>> ex1_1_11
81
c =
-92.0000
0
-10.4048
-9.5952
0
-5.0000
ceq =
[ ]
The optimal solution is x_1=78.000
The optimal solution is x_2=33.000
The optimal solution is x_3=27.071
The optimal solution is x_4=45.000
The optimal solution is x_5=44.969
The minimum objective function = -31025.560
(Gen and Cheng, 1997), which is
ƒ* = −30665.5 at x*
= [78 33 29.995 45 36.776].
06Process Optimization
Example 6-1-12
Resolve the problem in Example 6-1-5 with the real-coded
genetic algorithm
82
MATLAB program design:
0 ≤ xi ≤ 25, i = 1, 2, 3.
06Process Optimization
MATLAB program design:
─────────────── ex6_1_12.m ───────────────
function ex6_1_12
%
% Example 6-1-12 Optimization with RCGA
%
clear
clc
%
% the RCGA parameters
%
N=500; % Population number
Pr=0.2; % Reproduction probability
Pc=0.3; % Crossover probability threshold
Pm=0.7; % Mutation probability
G=1000; % Maximum generation number
%
% linear equality and inequality restraints
%
83
06Process Optimization
MATLAB program design:
─────────────── ex6_1_12.m ───────────────
A=[-1 -2 -2; 1 2 2];
b=[0 72]';
Aeq=[ ];
beq=[ ];
%
% the upper and lower bounds
%
xL=[0 0 0]; % lower bound
xU=[25 25 25]; % upper bound
%
% rearrange the RCGA parameters into param
%
param=[N Pr Pc Pm G]; % the RCGA parameters
%
% Solving with RCGA
%
[x, f]=rcga(@fun, A, b, Aeq, beq, xL, xU, @nonlcon, param);
84
06Process Optimization
MATLAB program design:
─────────────── ex6_1_12.m ───────────────
A*x'-b;
f=fun(x);
[c, ceq]=nonlcon(x);
%
% result printing
%
fprintf('n The optimal solution is x_%i=%.3fn', [1:length(x); x])
fprintf('n The minimum objective function = %.2fn', f)
%
% objective function
%
function f=fun(x)
x1=x(1);
x2=x(2);
x3=x(3);
f=-x1*x2^2*x3;
%
85
06Process Optimization
MATLAB program design:
─────────────── ex6_1_12.m ───────────────
% nonlinear constraints
%
function [c, ceq]=nonlcon(x)
x1=x(1);
x2=x(2);
x3=x(3);
c=x1*x3-0.5*x2^2-380;
ceq=x2*x3-144;
─────────────────────────────────────────────────
86
06Process Optimization
Execution results:
>> ex6_1_12
87
The optimal solution is x_1=20.000
The optimal solution is x_2=18.000
The optimal solution is x_3=8.000
The minimum objective function = -51840.00
06Process Optimization
6.2 Chemical engineering examples
Example 6-2-1
Maximizing the profit of a production system
88
A
B
C
E
F
G
Process 1
Process 2
Process 3
Process 1: A+B→E
Process 2: A+B→F
Process 3: 3A+2B+C→G
06Process Optimization
89
Raw material
Daily maximum supply
(lb/day)
Unit price ($/lb)
A 45,000 0.015
B 35,000 0.020
C 25,000 0.025
06Process Optimization
90
Process Product
The raw materials
required per pound of
product (lb)
Operation
costs
Price of
product
1 E
2
3
A,
1
3
B 0.015$/lb E 0.040$/lb E
2 F
2
3
A,
1
3
B 0.005$/lb F 0.033$/lb F
3 G
1
2
A,
1
6
B,
1
3
C 0.010$/lb G 0.038$/lb G
Determine the operating condition such that the daily profit is
maximized. And how much is the maximum profit?
06Process Optimization
Problem formulation and analysis:
Let x1~x6 denote the daily consumption of the raw materials A, B,
and C and the production quantities of the products E, F, and G,
respectively.
91
Cost of raw materials: C1 = 0.015x1+ 0.02x2 + 0.025x3
Operation cost: C2 = 0.015x4 + 0.005x5 + 0.01x6
daily total cost: C = C1 + C2
F = IC − C
= 0.025x4 +0.028x5 + 0.028x6 − 0.015x1 − 0.02x2 − 0.025x3
06Process Optimization
Problem formulation and analysis:
x1 = 0.667x4 + 0.667x5 + 0.5x6
x2 = 0.333x4 + 0.333x5 + 0.167x6
x3 = 0.333x6
0 ≤ x1 ≤ 45,000
0 ≤ x2 ≤ 35,000
0 ≤ x3 ≤ 25,000
92
06Process Optimization
Problem formulation and analysis:
93
06Process Optimization
MATLAB program design:
─────────────── ex6_2_1.m ───────────────
function ex6_2_1
%
% Example 6-2-1 Maximal profit of a production system
%
clear
clc
% Relevant parameters in a linear programming problem
%
n=6; % Number of variables
f=[ -0.015 -0.02 -0.025 0.025 0.028 0.028]';
Aeq=[1 0 0 -0.667 -0.667 -0.5
0 1 0 -0.333 -0.333 -0.167
0 0 1 0 0 -0.333];
beq=zeros(3,1);
xL=zeros(l,n);
xU=[45000 35000 25000 inf inf inf];
94
06Process Optimization
MATLAB program design:
─────────────── ex6_2_1.m ───────────────
A=[ ];
b=[ ];
%
% Solve the linear programming problem with linprog
%
[x, fval]=linprog(-f, A, b, Aeq, beq, xL, xU); % Note that –f is used
%
% Results printing
%
for i=l: n
fprintf('n The optimal solution x(%d) is %.3f', i, x(i))
end
fprintf('n The maximum profits are =%.3f.n', -fval) % NOTE: -fval
─────────────────────────────────────────────────
95
06Process Optimization
Execution results:
>> ex6_2_1
The optimal solution is x(1)=45000.000
The optimal solution is x(2)=16263.175
The optimal solution is x(3)=25000.000
The optimal solution is x(4)=0.000
The optimal solution is x(5)=11188.100
The optimal solution is x(6)=75075.075
The maximum profit is f=790.105.
96
06Process Optimization
Example 6-2-2
The optimal photoresist film thickness in a wafer production
process
According to practical operation experiences, one can summarize
the factors that affect the quality of printed circuits in a wafer
production process as follows (Edgar and Himmelblau, 1989):
1. Inadequately lower photoresist film thickness can inevitably
increase the defect ratio. The correlation between the defect
ratio and the film thickness is expressed by
D0 =1.5 d −3
where D0 is the defect ratio and d is the film thickness
(micrometers).
97
06Process Optimization
2. The percentage of perfect chips in the circuit layer can be
estimated by
𝜂 =
1
1+𝛽𝐷0 𝑎 4
where a is the activated area of the chips and β is the
percentage of severe defects.
3. The increment of the photoresist film thickness tends to
reduce the wafer production capacity; the relationship is
given as follows:
V = 125 − 50d + 5d 2
98
06Process Optimization
Note that the unit of V is wafers/h. Besides, the following process
information and statistical data are known: each wafer contains
100 chips, each chip has an activated area of 0.25 and the
percentage of severe defects is 30% (i.e., β = 0.3). Based on the
above, determine the optimal photoresist film thickness that
maximizes the production amount of perfect chips.
NOTE:
the admissible photoresist film thickness lies in the range of 0.5 ≤
d ≤ 2.5.
99
06Process Optimization
Problem formulation and analysis:
the hourly production number of perfect chips,
100
where β = 0.3, a = 0.25, and 0.5 ≤ d ≤ 2.5.
06Process Optimization
101
Ans:
>> f=inline('- 100*(125-50*d+5*d^2)/(1+0.3*0.25*1.5*d^(-3))^4');
>> [d, fval]=fminbnd(f, 0.5, 2.5)
d=
1.2441
fval =
-5.6203e+003
06Process Optimization
Example 6-2-3
Minimal energy of a chemical equilibrium system
Find the mole fraction of each component such that the energy
function
is minimized subject to following equality constraints derived
from material balances
x1 + 2x2 + 2x3 + x6 + x10 = 2
102
06Process Optimization
x4 + 2x5 + x6 + x7 = 1
x31 + x7 + x8 + 2x9 + x10 = 1
The values of the coefficient in Equation (6.2-15) are listed in
the following table:
Note that the system is operated under the total pressure of P =
760 mmHg.
103
i 1 2 3 4 5
wi 10.021 21.096 37.986 9.846 28.653
i 6 7 8 9 10
wi 18.918 28.032 14.640 30.594 26.111
06Process Optimization
MATLAB program design:
Because the mole fraction xi must satisfy 0 ≤ xi ≤ 1, these
additional constraints should be added into the optimization
problem.
─────────────── ex6_2_3.m ───────────────
function ex6_2_3
%
% Example 6-2-3 Energy minimization of a chemical equilibrium system
%
clear
clc
%
global w P
%
% System data: w values
%
w=[-10.021 -21.096 -37.986 -9.846 -28.653 -18.918 -28.032 -14.640… -30.594 -
26.111]; %
104
06Process Optimization
MATLAB program design:
─────────────── ex6_2_3.m ───────────────
P=760; % Pressure (mmHg)
%
% Initial guess values
%
x0=0.5*ones(1, 10);
%
% Constraints
%
Aeq=[1 2 2 0 0 1 0 0 0 1
0 0 0 1 2 1 1 0 0 0
0 0 1 0 0 0 1 1 2 1];
beq=[2 1 1]';
xL=eps*ones(1,10); % Lower bounds of the decision variables
xU=ones(1,10); % Upper bounds of the decision variables
%
% Solving the optimization problem with fmincon
%
105
06Process Optimization
MATLAB program design:
─────────────── ex6_2_3.m ───────────────
[x, fval]=fmincon(@fun, x0, [], [], Aeq, beq, xL, xU);
%
% Results printing
%
disp('The mole fraction of each component is')
x
disp('The minimal energy function value is')
fval
%
% Objective function
%
function f=fun(x)
global w P
%
f=sum(x.*(w+log(P)+log(x./sum(x))));
─────────────────────────────────────────────────
106
06Process Optimization
Execution results:
>> ex6_2_3
The mole fraction of each component is
x =
Columns 1 through 6
0.0070 0.0678 0.9076 0.0004 0.4909 0.0005
Columns 7 through 10
0.0173 0.0029 0.0152 0.0418
The minimal energy function value is
fval =
-43.4740
107
06Process Optimization
Execution results:
>> ex6_2_3
NOTE:
In the MATLAB program, the lower bound 0 is replaced by eps
(2.2204  l016) to avoid the numerical problem arising from the
calculation of natural logarithm for the objective function.
108
06Process Optimization
Example 6-2-4
Maximal profit of an alkylation process
Consider the alkylation process shown in the following figure
(Edgar and Himmelblau, 1989).
109
Reactor
Fractionator
Hydrocarbon
Olefin
Isobutane
Acid
Recycle of isobutane, x2
Alkylate product
Spent acids
x3
x1
x5
06Process Optimization
110
Variables Physical significance Unit
Lower
bound
Upper
bound
x1 Olefin feed Barrel/day 0 2,000
x2 Isobutane recycled Barrel/day 0 16,000
x3 Feed of fresh acid
Thousands of
pounds per day
0 120
x4 Alkylate yield Barrel/day 0 5,000
x5 Isobutane makeup Barrel/day 0 2,000
x6 Acid strength Weight percentage 85 93
x7 Motor octane number - 90 95
x8
External
isobutene-to-olefin ratio
- 3 12
x9 Acid dilution factor - 1.2 4
x10 F-4 performance number - 145 162
06Process Optimization
The objective function,
111
Parameter Physical meaning Value Unit
c1 Alkylate product value 0.063 $/barrel
c2 Olefin feed cost 5.04 $/barrel
c3 Isobutane recycle cost 0.035 $/barrel
c4 Acid addition cost 10 $/thousand lbs
c5 Isobutane makeup cost 3.36 $/barrel
06Process Optimization
112
06Process Optimization
To include the process uncertainties in the formulation,
113
06Process Optimization
where the values of 𝑑𝑖
−
and 𝑑𝑖
+
are listed in the following table:
114
𝑑4
−
𝑑4
+
𝑑7
−
𝑑7
+
𝑑9
−
𝑑9
+
𝑑10
−
𝑑10
+
95
100
100
95
95
100
100
95
95
100
100
95
95
100
100
95
06Process Optimization
MATLAB program design:
─────────────── ex6_2_4.m ───────────────
function ex6_2_4
%
% Example 6-2-4 Maximum profit in an alkylation process
%
clear
clc
%
% Upper and lower bounds of the decision variables
%
xL=[0 0 0 0 0 85 90 3 1.2 145]';
xU=[2000 16000 120 5000 2000 93 95 12 4 162]';
%
% Initial guess values
%
x0=[1745 12000 110 3048 1974 89.2 92.8 8 3.6 145]';
%
% Linear constraints
115
06Process Optimization
MATLAB program design:
─────────────── ex6_2_4.m ───────────────
%
Aeq=[-1 0 0 1.22 -1 0 0 0 0 0]; % Eq. (6.2-20)
beq=0;
%
A=[0 0 0 0 0 0 0 0 95/100 0.222 % Eq. (6.2-30)
0 0 0 0 0 0 0 0 -100/95 -0.222 % Eq. (6.2-31)
0 0 0 0 0 0 -3 0 0 95/100 % Eq. (6.2-32)
0 0 0 0 0 0 3 0 0 -100/95]; % Eq. (6.2-33)
b=[35.82 -35.82 -133 133]';
%
% Solving with fmincon
%
[x, f]=fmincon(@fun, x0, A, b, Aeq, beq, xL, xU, @nonlcon);
%
% Results printing
%
disp('The optimal solution is:')
116
06Process Optimization
MATLAB program design:
─────────────── ex6_2_4.m ───────────────
fprintf('n The maximum profit is %.3fn.', -f)
%
% Objective function
%
function f=fun(x)
x1=x(1);x2=x(2);x3=x(3);x4=x(4);x5=x(5);
x6=x(6);x7=x(7);x8=x(8);x9=x(9);x10=x(10);
f=0.063*x4*x7-5.04*x1-0.035*x2-10*x3-3.36*x5;
f=-f;
%
% Nonlinear constraints
%
function [c, ceq]=nonlcon(x)
x1=x(1);x2=x(2);x3=x(3);x4=x(4);x5=x(5);
x6=x(6);x7=x(7);x8=x(8);x9=x(9);x10=x(10);
c=[-x1*(1.12+0.13167*x8-0.00667*x8^2)+95/100*x4 % (6.2-26)
117
06Process Optimization
MATLAB program design:
─────────────── ex6_2_4.m ───────────────
x1*(1.12+0.13167*x8-0.00667*x8^2)-100/95*x4 % Eq. (6.2-27)
-(86.35+1.098*x8-0.038*x8^2+0.325*(x6-89))+95/100*x7 % (6.2-28)
86.35+1.098*x8-0.038*x8^2+0.325*(x6-89)-100/95*x7]; % Eq. (6.2-29)
ceq=[x6*(x4*x9+1000*x3)-98000*x3 % Eq. (6.2-21)
x8*x1-x2-x5]; % Eq. (6.2-23)
─────────────────────────────────────────────────
118
06Process Optimization
Execution results:
>> ex6_2_4
The optimal solution is:
x =
1.0e+003 *
1.7506
8.4495
0.0241
3.0743
2.0000
0.0850
0.0950
0.0060
0.0012
0.1562
The maximum profit is 2319.484.
119
06Process Optimization
Example 6-2-5
Maximum separation efficiency in a single-effect distillatory
Consider a two-component single-effect distillation tower
operated at one atmospheric pressure. The relationship between
the liquid-phase mole fraction x and the vapor-phase mole
fraction y of the light key component is shown in the following
table (Leu, 1985):
120
x 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
y 0 0.191 0.339 0.480 0.618 0.730 0.812 0.864 0.913 0.959 1.0
06Process Optimization
Let z and F denote, respectively, the mole fraction of the light key
component in the feed and the feeding rate. Then, the separation
efficiency of the single-effect distillation tower can be defined as
where d = D/F is the ratio of the flow rate of distillate to the
feeding rate. Based on the above-mentioned operating conditions,
determine the values of d and x such that the separation efficiency
is maximized under each of the feed condition of z ranging from
0.1 to 0.9 with an interval of 0.1.
121
06Process Optimization
Problem formulation and analysis:
122
F, z
D, y
W, x
Feed
Single-
effect
distillation
tower
Vapor
Liquid
06Process Optimization
Problem formulation and analysis:
F = D + W
Fz = Dy + Wx
Let w = W/F,
d = w + 1
z = dy + wx
y = f (x)
123
06Process Optimization
MATLAB program design:
─────────────── ex6_2_5.m ───────────────
function ex6_2_5
%
% Example 6-2-5 Maximum separation efficiency of a single-effect distillatory
%
clear; close all;
clc
%
global z xe ye
%
% equilibrium data
%
xe=0:0.1:1;
ye=[0 0.191 0.339 0.480 0.618 0.730 0.812 0.864 0.913 0.959 1.0];
%
% initial guess values
%
p0=[0.5 0.5];
124
06Process Optimization
MATLAB program design:
─────────────── ex6_2_5.m ───────────────
function ex6_2_5
%
% Example 6-2-5 Maximum separation efficiency of a single-effect distillatory
%
clear; close all;
clc
%
global z xe ye
%
% equilibrium data
%
xe=0:0.1:1;
ye=[0 0.191 0.339 0.480 0.618 0.730 0.812 0.864 0.913 0.959 1.0];
%
% initial guess values
%
p0=[0.5 0.5];
125
06Process Optimization
MATLAB program design:
─────────────── ex6_2_5.m ───────────────
%
% Upper and lower bounds of the decision variables
%
xL=[0 0];
xU=[1 1];
%
% finding the optimal solution to each case of z values
%
for i=1:9
z=0.1*i;
[p, f]=fmincon(@fun, p0, [], [], [], [], xL, xU, @nonlcon);
dopt(i)=p(1);
xopt(i)=p(2);
eta(i)=-f;
end
%
% Results printing
126
06Process Optimization
MATLAB program design:
─────────────── ex6_2_5.m ───────────────
%
for i=1:9
z=0.1*i;
fprintf('n When z=%.1f, d=%.3f, x=%.3f, the optimal efficiency is =…
%.3f.', z, dopt(i), xopt(i), eta(i))
end
%
% Plot a figure to show the variations of the optimal results
%
z=0.1:0.1:0.9;
plot(z, eta, z, eta, '*')
title('Variations of the optimial results')
xlabel('Mole fraction of the light key component in the feeding stream, z')
ylabel('Maximum separation efficiency')
%
% Objective function
%
127
06Process Optimization
MATLAB program design:
─────────────── ex6_2_5.m ───────────────
function f=fun(p)
global z xe ye
d=p(1);
x=p(2);
y=interp1(xe, ye, x, 'cubic');
f=-d*(y-z)/(z*(1-z));
%
% Contraints
%
function [c, ceq]=nonlcon(p)
global z xe ye
d=p(1);
x=p(2);
w=1-d;
y=interp1(xe, ye, x, 'cubic');
c=[ ];
ceq=z-d*y-w*x;
─────────────────────────────────────────────────
128
06Process Optimization
Execution results:
>> ex6_2_5
When z=0.1, d=0.426, x=0.071, the optimal efficiency is = 0.188.
When z=0.2, d=0.454, x=0.147, the optimal efficiency is = 0.180.
When z=0.3, d=0.457, x=0.231, the optimal efficiency is = 0.180.
When z=0.4, d=0.456, x=0.315, the optimal efficiency is = 0.192.
When z=0.5, d=0.472, x=0.397, the optimal efficiency is = 0.217.
When z=0.6, d=0.499, x=0.485, the optimal efficiency is = 0.240.
When z=0.7, d=0.541, x=0.582, the optimal efficiency is = 0.257.
When z=0.8, d=0.584, x=0.706, the optimal efficiency is = 0.245.
When z=0.9, d=0.595, x=0.848, the optimal efficiency is = 0.235.
129
06Process Optimization
130
06Process Optimization
Example 6-2-6
Dynamic optimization of an ammonia synthesis process
Haber-Bosch synthesis process
N2 + 3H2 ⇆ 2NH3
131
s.t.
06Process Optimization
132
06Process Optimization
133
where
06Process Optimization
134
06Process Optimization
135
Parameter Physical meaning Value Unit
Cpf Heat capacity of the feed 0.707 kcal/(kg∙K)
Cpg Heat capacity of the reaction gas 0.719 kcal/(kg∙K)
r Activity of the catalyst 0.95 -
ΔH Heat of reaction 26,600 kcal /(kg-mol N2)
𝑁N2
0 The molar flow rate of N2 in the
feed
701.2 kg-mol/(m2∙hr)
PT Total pressure 268 psi
R Ideal gas constant 1.987 kcal/(kg-mol∙K)
S1
Heat transfer area per unit of
reactor length
10 m
S2
Cross-sectional area of the catalyst
section
0.78 m2
U
Overall heat conduction
coefficient
500 kcal/(hr∙m2 ∙ K)
W Overall mass transport rate 26,400 kg/hr
Solve the dynamic optimization problem under the above-mentioned operating condition.
06Process Optimization
Analysis of the question:
136
06Process Optimization
Analysis of the question:
where z = x/L is the defined dimensionless variable and the
decision variable L (the reactor length) is in the range of 0 ≤ L ≤
20.
137
06Process Optimization
MATLAB program design:
─────────────── ex6_2_6.m ───────────────
function ex6_2_6
%
% Example 6-2-6 Optimization of an ammonia synthesis process
%
clear; close all;
clc
%
global PT U S1 S2 W Cpf Cpg dH R r NN20 L
%
% Model parameters
%
PT=286; % Total pressure (psi)
Cpf=0.707; % Heat capacity of the feed, kcal/(kg.K)
Cpg=0.719; % Heat capacity of the reaction gas, kcal/(kg.K)
r=0.95; % Catalyst activity
dH=-26600; % Heat of reaction, kcal/(kg-mol N2)
R=1.987; % Ideal gas constant, kcal/(kg-mol.K)
138
06Process Optimization
MATLAB program design:
─────────────── ex6_2_6.m ───────────────
S1=10; % Heat transfer area per unit of reactor length, m
S2=0.78; % cross-sectional area of the catalyst section, m^2
U=500; % Overall heat conduction coefficient, kcal/(h.m^2.K)
W=26400; % Overall mass transport rate, kg/h
NN20=701.2; % Mole flow rate of ammonia in the feed, kg-mol/(m^2.h)
%
% Upper and lower bounds of the reactor length (the decision variable)
%
pL=1;
pU=20;
%
% Solve the optimization problem with fminbnd
%
[L, fval]=fminbnd(@objfun, pL, pU);
%
% Results printing
%
139
06Process Optimization
MATLAB program design:
─────────────── ex6_2_6.m ───────────────
fprintf('n The optimal reactor length is %.3f m, and the maximum profit is…
%.3e.', L, -fval)
%
% Results plotting
%
solinit=bvpinit(linspace(0,1,20), @init);
sol=bvp4c(@ode, @bc, solinit);
xint=linspace(0,1);
yint=deval(sol, xint);
plot(xint, yint(1,:), 'r', xint, yint(2,:), '-.b', xint, yint(3,:), '--c')
legend('Tf', 'Tg', 'NN2')
xlabel('The dimensionless reactor length (z)')
ylabel('System states')
axis([0 1 670 735])
%
% objective function
%
140
06Process Optimization
MATLAB program design:
─────────────── ex6_2_6.m ───────────────
function f=objfun(p)
global PT U S1 S2 W Cpf Cpg dH R r NN20 L
L=p;
%
% Solve for the BVP ODE model
%
xint=linspace(0,1,20);
solinit=bvpinit(xint, @init);
sol=bvp4c(@ode, @bc, solinit);
yint=deval(sol, xint);
index=length(xint);
Tf=yint(1,index);
Tg=yint(2,index);
NN2=yint(3,index);
%
% Calculate the objective function value
%
141
06Process Optimization
MATLAB program design:
─────────────── ex6_2_6.m ───────────────
f=1.198e7-1.710e4*NN2+704.4*Tg-699.3*Tf-(3.456e7+2.101e9*L)^0.5;
f=-f;
%
% The ODE model
%
function dydt=ode(t, y)
global PT U S1 S2 W Cpf Cpg dH R r NN20 L
Tf=y(1);
Tg=y(2);
NN2=y(3);
k1=1.7895e4*exp(-20800/(R*Tg));
k2=2.5714e16*exp(-47400/(R*Tg));
B=NN20-NN2;
N=100*NN20/21.75;
A=5/100*N+2*B;
PN2=PT*NN2/(N-2*B);
PH2=PT*(3*NN2)/(N-2*B);
142
06Process Optimization
MATLAB program design:
─────────────── ex6_2_6.m ───────────────
PNH3=PT*A/(N-2*B);
Q=r*(1.5*k1*PN2*PH2/PNH3-k2*PNH3/(1.5*PH2));
dydt=L*[-U*S1*(Tg-Tf)/(W*Cpf)
-U*S1*(Tg-Tf)/(W*Cpg)+(-dH)*S2*Q/(W*Cpg)
-Q];
%
% Boundary conditions
%
function res=bc(ya, yb)
res=[yb(1)-693
ya(2)-693
ya(3)-701.2];
%
% Initial guess values
%
function yinit=init(x)
yinit=[693
143
06Process Optimization
MATLAB program design:
─────────────── ex6_2_6.m ───────────────
693
701.2];
─────────────────────────────────────────────────
144
06Process Optimization
Execution results:
>> ex6_2_6
The optimal reactor
length is 14.313 m,
and the maximum
profit is 3.125e+005.
145
06Process Optimization
Example 6-2-7
Optimal operating temperature for a tubular reactor
146
06Process Optimization
Suppose the reaction time is 10 hours, determine the optimal
profile of the operating temperature such that the concentration of
the product B (x2) is maximized at the end of the reaction.
147
I ki0 Ei
1 5.35  105 1.82  104
2 4.61  109 3.16  104
3 2.24  108 2.87  104
06Process Optimization
Problem formulation and analysis:
148
where τ = t/tf (0 ≤ τ ≤ 1) is the dimensionless time and the
reaction time is tƒ = 10 hr.
s.t.
06Process Optimization
MATLAB program design:
─────────────── ex6_2_7.m ───────────────
function ex6_2_7
%
% Example 6-2-7 Optimal operating temperature in a tubular reactor
%
clear; close all;
clc
%
global x0 tspan k0 ER tf dt T
%
% System operation data
%
x0=[0.95 0.05]'; % Initial state values
k0=[5.35e5 4.61e9 2.24e8]; % ko value
E=[1.82e4 3.16e4 2.87e4]; % E value
R=1.987; % Ideal gas constant (kcal/kg-mol.K)
ER=E/R; % E/R value
tf=10; % reaction time (hr)
149
06Process Optimization
MATLAB program design:
─────────────── ex6_2_7.m ───────────────
%
n=10; % number of sections (intervals) N=n+1;
N=n+1; % % number of points
dt=1/n; % time interval
tspan=linspace(0, 1, N); % dimensionless time
%
% Upper and lower bounds and the initial guess values
%
pL=[273*ones(1,N)]/100; % Lower bounds
pU=[873*ones(1,N)]/100; % Upper bounds
p0=(pL+pU)/2; % Initial guess value
%
% Solve the dynamic optimization problem
%
[P, fval]=fmincon(@objfun, p0, [ ], [ ], [ ], [ ], pL, pU);
%
% Results printing
150
06Process Optimization
MATLAB program design:
─────────────── ex6_2_7.m ───────────────
%
T=P*100;
fprintf('n At the end of the reaction, the maximum value of x2 is %.3f.n', -fval)
%
% Numerical solution of the ODE
%
[s, x]=ode45(@ode, tspan, x0);
%
% Plot of the system states
%
figure(1)
plot(s,x(:,1), 'r', s, x(:,2), '-.b')
xlabel('Dimensionless time, t/tf')
ylabel('System states')
legend('x1', 'x2')
%
% Optimal temperature distribution
151
06Process Optimization
MATLAB program design:
─────────────── ex6_2_7.m ───────────────
%
figure(2)
stairs(s, T)
xlabel('Dimensionless time, t/tf')
ylabel('Temperature (K)')
title('Optimal temperature distribution')
%
% Objective function
%
function f=objfun(P)
global x0 tspan k0 ER tf dt T
%
T=P*100;
%
% Solving the ODE
%
[s, x]=ode45(@ode, tspan, x0);
152
06Process Optimization
MATLAB program design:
─────────────── ex6_2_7.m ───────────────
%
% Calculating the objective function value
%
f=x(end, 2);
f=-f;
%
% Kinetic equations
%
function dxdtau=ode(tau, x)
global x0 tspan k0 ER tf dt T
i=floor(tau/dt)+1;
Ti=T(i);
k=k0.*exp(-ER/Ti);
k1=k(1);k2=k(2);k3=k(3);
dxdtau=tf*[-k1*x(1)^2+k2*x(2)
k1*x(1)^2-(k2+k3)*x(2)];
─────────────────────────────────────────────────
153
06Process Optimization
Execution results:
>> ex6_2_7
At the end of the
reaction, the maximum
value of x2 is 0.545.
154
06Process Optimization
155
06Process Optimization
6.4 Summary of the MATLAB commands related
to this chapter
156
Command Function
fminbnd The solver for the solution of univariate optimization problems
fminunc The solver for multivariate optimization problems without constraints
fminsearch
The solver using Simplex method for the multivariate optimal problem
without constraints
linprog The solver for linear programming problems
quadprog The solver for quadratic programming problems
fmincon The solver for nonlinear optimization problems
fgoalattain The solver for multi-objective goal attainment optimization problems
fseminf The solver for semi-infinite optimization problems
fminimax The solver for minimax problems
bintprog The solver for binary integer programming problems
rcga A real-coded genetic algorithm for process optimization

Contenu connexe

Tendances

Aspen hysys dynamic modeling
Aspen hysys dynamic modelingAspen hysys dynamic modeling
Aspen hysys dynamic modeling
Lara Arinelli
 

Tendances (20)

Compressor Polytropic Efficiency Calculation
Compressor Polytropic Efficiency CalculationCompressor Polytropic Efficiency Calculation
Compressor Polytropic Efficiency Calculation
 
Ch 05 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
Ch 05 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片Ch 05 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
Ch 05 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
 
Introduction to optimization Problems
Introduction to optimization ProblemsIntroduction to optimization Problems
Introduction to optimization Problems
 
pressure drop calculation in sieve plate distillation column
pressure drop calculation in sieve plate distillation columnpressure drop calculation in sieve plate distillation column
pressure drop calculation in sieve plate distillation column
 
Design of thermosyphon reboiler
Design of thermosyphon reboilerDesign of thermosyphon reboiler
Design of thermosyphon reboiler
 
Introduction to DFT Part 1
Introduction to DFT Part 1 Introduction to DFT Part 1
Introduction to DFT Part 1
 
New approach for wolfe’s modified simplex method to solve quadratic programmi...
New approach for wolfe’s modified simplex method to solve quadratic programmi...New approach for wolfe’s modified simplex method to solve quadratic programmi...
New approach for wolfe’s modified simplex method to solve quadratic programmi...
 
Engineering Numerical Analysis Lecture-1
Engineering Numerical Analysis Lecture-1Engineering Numerical Analysis Lecture-1
Engineering Numerical Analysis Lecture-1
 
Reactors simulation note.pdf
Reactors simulation note.pdfReactors simulation note.pdf
Reactors simulation note.pdf
 
Introduction to multicomponent distillation
Introduction to multicomponent distillationIntroduction to multicomponent distillation
Introduction to multicomponent distillation
 
Process Simulation using DWSIM
Process Simulation using DWSIMProcess Simulation using DWSIM
Process Simulation using DWSIM
 
Excess gibbs free energy models
Excess gibbs free energy modelsExcess gibbs free energy models
Excess gibbs free energy models
 
Fixed bed
Fixed bedFixed bed
Fixed bed
 
Finite difference equation
Finite difference equationFinite difference equation
Finite difference equation
 
Van Laar & NRTL Equation in Chemical Engineering Thermodynamicas
Van Laar & NRTL Equation in Chemical Engineering ThermodynamicasVan Laar & NRTL Equation in Chemical Engineering Thermodynamicas
Van Laar & NRTL Equation in Chemical Engineering Thermodynamicas
 
Aspen hysys dynamic modeling
Aspen hysys dynamic modelingAspen hysys dynamic modeling
Aspen hysys dynamic modeling
 
Finite DIfference Methods Mathematica
Finite DIfference Methods MathematicaFinite DIfference Methods Mathematica
Finite DIfference Methods Mathematica
 
Matlab
Matlab Matlab
Matlab
 
Lecture5
Lecture5Lecture5
Lecture5
 
Wien2k getting started
Wien2k getting startedWien2k getting started
Wien2k getting started
 

Similaire à Ch 06 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片

Reformulating Branch Coverage as a Many-Objective Optimization Problem
Reformulating Branch Coverage as a Many-Objective Optimization ProblemReformulating Branch Coverage as a Many-Objective Optimization Problem
Reformulating Branch Coverage as a Many-Objective Optimization Problem
Annibale Panichella
 

Similaire à Ch 06 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片 (20)

Aplikom11 matlab or
Aplikom11 matlab orAplikom11 matlab or
Aplikom11 matlab or
 
Chap07
Chap07Chap07
Chap07
 
Linear Programming Review.ppt
Linear Programming Review.pptLinear Programming Review.ppt
Linear Programming Review.ppt
 
Xgboost
XgboostXgboost
Xgboost
 
Ch6
Ch6Ch6
Ch6
 
optimization methods by using matlab.pptx
optimization methods by using matlab.pptxoptimization methods by using matlab.pptx
optimization methods by using matlab.pptx
 
Lenier Equation
Lenier EquationLenier Equation
Lenier Equation
 
curve fitting or regression analysis-1.pptx
curve fitting or regression analysis-1.pptxcurve fitting or regression analysis-1.pptx
curve fitting or regression analysis-1.pptx
 
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
 
Python Lab manual program for BE First semester (all department
Python Lab manual program for BE First semester (all departmentPython Lab manual program for BE First semester (all department
Python Lab manual program for BE First semester (all department
 
Fmincon
FminconFmincon
Fmincon
 
李宏毅课件-Regression.pdf
李宏毅课件-Regression.pdf李宏毅课件-Regression.pdf
李宏毅课件-Regression.pdf
 
Multi objective optimization and Benchmark functions result
Multi objective optimization and Benchmark functions resultMulti objective optimization and Benchmark functions result
Multi objective optimization and Benchmark functions result
 
Xgboost
XgboostXgboost
Xgboost
 
Reformulating Branch Coverage as a Many-Objective Optimization Problem
Reformulating Branch Coverage as a Many-Objective Optimization ProblemReformulating Branch Coverage as a Many-Objective Optimization Problem
Reformulating Branch Coverage as a Many-Objective Optimization Problem
 
ECE 2103_L6 Boolean Algebra Canonical Forms [Autosaved].pptx
ECE 2103_L6 Boolean Algebra Canonical Forms [Autosaved].pptxECE 2103_L6 Boolean Algebra Canonical Forms [Autosaved].pptx
ECE 2103_L6 Boolean Algebra Canonical Forms [Autosaved].pptx
 
Numerical methods generating polynomial
Numerical methods generating polynomialNumerical methods generating polynomial
Numerical methods generating polynomial
 
Idea for ineractive programming language
Idea for ineractive programming languageIdea for ineractive programming language
Idea for ineractive programming language
 
A few solvers for portfolio selection
A few solvers for portfolio selectionA few solvers for portfolio selection
A few solvers for portfolio selection
 
Optimization
OptimizationOptimization
Optimization
 

Plus de Chyi-Tsong Chen

[電子書-Google Play Books] MATLAB程式設計與工程應用 2022 目錄表.pdf
[電子書-Google Play Books] MATLAB程式設計與工程應用 2022 目錄表.pdf[電子書-Google Play Books] MATLAB程式設計與工程應用 2022 目錄表.pdf
[電子書-Google Play Books] MATLAB程式設計與工程應用 2022 目錄表.pdf
Chyi-Tsong Chen
 
[E-book at Google Play Books] MATLAB Applications in Chemical Engineering (20...
[E-book at Google Play Books] MATLAB Applications in Chemical Engineering (20...[E-book at Google Play Books] MATLAB Applications in Chemical Engineering (20...
[E-book at Google Play Books] MATLAB Applications in Chemical Engineering (20...
Chyi-Tsong Chen
 
大學經營與治校理念_陳奇中教授金大演講投影片
大學經營與治校理念_陳奇中教授金大演講投影片大學經營與治校理念_陳奇中教授金大演講投影片
大學經營與治校理念_陳奇中教授金大演講投影片
Chyi-Tsong Chen
 
化工概論: 製程分析模擬最適化與控制_陳奇中教授演講投影片
化工概論: 製程分析模擬最適化與控制_陳奇中教授演講投影片化工概論: 製程分析模擬最適化與控制_陳奇中教授演講投影片
化工概論: 製程分析模擬最適化與控制_陳奇中教授演講投影片
Chyi-Tsong Chen
 
Reliability-Based Design Optimization Using a Cell Evolution Method ~陳奇中教授演講投影片
Reliability-Based Design Optimization Using a Cell Evolution Method ~陳奇中教授演講投影片Reliability-Based Design Optimization Using a Cell Evolution Method ~陳奇中教授演講投影片
Reliability-Based Design Optimization Using a Cell Evolution Method ~陳奇中教授演講投影片
Chyi-Tsong Chen
 
創意研發專論:創意規則 ~陳奇中教授演講投影片
創意研發專論:創意規則 ~陳奇中教授演講投影片創意研發專論:創意規則 ~陳奇中教授演講投影片
創意研發專論:創意規則 ~陳奇中教授演講投影片
Chyi-Tsong Chen
 
Data Driven Process Optimization Using Real-Coded Genetic Algorithms ~陳奇中教授演講投影片
Data Driven Process Optimization Using Real-Coded Genetic Algorithms ~陳奇中教授演講投影片Data Driven Process Optimization Using Real-Coded Genetic Algorithms ~陳奇中教授演講投影片
Data Driven Process Optimization Using Real-Coded Genetic Algorithms ~陳奇中教授演講投影片
Chyi-Tsong Chen
 
Designs of Single Neuron Control Systems: Survey ~陳奇中教授演講投影片
Designs of Single Neuron Control Systems: Survey ~陳奇中教授演講投影片Designs of Single Neuron Control Systems: Survey ~陳奇中教授演講投影片
Designs of Single Neuron Control Systems: Survey ~陳奇中教授演講投影片
Chyi-Tsong Chen
 
Intelligent Process Control Using Neural Fuzzy Techniques ~陳奇中教授演講投影片
Intelligent Process Control Using Neural Fuzzy Techniques ~陳奇中教授演講投影片Intelligent Process Control Using Neural Fuzzy Techniques ~陳奇中教授演講投影片
Intelligent Process Control Using Neural Fuzzy Techniques ~陳奇中教授演講投影片
Chyi-Tsong Chen
 
MATLAB教學經驗分享~陳奇中教授演講投影片
MATLAB教學經驗分享~陳奇中教授演講投影片MATLAB教學經驗分享~陳奇中教授演講投影片
MATLAB教學經驗分享~陳奇中教授演講投影片
Chyi-Tsong Chen
 
認識化工~陳奇中教授演講投影片
認識化工~陳奇中教授演講投影片認識化工~陳奇中教授演講投影片
認識化工~陳奇中教授演講投影片
Chyi-Tsong Chen
 
IEET工程教育認證經驗分享~陳奇中教授演講投影片
IEET工程教育認證經驗分享~陳奇中教授演講投影片IEET工程教育認證經驗分享~陳奇中教授演講投影片
IEET工程教育認證經驗分享~陳奇中教授演講投影片
Chyi-Tsong Chen
 
當mit遇見MIT_波士頓見聞分享~陳奇中教授演講投影片
當mit遇見MIT_波士頓見聞分享~陳奇中教授演講投影片當mit遇見MIT_波士頓見聞分享~陳奇中教授演講投影片
當mit遇見MIT_波士頓見聞分享~陳奇中教授演講投影片
Chyi-Tsong Chen
 
化工與我_學思紀行~陳奇中教授演講投影片
化工與我_學思紀行~陳奇中教授演講投影片化工與我_學思紀行~陳奇中教授演講投影片
化工與我_學思紀行~陳奇中教授演講投影片
Chyi-Tsong Chen
 
程序控制的最後一堂課_ 美好的人生就從今天起 ~陳奇中教授演講投影片
程序控制的最後一堂課_ 美好的人生就從今天起 ~陳奇中教授演講投影片程序控制的最後一堂課_ 美好的人生就從今天起 ~陳奇中教授演講投影片
程序控制的最後一堂課_ 美好的人生就從今天起 ~陳奇中教授演講投影片
Chyi-Tsong Chen
 

Plus de Chyi-Tsong Chen (20)

[E-book at Google Play Books] Exercises Solution Manual for MATLAB Applicatio...
[E-book at Google Play Books] Exercises Solution Manual for MATLAB Applicatio...[E-book at Google Play Books] Exercises Solution Manual for MATLAB Applicatio...
[E-book at Google Play Books] Exercises Solution Manual for MATLAB Applicatio...
 
[電子書-Google Play Books ] MATLAB在化工上之應用習題解答自學手冊 (2022).pdf
[電子書-Google Play Books ] MATLAB在化工上之應用習題解答自學手冊 (2022).pdf[電子書-Google Play Books ] MATLAB在化工上之應用習題解答自學手冊 (2022).pdf
[電子書-Google Play Books ] MATLAB在化工上之應用習題解答自學手冊 (2022).pdf
 
[電子書-Google Play Books ] MATLAB程式設計與工程應用習題解答自學手冊 (2022).pdf
[電子書-Google Play Books ] MATLAB程式設計與工程應用習題解答自學手冊 (2022).pdf[電子書-Google Play Books ] MATLAB程式設計與工程應用習題解答自學手冊 (2022).pdf
[電子書-Google Play Books ] MATLAB程式設計與工程應用習題解答自學手冊 (2022).pdf
 
[電子書-Google Play Books] MATLAB程式設計與工程應用 2022 目錄表.pdf
[電子書-Google Play Books] MATLAB程式設計與工程應用 2022 目錄表.pdf[電子書-Google Play Books] MATLAB程式設計與工程應用 2022 目錄表.pdf
[電子書-Google Play Books] MATLAB程式設計與工程應用 2022 目錄表.pdf
 
[電子書-Google Play Books] MATLAB在化工上之應用 (2022修訂版) 目錄表.pdf
[電子書-Google Play Books] MATLAB在化工上之應用 (2022修訂版) 目錄表.pdf[電子書-Google Play Books] MATLAB在化工上之應用 (2022修訂版) 目錄表.pdf
[電子書-Google Play Books] MATLAB在化工上之應用 (2022修訂版) 目錄表.pdf
 
[E-book at Google Play Books] MATLAB Applications in Chemical Engineering (20...
[E-book at Google Play Books] MATLAB Applications in Chemical Engineering (20...[E-book at Google Play Books] MATLAB Applications in Chemical Engineering (20...
[E-book at Google Play Books] MATLAB Applications in Chemical Engineering (20...
 
Ch 01 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
Ch 01 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片Ch 01 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
Ch 01 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
 
大學經營與治校理念_陳奇中教授金大演講投影片
大學經營與治校理念_陳奇中教授金大演講投影片大學經營與治校理念_陳奇中教授金大演講投影片
大學經營與治校理念_陳奇中教授金大演講投影片
 
化工概論: 製程分析模擬最適化與控制_陳奇中教授演講投影片
化工概論: 製程分析模擬最適化與控制_陳奇中教授演講投影片化工概論: 製程分析模擬最適化與控制_陳奇中教授演講投影片
化工概論: 製程分析模擬最適化與控制_陳奇中教授演講投影片
 
Reliability-Based Design Optimization Using a Cell Evolution Method ~陳奇中教授演講投影片
Reliability-Based Design Optimization Using a Cell Evolution Method ~陳奇中教授演講投影片Reliability-Based Design Optimization Using a Cell Evolution Method ~陳奇中教授演講投影片
Reliability-Based Design Optimization Using a Cell Evolution Method ~陳奇中教授演講投影片
 
創意研發專論:創意規則 ~陳奇中教授演講投影片
創意研發專論:創意規則 ~陳奇中教授演講投影片創意研發專論:創意規則 ~陳奇中教授演講投影片
創意研發專論:創意規則 ~陳奇中教授演講投影片
 
Data Driven Process Optimization Using Real-Coded Genetic Algorithms ~陳奇中教授演講投影片
Data Driven Process Optimization Using Real-Coded Genetic Algorithms ~陳奇中教授演講投影片Data Driven Process Optimization Using Real-Coded Genetic Algorithms ~陳奇中教授演講投影片
Data Driven Process Optimization Using Real-Coded Genetic Algorithms ~陳奇中教授演講投影片
 
Designs of Single Neuron Control Systems: Survey ~陳奇中教授演講投影片
Designs of Single Neuron Control Systems: Survey ~陳奇中教授演講投影片Designs of Single Neuron Control Systems: Survey ~陳奇中教授演講投影片
Designs of Single Neuron Control Systems: Survey ~陳奇中教授演講投影片
 
Intelligent Process Control Using Neural Fuzzy Techniques ~陳奇中教授演講投影片
Intelligent Process Control Using Neural Fuzzy Techniques ~陳奇中教授演講投影片Intelligent Process Control Using Neural Fuzzy Techniques ~陳奇中教授演講投影片
Intelligent Process Control Using Neural Fuzzy Techniques ~陳奇中教授演講投影片
 
MATLAB教學經驗分享~陳奇中教授演講投影片
MATLAB教學經驗分享~陳奇中教授演講投影片MATLAB教學經驗分享~陳奇中教授演講投影片
MATLAB教學經驗分享~陳奇中教授演講投影片
 
認識化工~陳奇中教授演講投影片
認識化工~陳奇中教授演講投影片認識化工~陳奇中教授演講投影片
認識化工~陳奇中教授演講投影片
 
IEET工程教育認證經驗分享~陳奇中教授演講投影片
IEET工程教育認證經驗分享~陳奇中教授演講投影片IEET工程教育認證經驗分享~陳奇中教授演講投影片
IEET工程教育認證經驗分享~陳奇中教授演講投影片
 
當mit遇見MIT_波士頓見聞分享~陳奇中教授演講投影片
當mit遇見MIT_波士頓見聞分享~陳奇中教授演講投影片當mit遇見MIT_波士頓見聞分享~陳奇中教授演講投影片
當mit遇見MIT_波士頓見聞分享~陳奇中教授演講投影片
 
化工與我_學思紀行~陳奇中教授演講投影片
化工與我_學思紀行~陳奇中教授演講投影片化工與我_學思紀行~陳奇中教授演講投影片
化工與我_學思紀行~陳奇中教授演講投影片
 
程序控制的最後一堂課_ 美好的人生就從今天起 ~陳奇中教授演講投影片
程序控制的最後一堂課_ 美好的人生就從今天起 ~陳奇中教授演講投影片程序控制的最後一堂課_ 美好的人生就從今天起 ~陳奇中教授演講投影片
程序控制的最後一堂課_ 美好的人生就從今天起 ~陳奇中教授演講投影片
 

Dernier

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Dernier (20)

Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 

Ch 06 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片

  • 2. 06Process Optimization  to introduce the optimization commands  describe how to use them to solve diversified optimization problems that arose from the field of chemical engineering. introduce a population-based real-coded genetic algorithm (RCGA) 2
  • 3. 06Process Optimization 6.1 The optimization problem and the relevant MATLAB commands  6.1.1 Optimization problems of a single decision variable [x, fval]= fminbnd('fun', a, b, options) 3 Output argument Description x The obtained optimal solution in the feasible range [a b] fval The objective function value corresponding to the obtained optimal point x
  • 4. 06Process Optimization 4 Input argument Description fun The name of the function file provided by the user, and the format of the function is as follows: function f=fun(x) f= ... % objective function Besides, if the objective function is not complicated it can be directly given by the inline command, see Example 6-1-1 for detailed usage. a Lower limit of the decision variable b Upper limit of the decision variable options Solution optional parameters provided by the users, such as the maximal iteration number, the accuracy level and the gradient information, and so on. Refer to the command ‘optimset’ for its usage.
  • 5. 06Process Optimization Example 6-1-1 Solve the following optimization problem 5 Ans: >> f=inline('x.^3+x.^2-2*x-5'); % use inline to provide the objective function >> x=fminbnd(f, 0, 2) x= 0.5486 >> y=f(x) y= -5.6311
  • 6. 06Process Optimization 6.1.2 Multivariate optimization problems without constraints [x, fval]= fminunc('fun', x0, options) 6
  • 7. 06Process Optimization Example 6-1-2 Solve the following unconstrained optimization problem of two variables 7 Step 1: Provide the objective function file Ans:
  • 8. 06Process Optimization ──────────────── ex6_1_2f.m ──────────────── function f=fun(x) xl=x(1); x2=x(2); f=3*xl^2+2*xl*x2+5*x2^2; % objective function ───────────────────────────────────── 8 Ans: Step 2: Provide the objective function file >> x0= [1 1]; % initial guess value >> [x, fval]=fminunc('ex6_1_2f', x0) x= 1.0e-006 * -0.2047 0.2144 fval = 2.6778e-013
  • 9. 06Process Optimization ──────────────── ex6_1_2f2.m ─────────────── function [f, G]=fun(x) x1=x(1); x2=x(2); f=3*x1^2+2*x1*x2+5*x2^2; % objective function if nargout > 1 % the number of the output arguments is more than 1 G=[6*x1+2*x2 % partial differentiation with respect to x1 2*x1+10*x2]; % partial differentiation with respect to x2 end ───────────────────────────────────── 9 Ans:
  • 10. 06Process Optimization 10 Ans: >> options=optimset('GradObj', 'on'); % declare a gradient has been provided >> x0=[1 1]; % initial guess >> [x, fval]=fminunc('ex6_1_2f2', x0, options) x = 1.0e-015 * -0.2220 0.1110 fval = 1.6024e-031 [x, fval]=fminsearch('fun', x0, options)
  • 11. 06Process Optimization 6.1.3 Linear programming problems 11 s.t. [x, fval]=linprog(f, A, b, Aeq, beq, xL, xU, x0, options)
  • 12. 06Process Optimization Example 6-1-3 Solve the following linear programming problem 12 s.t.
  • 14. 06Process Optimization 14 Ans: >> f=[-5 -4 -3]'; >> A=[1 -1 2; 3 2 1; 2 3 0]; >> b=[30 40 20]'; >> Aeq=[ ]; >> beq=[ ]; >> xL=[0 0 0]'; >> xU=[ ]; >> [x, fval]=linprog(f, A, b, Aeq, beq, xL, xU) x= 0.0000 6.6667 18.3333 fval = -81.6667
  • 15. 06Process Optimization 6.1.4 Quadratic programming problem [x, fval] =quadprog(H, f, A, b, Aeq, beq, xL, xU, x0, options) 15 s.t.
  • 17. 06Process Optimization 17 Ans: where A=[1 -1 ; -1 2; 2 1], b=[l 2 3]', Aeq=[ ] and beq=[ ].
  • 18. 06Process Optimization 18 Ans: >> H=[1 -1 ; -1 2]; >> f=[-6 -2]'; >> A=[1 -1; -1 2; 2 1]; % inequality coefficient matrix >> b=[1 2 3]'; % inequality vector >> xL=[0 0]'; % lower limit of the variable >> [x, fval]=quadprog(H, f, A, b, [ ], [ ], xL, [ ]) x= 1.3077 0.3846 fval = -8.1154
  • 19. 06Process Optimization NOTES: The determination of the H matrix of the quadratic objective function (6.1-11) can be easily accomplished by using the Symbolic Math operations as follows. 19 Ans: >> syms x1 x2 % declare x1 and x2 as symbolic variables >> f=1/2*x1^2+x2^2-x1*x2; % define the quadratic function >> H=jacobian(jacobian(f)) % calculate the H matrix H = [ 1, 1] [ 1, 2]
  • 20. 06Process Optimization 6.1.5 The constrained nonlinear optimization problems [x, fval]= fmincon('fun', x0, A, b, Aeq, beq, xL, xU, 'nonlcon', options) 20 s.t.
  • 21. 06Process Optimization • the objective function, 21 function f=fun(x) f= ... % the objective function • The nonlinear constraints, c(x) and ceq(x), function [c, ceq]=nonlcon(x) c=... % the nonlinear inequality constraints ceq=... % the nonlinear equality constraints • the gradient information options=optimset('Gradconstr', 'on')
  • 22. 06Process Optimization 22 function [c, ceq, Gc, Gceq]=nonlcon(x) c=... % nonlinear inequality constraints ceq=... % nonlinear equality constraints if nargout > 2 % since gradients are provided Gc=... % the gradients of the inequality constraints (in vector form) Gceq=... % the gradient of the equality constraints (in vector form) end
  • 24. 06Process Optimization ─────────────── ex6_1_5.m ─────────────── function ex6_1_5 % % Example 6-1-5 Solve an optimization problem with fmincon % clear clc % % initial guess values % x0=[10 10 10]'; % % coefficients for the inequality constraints % A=[-1 -2 -2; 1 2 2]; b=[0 72]'; % % solving the optimization problem with fmincon 24 Ans:
  • 25. 06Process Optimization ─────────────── ex6_1_5.m ─────────────── % [x, fval]=fmincon(@objfun, x0, A, b, [ ], [ ], [ ], [ ], @nonlcon); x1=x(1); x2=x(2); x3=x(3); fprintf('n The optimal solution is x1=%.3f, x2=%.3f, x3=%.3f,… ,n and the minimum objective function is f=%.3fn', x1, x2, x3, fval) % % objective function % function f=objfun(x) x1=x(1); x2=x(2); x3=x(3); f=-x1*x2^2*x3; % % nonlinear constraints 25 Ans:
  • 26. 06Process Optimization ─────────────── ex6_1_5.m ─────────────── % function [c, ceq]=nonlcon(x) x1=x(1); x2=x(2); x3=x(3); c=x1*x3-0.5*x2^2-380; ceq=x2*x3-144; ───────────────────────────────────── 26 Ans:
  • 27. 06Process Optimization Execution results: >> ex6_1_5 The optimal solution is x1=20.000, x2=18.000, x3=8.000, and the minimum objective function is f=-51840.000 27
  • 28. 06Process Optimization 6.1.6 The multi-objective goal attainment problem [x, fval, r]=fgoalattain('fun', x0, goal, w, A, b, Aeq, beq, xL, xU, 'nonlcon', options) 28 s.t.
  • 29. 06Process Optimization Example 6-1-6 Design of a pole placement controller 29
  • 30. 06Process Optimization feedback control law u=Ky the closed-loop system To avoid aggressive control inputs, the absolute value of each element in the gain matrix K is required to be less than 4. Determine the controller’s gain matrix K if the desired closed- loop poles, i.e., the eigenvalues of the matrix A+BKC, are located at 5, 3, and 1. 30
  • 31. 06Process Optimization Problem formulation and MATLAB program design: goal = [-5, -3, -1] F=sort(eig(A+B*K*C)) w=abs(goal) and 31
  • 32. 06Process Optimization ──────────────── ex6_1_6 ─────────────── function ex6_1_6 % % Example 6-1-6 Design of a pole placement controller % clear clc % global A B C % declared as the global variables % % system matrices % A=[-0.5 0 0 ; 0 -2 10 ; 0 1 -2]; B=[1 0 ; -2 2 ; 0 1 ]; C=[1 0 0 ; 0 0 1 ]; % % initial guess values of the controller parameter % K0=[-1 -1 ; -1 -1 ]; % 32
  • 33. 06Process Optimization ──────────────── ex6_1_6 ─────────────── % the desired poles and the weighting vector % goal=[-5 -3 -1]; % vector of the desired poles w=abs(goal); % weighting vector % % the lower and upper bounds of the decision parameters % xL=-4*ones(size(K0)); % lower limit of the controller parameters xU=4*ones(size(K0)); % upper limit of the controller parameters % % solving the multi-objective goal attainment problem % % options=optimset('GoalsExactAchieve',3); % [K,fval,r]=fgoalattain(@eigfun,K0,goal,w,[ ],[ ],[ ],[ ],xL,xU,[ ],options) [K,fval,r]=fgoalattain(@eigfun,K0,goal,w,[ ],[ ],[ ],[ ],xL,xU) % % multi-objective function vector % 33
  • 34. 06Process Optimization ──────────────── ex6_1_6 ─────────────── function f=eigfun(K) global A B C f=sort(eig(A+B*K*C)); ───────────────────────────────────────────────── 34
  • 35. 06Process Optimization Execution results: >> ex6_1_6 35 K= -4.0000 -0.2564 -4.0000 -4.0000 fval = -6.9313 -4.1588 -1.4099 r= -0.3863
  • 36. 06Process Optimization Execution results: >> ex6_1_6 replace the original command of fgoalattain with the following two lines: 36 options=optimset (‘GoalsExactAchieve', 3); [K, fval, r]=fgoalattain(@eigfun, K0, goal, W, [ ], [ ], [ ], [ ], xL, xU, [ ], options)
  • 37. 06Process Optimization Execution results: >> ex6_1_6 37 K = -1.5953 1.2040 -0.4201 -2.9047 fval = -5.0000 -3.0000 -1.0000 r = 4.1222e-021
  • 38. 06Process Optimization 6.1.7 Semi-infinitely constrained optimization problem s.t. c(x) = 0 c eq (x) = 0 Ax = b Aeq x = beq xL ≤ x ≤ xU k1 (x, w1) ≤ 0 k2 (x, w2) ≤ 0 ⁞ kn (x, wn) ≤ 0 38
  • 39. 06Process Optimization 39 [x, fval]=fseminf('fun' , x0, n, 'seminfcon' , A, b, Aeq, beq, xL, xU, options) function f = fun(x) f = ... % objective function options=optimset(‘GradObj , 'on ') function [f, G]=fun(x) f= ... % the objective function if nargout >1 % due to the gradient information is provided G =... % the gradient formula end
  • 40. 06Process Optimization 40 function [c, ceq, k1, k2, ... , kn, S]=seminfcon(x, S) % % given S matrix % if isnan(S(l, l)) S =... % S is a matrix with n rows and 2 columns end % % mesh points of wi based on S matrix % w1=… ; % w2= … ; % …
  • 41. 06Process Optimization 41 wn= … ; % % % calculate the semi-infinite inequalities % k1=…% k2=…% … kn=…% % % other nonlinear constraints % c = … % inequality constraints ceq= …% equality constraints
  • 42. 06Process Optimization Example 6-1-7 Solve the following semi-infinite optimization problem (MATLAB User’s Guide, 1997) 42 s.t. where the values of w1 and w2 both lie in the range of 1 and 100.
  • 43. 06Process Optimization Example 6-1-7 Step 1: Prepare the objective function file: function f=fun6_1_7(x) f=sum((x-0.5).^2); Step 2: Prepare a function file that contains the semi-infinite constraints: function [c, ceq, k1 , k2, S]=seminfcon6_1_7(x, S) % % S matrix: distance between meshes % if isnan(S(l, l)) 43 Ans:
  • 44. 06Process Optimization S=[0.1 0 0.1 0]; % NOTE: the second column is a zero vector end % % meshes for wi % w1=1:S(1,1):100; w2=1:S(2,1):100; % % semi-infinite constraints % k1=sin(w1*x(1)).*cos(w1*x(2))-1/1000*(wl-50).^2- sin(w1*x(3))-x(3)-1; 44 Ans:
  • 45. 06Process Optimization k2=sin(w2*x(2)).*cos(w2*x(l) )-1/1000*(w2-50).^2- sin(w2*x(3))-x(3)-1; % % other nonlinear constraints % c= [ ]; % no other nonlinear constraints ceq=[ ]; Step 3:Combine the subroutines 45 Ans:
  • 46. 06Process Optimization ──────────────── ex6_7.m ─────────────── function ex6_1_7 % % Example 6-1-7 Semi-infinite optimization % clear clc % x0=[0.5 0.2 0.3]'; % initial guess values % % solve the semi-infinite optimization problem % [x, fval]=fseminf(@fun6_1_7, x0, 2, @seminfcon6_1_7) % % objective function % function f=fun6_1_7(x) f=sum((x-0.5).^2); % % constraints 46
  • 47. 06Process Optimization ──────────────── ex6_7.m ─────────────── % function [c, ceq, k1, k2, S]=seminfcon6_1_7(x, S) % % S matrix: distance between meshes % if isnan(S(l, l)) S=[0.1 0 0.1 0]; % NOTE: the second column is a zero vector end % % meshes for wi % w1=1:S(1,1):100; w2=1:S(2,1):100; % % semi-infinite constraints % k1=sin(w1*x(1)).*cos(w1*x(2))-1/1000*(wl-50).^2-sin(w1*x(3))-x(3)-1; k2=sin(w2*x(2)).*cos(w2*x(l))-1/1000*(w2-50).^2-sin(w2*x(3))-x(3)-1; 47
  • 48. 06Process Optimization ──────────────── ex6_7.m ─────────────── % % other nonlinear constraints % c= [ ]; % no other nonlinear constraints ceq=[ ]; ───────────────────────────────────────────────── 48
  • 49. 06Process Optimization Step 4: Execute the program to get the optimal solution >> ex6_1_7 x = 0.6581 0.2972 0.3962 fval = 0.0769 49 Ans:
  • 50. 06Process Optimization Example 6-1-8 Solve the following two-dimensional semi-infinite optimization problem (MATLAB User’s Guide, 1997) 50 where w =[w1 w2 ] with 1 ≤ w1 ≤ 100 and 1 ≤ w2 ≤ 100 . s.t.
  • 51. 06Process Optimization Example 6-1-8 ─────────────── ex6_1_8.m ─────────────── function ex6_1_8 % % Example 6-1-8 Two-dimensional semi-infinite optimization % clear; close all; clc % x0=[0.5 0.5 0.5]'; % initial guess values % % solve the 2D semi-infinite optimization problem % [x, f]=fseminf(@fun6_1_8, x0, 1, @seminfcon6_1_8); % [c, ceq, k]=seminfcon6_1_8(x, [0.2 0.2]); kmax=max(max(k)); % the maximum value in the constraint 51 Ans:
  • 52. 06Process Optimization ─────────────── ex6_1_8.m ─────────────── function ex6_1_8 % % Example 6-1-8 Two-dimensional semi-infinite optimization % clear; close all; clc % x0=[0.5 0.5 0.5]'; % initial guess values % % solve the 2D semi-infinite optimization problem % [x, f]=fseminf(@fun6_1_8, x0, 1, @seminfcon6_1_8); % [c, ceq, k]=seminfcon6_1_8(x, [0.2 0.2]); kmax=max(max(k)); % the maximum value in the constraint % % Results printing % 52 Ans:
  • 53. 06Process Optimization ─────────────── ex6_1_8.m ─────────────── fprintf('n if x1=%.3f, x2=%.3f, x3=%.3f, minimal value is… f=%.3e',x(1),x(2),x(3),f) fprintf('n the maximal value in the constraint is %.3fn', kmax) % % objective function % function f=fun6_1_8(x) f=sum((x-0.5).^2); % % constraints % function [c, ceq, k, S]=seminfcon6_1_8(x, S) % % S matrix: distance between meshes % if isnan(S(1, 1)) S=[0.2 0.2]; 53 Ans:
  • 54. 06Process Optimization ─────────────── ex6_1_8.m ─────────────── end % % meshes % w1=1:S(1,1):100; w2=1:S(1,2):100; [W1, W2]=meshgrid(w1, w2); % meshgrid for interlacing meshes in 2D % % semi-infinite constraints % k=sin(W1*x(1)).*cos(W1*x(2))-1/1000*(W1-50).^2-sin(W1*x(3))+... sin(W2*x(2)).*cos(W1*x(1))-1/1000*(W2-50).^2-sin(W2*x(3))-2*x(3)-1.5; % c=[ ]; % no other nonlinear constraints ceq=[ ]; % % plotting during execution % 54 Ans:
  • 55. 06Process Optimization ─────────────── ex6_1_8.m ─────────────── m=surf(W1, W2, k, 'edgecolor', 'non', 'facecolor', 'interp'); camlight headlight xlabel('w1') ylabel('w2') zlabel('k') title('semi-infinite constraint') ───────────────────────────────────────────────── 55 Ans:
  • 56. 06Process Optimization Execution results: >> ex6_1_8 if x1=0.503, x2=0.506, x3=0.492, minimal value is f=9.803e005 the maximal value in the constraint is -0.147 56
  • 57. 06Process Optimization 6.1.8 The minimax problem [x, f, maxf] =fminimax('fun', x0, A, b, Aeq, beq, xL, xU, 'nonlcon', options) 57 s.t.
  • 58. 06Process Optimization • objective functions 58 function f=fun(x) f(l) =… % the first objective function f(2) =… % the second objective function ⁞ f(n) =… % the n-th objective function options = optimset('GradObj', 'on', 'GradConstr', 'on') function [f, G] = fun(x) f=[ ... % the first objective function … % the second objective function ⁞ … % the n-th objective function ]
  • 59. 06Process Optimization 59 if nargout > 1 G=[ … % ∂f1 / ∂x … % ∂f2 / ∂x ⁞ … % ∂fn / ∂x ] end function [c, ceq, Gc, Gceq] =nonlcon(x) c =... % the nonlinear inequality constraints ceq =... % the nonlinear equality constraints if nargout > 2 Gc=… % gradients for inequality constraints Gceq=… % gradients for equality constraints end
  • 61. 06Process Optimization Example 6-1-9 ─────────────── ex6_1_9.m ─────────────── function ex6_1_9 % % Example 6-1-9 Minimax optimization % clear clc % % initial guess values % x0=[2 2]; % % solving the minimax optimization problem % [x, fval, fmax]=fminimax(@objfun, x0) 61 Ans:
  • 62. 06Process Optimization ─────────────── ex6_1_9.m ─────────────── % % objective functions % function f=objfun(x) x1=x(1); x2=x(2); f=[x1^2+x2^4 (2-x1)^2+(2-x2)^2 2*exp(x2-x1)]; ───────────────────────────────────────────────── 62 Ans:
  • 63. 06Process Optimization Execution results: >> ex6_1_9 x = 1.1390 0.8996 fval = 1.9522 1.9522 1.5741 fmax = 1.9522 63
  • 64. 06Process Optimization 6.1.9 Binary integer programming problem [x, fval]=bintprog(f, A, b, Aeq, beq, x0, options) 64 s.t.
  • 65. 06Process Optimization Example 6-1-10 s.t. 6x1 + 3x2 + 5x3 + 2x4 ≤ 9 x3 + x4 ≤ 1 –x2 + x4 ≤ 0 x1 + x2 + x3 + x4 = 2 xi = 0 or 1, i = 1, 2, 3, 4 65
  • 67. 06Process Optimization and beq = 2 67 Ans: >> f=[-9 -5 -6 -4]'; >> A=[6 3 5 2 0 0 1 1 -1 0 1 0 0 -1 0 1]; >> b=[9 1 0 0]'; >> Aeq=[1 1 1 1]; >> beq=2; >> [x, fval]=bintprog(f,A, b,Aeq, beq) Optimization terminated.
  • 69. 06Process Optimization 6.1.10 A real-coded genetic algorithm for optimization  6.1.10.1 Fundamental principles of the real-coded genetic algorithm  Genetic algorithm (GA) is a kind of population-based stochastic approach that mimics the natural selection and survival of the fittest in the biological world.  Let θ = [θ1, θ2, …, θn ] be a set of possible solutions  The feasible solution Ωθ is expressed as follows: 69
  • 70. 06Process Optimization 6.1.10.1 Fundamental principles of the real- coded genetic algorithm I. Reproduction • the reproduction is an evolutionary process to determine which chromosome should be eliminated or reproduced in the population. • Using the scheme, pr × N chromosomes having worst objective function values will be discarded and at the same time other rp × N chromosomes that have better objective functions are reproduced. 70
  • 71. 06Process Optimization II. Crossover • Crossover operation, which acts as a scheme to blend the parents’ information for generating the offspring chromosomes, is well recognized as the most important and effective searching mechanism in RCGAs. • if obj (θ1) < obj (θ2) θ1 ← θ1 + r (θ1–θ2) θ2 ← θ2 + r (θ1–θ2) else θ1 ← θ1 + r (θ2–θ1) θ2 ← θ2 + r (θ2–θ1) end 71
  • 72. 06Process Optimization III. Mutation • Mutation serves as a process to change the gene of a chromosome (solution) randomly in order to increase the population diversity and thus prevent the population from premature convergence to a suboptimal solution. θ ← θ + s × Φ • The operational procedure of the RCGA Step 1:Set the number of chromosomes in the population N, and the relevant probability values pr, pc, and pm. Meanwhile, the maximum number of generations G is also assigned. Step 2:Randomly produce N chromosomes from the feasible domain Ωθ. Step 3:Evaluate the corresponding objective function value for each chromosome in the population. 72
  • 73. 06Process Optimization III. Mutation Step 4:The genetic evolution terminates once the computation process has reached the specified maximum number of generations or the objective function has attained an optimal value. Step 5:Implement the operations of reproduction, crossover, and mutation in the genetic evolution. Note that if the chromosomes of the offspring produced exceed the feasible range Ωθ, the chromosomes before the evolution are retained. Step 6:Go back to Step 3. 73
  • 74. 06Process Optimization 6.1.10.2 Application of the real-coded genetic algorithm to solve optimization problems s.t. c(x) ≤ 0 c eq (x) = 0 Ax ≤ b Aeq x = beq xL ≤ x ≤ xU 74
  • 75. 06Process Optimization 75 [x , fval]=rcga('fun', A, b, Aeq, beq, xL, xU, 'nonlcon', param) Param Description param(1) Number of chromosomes in the population, N param(2) Reproduction probability, pr param(3) Crossover probability threshold, pc param(4) Mutation probability, pm param(5) Maximum number of generations, G
  • 76. 06Process Optimization Example 6-1-11 s.t. 0 ≤ 85.334407 + 0.0056858x2 x5+ 0.00026x1 x4 – 0.0022053x3 x5 ≤ 92 90 ≤ 80.51249 + 0.0071317x2 x5+ 0.0029955x1 x2+ 0.0021813x2 3 ≤ 110 20 ≤ 9.300961+ 0.0047026x3 x5+ 0.0012547x1 x3+ 0.0019085x3 x4 ≤ 25 78 ≤ x1 ≤ 102 33 ≤ x2 ≤ 45 27 ≤ x3, x4, x5 ≤ 45 76
  • 77. 06Process Optimization MATLAB program design: N= 200, Pr = 0.2, Pc = 0.3, Pm = 0.7 and G = 500. ─────────────── ex6_1_11 ─────────────── function ex6_1_11 % % Example 6-1-11 Optimization with the real-coded genetic algorithm % clear clc % % the RCGA parameters % N=200; % Number of populations Pr=0.2; % Reproduction probability Pc=0.3; % Crossover probability threshold Pm=0.7; % Mutation probability G=500; % Maximum generation numbers 77
  • 78. 06Process Optimization MATLAB program design: ─────────────── ex6_1_11 ─────────────── % the linear constraints % A=[ ]; b=[ ]; Aeq=[ ]; beq=[ ]; % % the upper and lower bounds of the decision variables % xL=[78 33 27 27 27]; % lower bound xU=[102 45 45 45 45]; % upper bound % % rearrange the RCGA parameters into param % param=[N Pr Pc Pm G]; % RCGA parameter vector % % solving with the real-coded genetic algorithm 78
  • 79. 06Process Optimization MATLAB program design: ─────────────── ex6_1_11 ─────────────── % [x, f]=rcga(@fun, A, b, Aeq, beq, xL, xU, @nonlcon, param); [c, ceq]=nonlcon(x) % check the satisfaction of the constraints % % results printing % fprintf('n The optimal solution is x_%i=%.3fn',[1:length(x); x]) fprintf('n The minimum objective function = %.3fn', f) % % Objective function % function f=fun(x) x1=x(1); x2=x(2); x3=x(3); x4=x(4); x5=x(5); f=5.3578547*x3^2+0.8356891*x1*x5+37.293239*x1-40792.141; % % nonlinear constraints % 79
  • 80. 06Process Optimization MATLAB program design: ─────────────── ex6_1_11 ─────────────── function [c, ceq]=nonlcon(x) x1=x(1); x2=x(2); x3=x(3); x4=x(4); x5=x(5); f1=85.334407+0.0056858*x2*x5+0.00026*x1*x4-0.0022053*x3*x5; f2=80.51249+0.0071317*x2*x5+0.0029955*x1*x2+0.0021813*x3^2; f3=9.300961+0.0047026*x3*x5+0.0012547*x1*x3+0.0019085*x3*x4; c=[-f1; f1-92; 90-f2; f2-110; 20-f3; f3-25]; ceq=[ ]; ───────────────────────────────────────────────── 80
  • 81. 06Process Optimization Execution results: >> ex1_1_11 81 c = -92.0000 0 -10.4048 -9.5952 0 -5.0000 ceq = [ ] The optimal solution is x_1=78.000 The optimal solution is x_2=33.000 The optimal solution is x_3=27.071 The optimal solution is x_4=45.000 The optimal solution is x_5=44.969 The minimum objective function = -31025.560 (Gen and Cheng, 1997), which is ƒ* = −30665.5 at x* = [78 33 29.995 45 36.776].
  • 82. 06Process Optimization Example 6-1-12 Resolve the problem in Example 6-1-5 with the real-coded genetic algorithm 82 MATLAB program design: 0 ≤ xi ≤ 25, i = 1, 2, 3.
  • 83. 06Process Optimization MATLAB program design: ─────────────── ex6_1_12.m ─────────────── function ex6_1_12 % % Example 6-1-12 Optimization with RCGA % clear clc % % the RCGA parameters % N=500; % Population number Pr=0.2; % Reproduction probability Pc=0.3; % Crossover probability threshold Pm=0.7; % Mutation probability G=1000; % Maximum generation number % % linear equality and inequality restraints % 83
  • 84. 06Process Optimization MATLAB program design: ─────────────── ex6_1_12.m ─────────────── A=[-1 -2 -2; 1 2 2]; b=[0 72]'; Aeq=[ ]; beq=[ ]; % % the upper and lower bounds % xL=[0 0 0]; % lower bound xU=[25 25 25]; % upper bound % % rearrange the RCGA parameters into param % param=[N Pr Pc Pm G]; % the RCGA parameters % % Solving with RCGA % [x, f]=rcga(@fun, A, b, Aeq, beq, xL, xU, @nonlcon, param); 84
  • 85. 06Process Optimization MATLAB program design: ─────────────── ex6_1_12.m ─────────────── A*x'-b; f=fun(x); [c, ceq]=nonlcon(x); % % result printing % fprintf('n The optimal solution is x_%i=%.3fn', [1:length(x); x]) fprintf('n The minimum objective function = %.2fn', f) % % objective function % function f=fun(x) x1=x(1); x2=x(2); x3=x(3); f=-x1*x2^2*x3; % 85
  • 86. 06Process Optimization MATLAB program design: ─────────────── ex6_1_12.m ─────────────── % nonlinear constraints % function [c, ceq]=nonlcon(x) x1=x(1); x2=x(2); x3=x(3); c=x1*x3-0.5*x2^2-380; ceq=x2*x3-144; ───────────────────────────────────────────────── 86
  • 87. 06Process Optimization Execution results: >> ex6_1_12 87 The optimal solution is x_1=20.000 The optimal solution is x_2=18.000 The optimal solution is x_3=8.000 The minimum objective function = -51840.00
  • 88. 06Process Optimization 6.2 Chemical engineering examples Example 6-2-1 Maximizing the profit of a production system 88 A B C E F G Process 1 Process 2 Process 3 Process 1: A+B→E Process 2: A+B→F Process 3: 3A+2B+C→G
  • 89. 06Process Optimization 89 Raw material Daily maximum supply (lb/day) Unit price ($/lb) A 45,000 0.015 B 35,000 0.020 C 25,000 0.025
  • 90. 06Process Optimization 90 Process Product The raw materials required per pound of product (lb) Operation costs Price of product 1 E 2 3 A, 1 3 B 0.015$/lb E 0.040$/lb E 2 F 2 3 A, 1 3 B 0.005$/lb F 0.033$/lb F 3 G 1 2 A, 1 6 B, 1 3 C 0.010$/lb G 0.038$/lb G Determine the operating condition such that the daily profit is maximized. And how much is the maximum profit?
  • 91. 06Process Optimization Problem formulation and analysis: Let x1~x6 denote the daily consumption of the raw materials A, B, and C and the production quantities of the products E, F, and G, respectively. 91 Cost of raw materials: C1 = 0.015x1+ 0.02x2 + 0.025x3 Operation cost: C2 = 0.015x4 + 0.005x5 + 0.01x6 daily total cost: C = C1 + C2 F = IC − C = 0.025x4 +0.028x5 + 0.028x6 − 0.015x1 − 0.02x2 − 0.025x3
  • 92. 06Process Optimization Problem formulation and analysis: x1 = 0.667x4 + 0.667x5 + 0.5x6 x2 = 0.333x4 + 0.333x5 + 0.167x6 x3 = 0.333x6 0 ≤ x1 ≤ 45,000 0 ≤ x2 ≤ 35,000 0 ≤ x3 ≤ 25,000 92
  • 94. 06Process Optimization MATLAB program design: ─────────────── ex6_2_1.m ─────────────── function ex6_2_1 % % Example 6-2-1 Maximal profit of a production system % clear clc % Relevant parameters in a linear programming problem % n=6; % Number of variables f=[ -0.015 -0.02 -0.025 0.025 0.028 0.028]'; Aeq=[1 0 0 -0.667 -0.667 -0.5 0 1 0 -0.333 -0.333 -0.167 0 0 1 0 0 -0.333]; beq=zeros(3,1); xL=zeros(l,n); xU=[45000 35000 25000 inf inf inf]; 94
  • 95. 06Process Optimization MATLAB program design: ─────────────── ex6_2_1.m ─────────────── A=[ ]; b=[ ]; % % Solve the linear programming problem with linprog % [x, fval]=linprog(-f, A, b, Aeq, beq, xL, xU); % Note that –f is used % % Results printing % for i=l: n fprintf('n The optimal solution x(%d) is %.3f', i, x(i)) end fprintf('n The maximum profits are =%.3f.n', -fval) % NOTE: -fval ───────────────────────────────────────────────── 95
  • 96. 06Process Optimization Execution results: >> ex6_2_1 The optimal solution is x(1)=45000.000 The optimal solution is x(2)=16263.175 The optimal solution is x(3)=25000.000 The optimal solution is x(4)=0.000 The optimal solution is x(5)=11188.100 The optimal solution is x(6)=75075.075 The maximum profit is f=790.105. 96
  • 97. 06Process Optimization Example 6-2-2 The optimal photoresist film thickness in a wafer production process According to practical operation experiences, one can summarize the factors that affect the quality of printed circuits in a wafer production process as follows (Edgar and Himmelblau, 1989): 1. Inadequately lower photoresist film thickness can inevitably increase the defect ratio. The correlation between the defect ratio and the film thickness is expressed by D0 =1.5 d −3 where D0 is the defect ratio and d is the film thickness (micrometers). 97
  • 98. 06Process Optimization 2. The percentage of perfect chips in the circuit layer can be estimated by 𝜂 = 1 1+𝛽𝐷0 𝑎 4 where a is the activated area of the chips and β is the percentage of severe defects. 3. The increment of the photoresist film thickness tends to reduce the wafer production capacity; the relationship is given as follows: V = 125 − 50d + 5d 2 98
  • 99. 06Process Optimization Note that the unit of V is wafers/h. Besides, the following process information and statistical data are known: each wafer contains 100 chips, each chip has an activated area of 0.25 and the percentage of severe defects is 30% (i.e., β = 0.3). Based on the above, determine the optimal photoresist film thickness that maximizes the production amount of perfect chips. NOTE: the admissible photoresist film thickness lies in the range of 0.5 ≤ d ≤ 2.5. 99
  • 100. 06Process Optimization Problem formulation and analysis: the hourly production number of perfect chips, 100 where β = 0.3, a = 0.25, and 0.5 ≤ d ≤ 2.5.
  • 101. 06Process Optimization 101 Ans: >> f=inline('- 100*(125-50*d+5*d^2)/(1+0.3*0.25*1.5*d^(-3))^4'); >> [d, fval]=fminbnd(f, 0.5, 2.5) d= 1.2441 fval = -5.6203e+003
  • 102. 06Process Optimization Example 6-2-3 Minimal energy of a chemical equilibrium system Find the mole fraction of each component such that the energy function is minimized subject to following equality constraints derived from material balances x1 + 2x2 + 2x3 + x6 + x10 = 2 102
  • 103. 06Process Optimization x4 + 2x5 + x6 + x7 = 1 x31 + x7 + x8 + 2x9 + x10 = 1 The values of the coefficient in Equation (6.2-15) are listed in the following table: Note that the system is operated under the total pressure of P = 760 mmHg. 103 i 1 2 3 4 5 wi 10.021 21.096 37.986 9.846 28.653 i 6 7 8 9 10 wi 18.918 28.032 14.640 30.594 26.111
  • 104. 06Process Optimization MATLAB program design: Because the mole fraction xi must satisfy 0 ≤ xi ≤ 1, these additional constraints should be added into the optimization problem. ─────────────── ex6_2_3.m ─────────────── function ex6_2_3 % % Example 6-2-3 Energy minimization of a chemical equilibrium system % clear clc % global w P % % System data: w values % w=[-10.021 -21.096 -37.986 -9.846 -28.653 -18.918 -28.032 -14.640… -30.594 - 26.111]; % 104
  • 105. 06Process Optimization MATLAB program design: ─────────────── ex6_2_3.m ─────────────── P=760; % Pressure (mmHg) % % Initial guess values % x0=0.5*ones(1, 10); % % Constraints % Aeq=[1 2 2 0 0 1 0 0 0 1 0 0 0 1 2 1 1 0 0 0 0 0 1 0 0 0 1 1 2 1]; beq=[2 1 1]'; xL=eps*ones(1,10); % Lower bounds of the decision variables xU=ones(1,10); % Upper bounds of the decision variables % % Solving the optimization problem with fmincon % 105
  • 106. 06Process Optimization MATLAB program design: ─────────────── ex6_2_3.m ─────────────── [x, fval]=fmincon(@fun, x0, [], [], Aeq, beq, xL, xU); % % Results printing % disp('The mole fraction of each component is') x disp('The minimal energy function value is') fval % % Objective function % function f=fun(x) global w P % f=sum(x.*(w+log(P)+log(x./sum(x)))); ───────────────────────────────────────────────── 106
  • 107. 06Process Optimization Execution results: >> ex6_2_3 The mole fraction of each component is x = Columns 1 through 6 0.0070 0.0678 0.9076 0.0004 0.4909 0.0005 Columns 7 through 10 0.0173 0.0029 0.0152 0.0418 The minimal energy function value is fval = -43.4740 107
  • 108. 06Process Optimization Execution results: >> ex6_2_3 NOTE: In the MATLAB program, the lower bound 0 is replaced by eps (2.2204  l016) to avoid the numerical problem arising from the calculation of natural logarithm for the objective function. 108
  • 109. 06Process Optimization Example 6-2-4 Maximal profit of an alkylation process Consider the alkylation process shown in the following figure (Edgar and Himmelblau, 1989). 109 Reactor Fractionator Hydrocarbon Olefin Isobutane Acid Recycle of isobutane, x2 Alkylate product Spent acids x3 x1 x5
  • 110. 06Process Optimization 110 Variables Physical significance Unit Lower bound Upper bound x1 Olefin feed Barrel/day 0 2,000 x2 Isobutane recycled Barrel/day 0 16,000 x3 Feed of fresh acid Thousands of pounds per day 0 120 x4 Alkylate yield Barrel/day 0 5,000 x5 Isobutane makeup Barrel/day 0 2,000 x6 Acid strength Weight percentage 85 93 x7 Motor octane number - 90 95 x8 External isobutene-to-olefin ratio - 3 12 x9 Acid dilution factor - 1.2 4 x10 F-4 performance number - 145 162
  • 111. 06Process Optimization The objective function, 111 Parameter Physical meaning Value Unit c1 Alkylate product value 0.063 $/barrel c2 Olefin feed cost 5.04 $/barrel c3 Isobutane recycle cost 0.035 $/barrel c4 Acid addition cost 10 $/thousand lbs c5 Isobutane makeup cost 3.36 $/barrel
  • 113. 06Process Optimization To include the process uncertainties in the formulation, 113
  • 114. 06Process Optimization where the values of 𝑑𝑖 − and 𝑑𝑖 + are listed in the following table: 114 𝑑4 − 𝑑4 + 𝑑7 − 𝑑7 + 𝑑9 − 𝑑9 + 𝑑10 − 𝑑10 + 95 100 100 95 95 100 100 95 95 100 100 95 95 100 100 95
  • 115. 06Process Optimization MATLAB program design: ─────────────── ex6_2_4.m ─────────────── function ex6_2_4 % % Example 6-2-4 Maximum profit in an alkylation process % clear clc % % Upper and lower bounds of the decision variables % xL=[0 0 0 0 0 85 90 3 1.2 145]'; xU=[2000 16000 120 5000 2000 93 95 12 4 162]'; % % Initial guess values % x0=[1745 12000 110 3048 1974 89.2 92.8 8 3.6 145]'; % % Linear constraints 115
  • 116. 06Process Optimization MATLAB program design: ─────────────── ex6_2_4.m ─────────────── % Aeq=[-1 0 0 1.22 -1 0 0 0 0 0]; % Eq. (6.2-20) beq=0; % A=[0 0 0 0 0 0 0 0 95/100 0.222 % Eq. (6.2-30) 0 0 0 0 0 0 0 0 -100/95 -0.222 % Eq. (6.2-31) 0 0 0 0 0 0 -3 0 0 95/100 % Eq. (6.2-32) 0 0 0 0 0 0 3 0 0 -100/95]; % Eq. (6.2-33) b=[35.82 -35.82 -133 133]'; % % Solving with fmincon % [x, f]=fmincon(@fun, x0, A, b, Aeq, beq, xL, xU, @nonlcon); % % Results printing % disp('The optimal solution is:') 116
  • 117. 06Process Optimization MATLAB program design: ─────────────── ex6_2_4.m ─────────────── fprintf('n The maximum profit is %.3fn.', -f) % % Objective function % function f=fun(x) x1=x(1);x2=x(2);x3=x(3);x4=x(4);x5=x(5); x6=x(6);x7=x(7);x8=x(8);x9=x(9);x10=x(10); f=0.063*x4*x7-5.04*x1-0.035*x2-10*x3-3.36*x5; f=-f; % % Nonlinear constraints % function [c, ceq]=nonlcon(x) x1=x(1);x2=x(2);x3=x(3);x4=x(4);x5=x(5); x6=x(6);x7=x(7);x8=x(8);x9=x(9);x10=x(10); c=[-x1*(1.12+0.13167*x8-0.00667*x8^2)+95/100*x4 % (6.2-26) 117
  • 118. 06Process Optimization MATLAB program design: ─────────────── ex6_2_4.m ─────────────── x1*(1.12+0.13167*x8-0.00667*x8^2)-100/95*x4 % Eq. (6.2-27) -(86.35+1.098*x8-0.038*x8^2+0.325*(x6-89))+95/100*x7 % (6.2-28) 86.35+1.098*x8-0.038*x8^2+0.325*(x6-89)-100/95*x7]; % Eq. (6.2-29) ceq=[x6*(x4*x9+1000*x3)-98000*x3 % Eq. (6.2-21) x8*x1-x2-x5]; % Eq. (6.2-23) ───────────────────────────────────────────────── 118
  • 119. 06Process Optimization Execution results: >> ex6_2_4 The optimal solution is: x = 1.0e+003 * 1.7506 8.4495 0.0241 3.0743 2.0000 0.0850 0.0950 0.0060 0.0012 0.1562 The maximum profit is 2319.484. 119
  • 120. 06Process Optimization Example 6-2-5 Maximum separation efficiency in a single-effect distillatory Consider a two-component single-effect distillation tower operated at one atmospheric pressure. The relationship between the liquid-phase mole fraction x and the vapor-phase mole fraction y of the light key component is shown in the following table (Leu, 1985): 120 x 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 y 0 0.191 0.339 0.480 0.618 0.730 0.812 0.864 0.913 0.959 1.0
  • 121. 06Process Optimization Let z and F denote, respectively, the mole fraction of the light key component in the feed and the feeding rate. Then, the separation efficiency of the single-effect distillation tower can be defined as where d = D/F is the ratio of the flow rate of distillate to the feeding rate. Based on the above-mentioned operating conditions, determine the values of d and x such that the separation efficiency is maximized under each of the feed condition of z ranging from 0.1 to 0.9 with an interval of 0.1. 121
  • 122. 06Process Optimization Problem formulation and analysis: 122 F, z D, y W, x Feed Single- effect distillation tower Vapor Liquid
  • 123. 06Process Optimization Problem formulation and analysis: F = D + W Fz = Dy + Wx Let w = W/F, d = w + 1 z = dy + wx y = f (x) 123
  • 124. 06Process Optimization MATLAB program design: ─────────────── ex6_2_5.m ─────────────── function ex6_2_5 % % Example 6-2-5 Maximum separation efficiency of a single-effect distillatory % clear; close all; clc % global z xe ye % % equilibrium data % xe=0:0.1:1; ye=[0 0.191 0.339 0.480 0.618 0.730 0.812 0.864 0.913 0.959 1.0]; % % initial guess values % p0=[0.5 0.5]; 124
  • 125. 06Process Optimization MATLAB program design: ─────────────── ex6_2_5.m ─────────────── function ex6_2_5 % % Example 6-2-5 Maximum separation efficiency of a single-effect distillatory % clear; close all; clc % global z xe ye % % equilibrium data % xe=0:0.1:1; ye=[0 0.191 0.339 0.480 0.618 0.730 0.812 0.864 0.913 0.959 1.0]; % % initial guess values % p0=[0.5 0.5]; 125
  • 126. 06Process Optimization MATLAB program design: ─────────────── ex6_2_5.m ─────────────── % % Upper and lower bounds of the decision variables % xL=[0 0]; xU=[1 1]; % % finding the optimal solution to each case of z values % for i=1:9 z=0.1*i; [p, f]=fmincon(@fun, p0, [], [], [], [], xL, xU, @nonlcon); dopt(i)=p(1); xopt(i)=p(2); eta(i)=-f; end % % Results printing 126
  • 127. 06Process Optimization MATLAB program design: ─────────────── ex6_2_5.m ─────────────── % for i=1:9 z=0.1*i; fprintf('n When z=%.1f, d=%.3f, x=%.3f, the optimal efficiency is =… %.3f.', z, dopt(i), xopt(i), eta(i)) end % % Plot a figure to show the variations of the optimal results % z=0.1:0.1:0.9; plot(z, eta, z, eta, '*') title('Variations of the optimial results') xlabel('Mole fraction of the light key component in the feeding stream, z') ylabel('Maximum separation efficiency') % % Objective function % 127
  • 128. 06Process Optimization MATLAB program design: ─────────────── ex6_2_5.m ─────────────── function f=fun(p) global z xe ye d=p(1); x=p(2); y=interp1(xe, ye, x, 'cubic'); f=-d*(y-z)/(z*(1-z)); % % Contraints % function [c, ceq]=nonlcon(p) global z xe ye d=p(1); x=p(2); w=1-d; y=interp1(xe, ye, x, 'cubic'); c=[ ]; ceq=z-d*y-w*x; ───────────────────────────────────────────────── 128
  • 129. 06Process Optimization Execution results: >> ex6_2_5 When z=0.1, d=0.426, x=0.071, the optimal efficiency is = 0.188. When z=0.2, d=0.454, x=0.147, the optimal efficiency is = 0.180. When z=0.3, d=0.457, x=0.231, the optimal efficiency is = 0.180. When z=0.4, d=0.456, x=0.315, the optimal efficiency is = 0.192. When z=0.5, d=0.472, x=0.397, the optimal efficiency is = 0.217. When z=0.6, d=0.499, x=0.485, the optimal efficiency is = 0.240. When z=0.7, d=0.541, x=0.582, the optimal efficiency is = 0.257. When z=0.8, d=0.584, x=0.706, the optimal efficiency is = 0.245. When z=0.9, d=0.595, x=0.848, the optimal efficiency is = 0.235. 129
  • 131. 06Process Optimization Example 6-2-6 Dynamic optimization of an ammonia synthesis process Haber-Bosch synthesis process N2 + 3H2 ⇆ 2NH3 131 s.t.
  • 135. 06Process Optimization 135 Parameter Physical meaning Value Unit Cpf Heat capacity of the feed 0.707 kcal/(kg∙K) Cpg Heat capacity of the reaction gas 0.719 kcal/(kg∙K) r Activity of the catalyst 0.95 - ΔH Heat of reaction 26,600 kcal /(kg-mol N2) 𝑁N2 0 The molar flow rate of N2 in the feed 701.2 kg-mol/(m2∙hr) PT Total pressure 268 psi R Ideal gas constant 1.987 kcal/(kg-mol∙K) S1 Heat transfer area per unit of reactor length 10 m S2 Cross-sectional area of the catalyst section 0.78 m2 U Overall heat conduction coefficient 500 kcal/(hr∙m2 ∙ K) W Overall mass transport rate 26,400 kg/hr Solve the dynamic optimization problem under the above-mentioned operating condition.
  • 137. 06Process Optimization Analysis of the question: where z = x/L is the defined dimensionless variable and the decision variable L (the reactor length) is in the range of 0 ≤ L ≤ 20. 137
  • 138. 06Process Optimization MATLAB program design: ─────────────── ex6_2_6.m ─────────────── function ex6_2_6 % % Example 6-2-6 Optimization of an ammonia synthesis process % clear; close all; clc % global PT U S1 S2 W Cpf Cpg dH R r NN20 L % % Model parameters % PT=286; % Total pressure (psi) Cpf=0.707; % Heat capacity of the feed, kcal/(kg.K) Cpg=0.719; % Heat capacity of the reaction gas, kcal/(kg.K) r=0.95; % Catalyst activity dH=-26600; % Heat of reaction, kcal/(kg-mol N2) R=1.987; % Ideal gas constant, kcal/(kg-mol.K) 138
  • 139. 06Process Optimization MATLAB program design: ─────────────── ex6_2_6.m ─────────────── S1=10; % Heat transfer area per unit of reactor length, m S2=0.78; % cross-sectional area of the catalyst section, m^2 U=500; % Overall heat conduction coefficient, kcal/(h.m^2.K) W=26400; % Overall mass transport rate, kg/h NN20=701.2; % Mole flow rate of ammonia in the feed, kg-mol/(m^2.h) % % Upper and lower bounds of the reactor length (the decision variable) % pL=1; pU=20; % % Solve the optimization problem with fminbnd % [L, fval]=fminbnd(@objfun, pL, pU); % % Results printing % 139
  • 140. 06Process Optimization MATLAB program design: ─────────────── ex6_2_6.m ─────────────── fprintf('n The optimal reactor length is %.3f m, and the maximum profit is… %.3e.', L, -fval) % % Results plotting % solinit=bvpinit(linspace(0,1,20), @init); sol=bvp4c(@ode, @bc, solinit); xint=linspace(0,1); yint=deval(sol, xint); plot(xint, yint(1,:), 'r', xint, yint(2,:), '-.b', xint, yint(3,:), '--c') legend('Tf', 'Tg', 'NN2') xlabel('The dimensionless reactor length (z)') ylabel('System states') axis([0 1 670 735]) % % objective function % 140
  • 141. 06Process Optimization MATLAB program design: ─────────────── ex6_2_6.m ─────────────── function f=objfun(p) global PT U S1 S2 W Cpf Cpg dH R r NN20 L L=p; % % Solve for the BVP ODE model % xint=linspace(0,1,20); solinit=bvpinit(xint, @init); sol=bvp4c(@ode, @bc, solinit); yint=deval(sol, xint); index=length(xint); Tf=yint(1,index); Tg=yint(2,index); NN2=yint(3,index); % % Calculate the objective function value % 141
  • 142. 06Process Optimization MATLAB program design: ─────────────── ex6_2_6.m ─────────────── f=1.198e7-1.710e4*NN2+704.4*Tg-699.3*Tf-(3.456e7+2.101e9*L)^0.5; f=-f; % % The ODE model % function dydt=ode(t, y) global PT U S1 S2 W Cpf Cpg dH R r NN20 L Tf=y(1); Tg=y(2); NN2=y(3); k1=1.7895e4*exp(-20800/(R*Tg)); k2=2.5714e16*exp(-47400/(R*Tg)); B=NN20-NN2; N=100*NN20/21.75; A=5/100*N+2*B; PN2=PT*NN2/(N-2*B); PH2=PT*(3*NN2)/(N-2*B); 142
  • 143. 06Process Optimization MATLAB program design: ─────────────── ex6_2_6.m ─────────────── PNH3=PT*A/(N-2*B); Q=r*(1.5*k1*PN2*PH2/PNH3-k2*PNH3/(1.5*PH2)); dydt=L*[-U*S1*(Tg-Tf)/(W*Cpf) -U*S1*(Tg-Tf)/(W*Cpg)+(-dH)*S2*Q/(W*Cpg) -Q]; % % Boundary conditions % function res=bc(ya, yb) res=[yb(1)-693 ya(2)-693 ya(3)-701.2]; % % Initial guess values % function yinit=init(x) yinit=[693 143
  • 144. 06Process Optimization MATLAB program design: ─────────────── ex6_2_6.m ─────────────── 693 701.2]; ───────────────────────────────────────────────── 144
  • 145. 06Process Optimization Execution results: >> ex6_2_6 The optimal reactor length is 14.313 m, and the maximum profit is 3.125e+005. 145
  • 146. 06Process Optimization Example 6-2-7 Optimal operating temperature for a tubular reactor 146
  • 147. 06Process Optimization Suppose the reaction time is 10 hours, determine the optimal profile of the operating temperature such that the concentration of the product B (x2) is maximized at the end of the reaction. 147 I ki0 Ei 1 5.35  105 1.82  104 2 4.61  109 3.16  104 3 2.24  108 2.87  104
  • 148. 06Process Optimization Problem formulation and analysis: 148 where τ = t/tf (0 ≤ τ ≤ 1) is the dimensionless time and the reaction time is tƒ = 10 hr. s.t.
  • 149. 06Process Optimization MATLAB program design: ─────────────── ex6_2_7.m ─────────────── function ex6_2_7 % % Example 6-2-7 Optimal operating temperature in a tubular reactor % clear; close all; clc % global x0 tspan k0 ER tf dt T % % System operation data % x0=[0.95 0.05]'; % Initial state values k0=[5.35e5 4.61e9 2.24e8]; % ko value E=[1.82e4 3.16e4 2.87e4]; % E value R=1.987; % Ideal gas constant (kcal/kg-mol.K) ER=E/R; % E/R value tf=10; % reaction time (hr) 149
  • 150. 06Process Optimization MATLAB program design: ─────────────── ex6_2_7.m ─────────────── % n=10; % number of sections (intervals) N=n+1; N=n+1; % % number of points dt=1/n; % time interval tspan=linspace(0, 1, N); % dimensionless time % % Upper and lower bounds and the initial guess values % pL=[273*ones(1,N)]/100; % Lower bounds pU=[873*ones(1,N)]/100; % Upper bounds p0=(pL+pU)/2; % Initial guess value % % Solve the dynamic optimization problem % [P, fval]=fmincon(@objfun, p0, [ ], [ ], [ ], [ ], pL, pU); % % Results printing 150
  • 151. 06Process Optimization MATLAB program design: ─────────────── ex6_2_7.m ─────────────── % T=P*100; fprintf('n At the end of the reaction, the maximum value of x2 is %.3f.n', -fval) % % Numerical solution of the ODE % [s, x]=ode45(@ode, tspan, x0); % % Plot of the system states % figure(1) plot(s,x(:,1), 'r', s, x(:,2), '-.b') xlabel('Dimensionless time, t/tf') ylabel('System states') legend('x1', 'x2') % % Optimal temperature distribution 151
  • 152. 06Process Optimization MATLAB program design: ─────────────── ex6_2_7.m ─────────────── % figure(2) stairs(s, T) xlabel('Dimensionless time, t/tf') ylabel('Temperature (K)') title('Optimal temperature distribution') % % Objective function % function f=objfun(P) global x0 tspan k0 ER tf dt T % T=P*100; % % Solving the ODE % [s, x]=ode45(@ode, tspan, x0); 152
  • 153. 06Process Optimization MATLAB program design: ─────────────── ex6_2_7.m ─────────────── % % Calculating the objective function value % f=x(end, 2); f=-f; % % Kinetic equations % function dxdtau=ode(tau, x) global x0 tspan k0 ER tf dt T i=floor(tau/dt)+1; Ti=T(i); k=k0.*exp(-ER/Ti); k1=k(1);k2=k(2);k3=k(3); dxdtau=tf*[-k1*x(1)^2+k2*x(2) k1*x(1)^2-(k2+k3)*x(2)]; ───────────────────────────────────────────────── 153
  • 154. 06Process Optimization Execution results: >> ex6_2_7 At the end of the reaction, the maximum value of x2 is 0.545. 154
  • 156. 06Process Optimization 6.4 Summary of the MATLAB commands related to this chapter 156 Command Function fminbnd The solver for the solution of univariate optimization problems fminunc The solver for multivariate optimization problems without constraints fminsearch The solver using Simplex method for the multivariate optimal problem without constraints linprog The solver for linear programming problems quadprog The solver for quadratic programming problems fmincon The solver for nonlinear optimization problems fgoalattain The solver for multi-objective goal attainment optimization problems fseminf The solver for semi-infinite optimization problems fminimax The solver for minimax problems bintprog The solver for binary integer programming problems rcga A real-coded genetic algorithm for process optimization