33
1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

Embed Size (px)

Citation preview

Page 1: 1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

1

Chapter 5 Nonlinear Programming

Chemical Engineering DepartmentNational Tsing-Hua University

Prof. Shi-Shang JangMay, 2003

Page 2: 1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

2

Problem Statement

KkMj

Rx

xh

xgts

xf

N

k

j

,...,1 .,...,1

0)(

0)(..

)(min

Page 3: 1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

3

5-1 ExamplesExample: Multistage Compressor Optimization

Driver stage1 stage2 stage3

N (ml/hr) P = 1 (atm)

T T T

X1 X2

T ,P=64atm

Page 4: 1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

4

Example: Multistage Compressor Optimization

:have we

NT, fixed,4

1let

1 where

364

11

constant gas idea,

11

21

21

1

K

K

xx

xx

K

KNRTW

RC

CK

K

KNRT

P

P

K

KNRTW

total

v

p

K

K

in

out

Page 5: 1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

5

Example: Multistage Compressor Optimization

2

12

1

4/1

2

4/1

1

24/11

64

1..

64min

x

xx

xts

xx

xxxf

Page 6: 1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

6

5-3 Lagrange Multiplier

xhvL

x

hv

x

f

v)L(x

xvhxfvxL

xhts

xf

0

figure see00xL

, of optimality theofcondition necessary thefind

,set

0)( ..

)(min

Page 7: 1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

7

Lagrange Multiplierf(x,y)=(x-3)2+(y-3)2,h(x)=y+x2-3x=0

Page 8: 1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

8

Solution

2,2,2

03

032

03232

333

2

222

vyx

x-y+xvL

)-v(y-yL

)x-)-v((x-xL

x-y+xvyxL

Page 9: 1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

9

Physical Meaning of Lagrange Multiplier – Shadow Price

**,* shown that becan It

0))((,0**,

)()(),(

)(..

)(min

vvxxb

fv

bxhv

L

x

Lsolvesvx

xvhxfvxL

bxhts

xf

Page 10: 1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

10

5-4 Kuhn-Tucker Condition

0,0

0,0

equations N0

:Condition TK

,,1 .,,1

0)(

0)(..

)(min

jjj

kj

k kkjj j

k

j

ugu

hg

hvguf

KkMj

xh

xgts

xf

Page 11: 1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

11

K-T Condition - Example

5 ,1**,

06

030

01..

)(min

21

211

22

212

11

221

xx

xxh

xxg

xgts

xxxf

Page 12: 1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

12

K-T Condition - Example

0,

030

01

06

030

01

021

022

21

22

212

11

21

22

21

1

122

12111

uu

xxu

xu

xx

xx

x

vux

vuxux

Page 13: 1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

13

K-T Condition - Example

The above problem is reduced to :

3,1,0

0101

022

112

12

121

uvu

vu

vuu

Page 14: 1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

14

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).

Page 15: 1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

15

K-T Theory - Example f(x)=x1

2-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-x1

2-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, ∴g2 concave

The solution is global optimum

Page 16: 1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

16

5-5 Duality of Linear Programming

Primal problem:

The corresponding Lagrangian can be expressed by

0;0..

min

1

1

ij

n

iiji

n

iii

xbxats

xcy

n

iiij

n

iiji

m

jj

n

iii xbxaxcL

1111

Page 17: 1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

17

Duality of Linear Programming

At x*

Also

Substitute for ci above get:

n

iiixcL

1

**

01

k

m

jjkjk

k

acx

L

m

jjj

m

j

n

iijijj

n

ii

m

jjiji bxabaxL

1

*

1 1

**

1 1

***

Page 18: 1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

18

Duality of Linear Programming

The Dual Problem hence becomes:

k

m

jjkj

m

jjj

cats

bw

1

1

..

max

0with j

Page 19: 1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

19

Example – Primal Problem

0,,

5

85.05.12

205.124

4868..

203060max

321

2

321

321

321

321

xxx

x

xxx

xxx

xxxts

xxx

Page 20: 1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

20

Example – Dual Problem

0,,,

205.05.1

305.126

60248..

582048min

4321

321

4321

321

4321

ts

Page 21: 1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

21

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?

Page 22: 1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

22

Example: Charity Work- ContinuedResources Desk Table Chair

Lumber (Board feet) 8 6 1

Finishing hours (hours) 4 2 1.5

Carpentry (hours) 2 1.5 0.5

Page 23: 1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

23

Example: Charity Work- Continued (Primal and Dual)

Primal:

Dual:

0,,

5:

85.05.12:

205.124:

4868: ..

203060max

321

24

3213

3212

3211

321

xxx

xg

xxxg

xxxg

xxxgts

xxxz

0,,,

2005.05.1:

305.126:

600248: ..

582048min

4321

43213

43212

4321

4321

g

g

gts

w

1

Page 24: 1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

24

Example: Charity Work- Continued (MATLAB Code)%Primalb=[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%Dualff=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

Page 25: 1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

25

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

Page 26: 1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

26

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.

Page 27: 1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

27

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.

Page 28: 1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

28

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.)

Page 29: 1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

29

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);

Page 30: 1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

30

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 4Optimization 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

Page 31: 1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

31

Example

028.09

012..

33)(min

2212

2211

22

21

xxg

xxgts

xxxf

Page 32: 1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

32

Contour Plot and Constraints

Page 33: 1 Chapter 5 Nonlinear Programming Chemical Engineering Department National Tsing-Hua University Prof. Shi-Shang Jang May, 2003

33

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,'exa

mp_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