330 likes | 349 Views
Chapter 5 Nonlinear Programming. Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003. Problem Statement. Driver. stage1. stage2. stage3. T. T. ,P=64atm. T. T. X 1. N (ml/hr) P = 1 (atm). X 2.
E N D
Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003
Driver stage1 stage2 stage3 T T ,P=64atm T T X1 N (ml/hr) P = 1 (atm) X2 5-1 ExamplesExample: Multistage Compressor Optimization
K-T Condition - Example • The above problem is reduced to :
K-T Theory • Theorem 1: (Necessity) Consider the NLP problem (1). Let f, g and h be differentiable and x* is the solution, also gj(x*) and hk(x*) be differentiable. Then there exist u*, v* solve K-T problem. • Theorem 2 : (Sufficiency) • Consider the NLP problem (1). Let f(x) be convex, g (x) be concave functions, and h(x) be linear if there exist x*, u* and v* solve K-T problem., then x* is the optimality of (1).
K-T Theory - Example • f(x)=x12-x2 (1,1),(2,2),(1.5,1.5) • f(1,1)=0, f(2,2)=2,f(1.5,1.5)=0.75<1 • ∴f convex • h1=x1+x2-6 linear • g1=x1-1 concave • g2=30-x12-x22 (1,1), (2,2),(1.5,1.5) • g2(1,1)=28, g2(2,2)=22, g2(1.5,1.5)=25.5>25, • ∴g2concave • The solution is global optimum
5-5 Duality of Linear Programming • Primal problem: • The corresponding Lagrangian can be expressed by
Duality of Linear Programming • At x* • Also • Substitute for ci above get:
Duality of Linear Programming • The Dual Problem hence becomes:
Example: Charity Work • The local college’s School of American Craftsman has decided to participate seriously in a local charity event by manufacturing special commemorative desks, tables, and chairs. Resources are restricted as shown in the next table. The local lumber cooperative has donated 48 board feet of lumber. Faculty and staff have volunteered 20 finishing hours and 8 carpentry hours. The desk will be sold for $60, the table $30 and the chair for $20. The school does not expect to sell more than 5 tables. How does the school should do to maximize the profit?
Example: Charity Work- Continued (Primal and Dual) • Primal: • Dual:
Example: Charity Work- Continued (MATLAB Code) %Primal b=[48;20;8;5]; Aeq=[];beq=[]; UB=[Inf Inf Inf]';LB=[0 0 0]'; f=[-60;-30;-20]; A=[8 6 1;4 2 1.5;2 1.5 0.5;0 1 0]; [X,FVAL,EXITFLAG,OUTPUT,LAMBDA]=LINPROG(f,A,b,Aeq,beq,LB,UB); X' LAMBDA.ineqlin %Dual ff=f; AA=-A'; bb=b; UB=[Inf Inf Inf Inf]';LB=[0 0 0 0]'; [X,FVAL,EXITFLAG,OUTPUT,LAMBDA]=LINPROG(bb,AA,ff,Aeq,beq,LB,UB) X' LAMBDA.ineqlin
Example: Charity Work- Continued (MATLAB Result) • >> Optimization terminated successfully. ans = 2.0000 0.0000 8.0000 ans = 0.0000 10.0000 10.0000 0.0000 Optimization terminated successfully. ans = 0.0000 10.0000 10.0000 0.0000 ans = 2.0000 0.0000 8.0000
5-6 MATLAB NLP tool • FMINCON Finds a constrained minimum of a function of several variables. • FMINCON solves problems of the form: • min F(X) subject to: A*X <= B, Aeq*X = Beq (linear constraints) • X C(X) <= 0, Ceq(X) = 0 (nonlinear constraints) • LB <= X <= UB • X=FMINCON(FUN,X0,A,B) starts at X0 and finds a minimum X to the function • FUN, subject to the linear inequalities A*X <= B. FUN accepts input X and • returns a scalar function value F evaluated at X. X0 may be a scalar, • vector, or matrix.
MATLAB NLP tool-continued • X=FMINCON(FUN,X0,A,B,Aeq,Beq) minimizes FUN subject to the linear equalities • Aeq*X = Beq as well as A*X <= B. (Set A=[] and B=[] if no inequalities exist.) • X=FMINCON(FUN,X0,A,B,Aeq,Beq,LB,UB) defines a set of lower and upper • bounds on the design variables, X, so that a solution is found in • the range LB <= X <= UB. Use empty matrices for LB and UB • if no bounds exist. Set LB(i) = -Inf if X(i) is unbounded below; • set UB(i) = Inf if X(i) is unbounded above.
MATLAB NLP tool-continued • X=FMINCON(FUN,X0,A,B,Aeq,Beq,LB,UB,NONLCON) subjects the minimization to the • constraints defined in NONLCON. The function NONLCON accepts X and returns • the vectors C and Ceq, representing the nonlinear inequalities and equalities • respectively. FMINCON minimizes FUN such that C(X)<=0 and Ceq(X)=0. • (Set LB=[] and/or UB=[] if no bounds exist.)
Example: Multi-Stage compressor (MATLAB Code) A=[-1 0;1 -1;0 1]; B=[-1;0;64]; X0=[2;10]; X=FMINCON('stage_com',X0,A,B) function obj=stage_com(x); x1=x(1);x2=x(2); obj=x1^(0.25)+(x2/x1)^0.25+(64/x2)^(0.25);
Example: Multi-Stage compressor (MATLAB Result) >> Warning: Large-scale (trust region) method does not currently solve this type of problem, switching to medium-scale (line search). > In C:\MATLAB6p5\toolbox\optim\fmincon.m at line 213 In C:\MATLAB6p5\work\stage_com_main.m at line 4 Optimization terminated successfully: Magnitude of directional derivative in search direction less than 2*options.TolFun and maximum constraint violation is less than options.TolCon No Active Constraints X = 3.9994 16.0011
MATLAB PROGRAM • X0=[2 1];A=[];B=[];Aeq=[];Beq=[];LB=[0 0];UB=[5 5]; • X=FMINCON('examp_FUN',X0,A,B,Aeq,Beq,LB,UB,'examp_NONLCON') • function y=examp_FUN(x) • y=(x(1)-3)^2+(x(2)-3)^2; • function [c,ceq]=examp_NONLCON(x) • ceq=[]; • c(1)=-2*x(1)+x(2)^2+1; • c(2)=0.8*x(1)^2+2*x(2)-9; • X = 2.5000 2.0000