You are on page 1of 25

CHEN10050

Computational Methods for Chemical Engineering

5 – Optimisation

Cláudio P. Fonte
Department of Chemical Engineering and Analytical Science
Learning Objectives
The objective of this video is to introduce you to how numerical optimisation
can be used to determine minima and maxima of both on-dimensional and
multidimensional functions.

Specific objectives and topics covered are:

• Understanding why and where optimisation occurs in Chemical


Engineering
• Locating the optimum of a single-variable function with the golden-
section method
• Knowing how to apply the MATLAB fminbnd function to determine the
minimum of a one-dimensional function
• Knowing how to apply the MATLAB fminsearch function to determine
the minimum of a multidimensional function.
• Knowing how to recast a maximisation problem so it can be solved with a
minimisation algorithm
© Cláudio Fonte, 2020
CHEN10050
Computational Methods for Chemical Engineering

5.1 – Motivation and numerical methods

Cláudio P. Fonte
Department of Chemical Engineering and Analytical Science
Optimisation
Problem
Given ! " = "$ − $" + ', find the values of ( that correspond to local minima and
maxima of )(()
5
Solve for ( so that ) , ( =0
!′(")
The solution is:
(/ = −1
(1 = 1

If:
) ,, ( < 0 → Local maximum (
!(")
) ,, ( > 0 → Local minimum
!′′(")

© Cláudio Fonte, 2020


Optimisation

A function can have


multiple maxima and
minima

© Cláudio Fonte, 2020


Optimisation in Chem. Eng.
As engineers we must continuously design equipment and products that perform a task in
the most efficient fashion and for the lowest cost à sustainable processes and products

• Design pumps, heat exchangers, distillation columns, chemical reactors, etc., for
maximum efficiency (minimise operational costs)
• Material-cutting strategy for minimum investment cost (stainless steel, insulating
materials, …)
• Heat integration to minimise operational costs
• Network of heat exchangers
• Optimal scheduling of batch equipment operation
• Inventory control
• Process control
• …

© Cláudio Fonte, 2020


Optimisation in Chem. Eng.
$ A cylindrical pressure vessel with a hemispherical head and bottom
is needed for a process.
It needs to have a fixed volume ! = 10 m* given by
& 4 *
!= #$%& + #$
3
and a thickness + = 5 ×100* m.
The cost of the vessel is given by
3 = 45 + 46 2#$&+ + 48 4#$%+
Find the values of
where
; and < that
45 = £10 000 is the fixed costs of manufacture and delivery
minimise the cost
46 = £20 000/m* is the cost of the side wall
of the vessel.
48 = £50 000/m* is the cost of the head and bottom
© Cláudio Fonte, 2020
Methods you already know
Analytical solutions

Excel Solver

Graphical methods
• Approximate solutions
• Impractical for functions with more than two variables

Finding the roots of the derivative of the function


• Graphically
• Bisection method
• False position method
• Newton-Raphson method
• MATLAB functions for root finding
© Cláudio Fonte, 2020
Golden-section search
Golden ratio
1) Find suitable guesses of !) and !( that
bracket a single minimum of "(!)
ℓ* 1 + 5
0= =
ℓ. 2
2) New estimates of the minimum are
"(!) calculated as
ℓ* ℓ. !* = !( + -
!. = !) − -
where - = 0 − 1 !) − !(

!( !%&' !) !
!*
© Cláudio Fonte, 2020
Golden-section search
Golden ratio
1) Find suitable guesses of !) and !( that
bracket a single minimum of "(!)
ℓ- 1 + 5
*= =
ℓ. 2
2) New estimates of the minimum are
"(!) calculated as
!- = !( + 3
ℓ. ℓ- !. = !) − 3
where 3 = * − 1 !) − !(

!( !%&' !) !
!. !-
© Cláudio Fonte, 2020
Golden-section search
1) Find suitable guesses of !) and !( that
Minimum contained bracket a single minimum of "(!)
between /0 and /1
2) New estimates of the minimum are
"(!) calculated as
Eliminate
!* = !( + 3
!, = !) − 3
where 3 = 5 − 1 !) − !(

3) If " !* < " !,


!( = !,

!( !%&' !) ! If " !* > " !,


!, !* !) = !*
© Cláudio Fonte, 2020
Golden-section search 3) If " !* < " !,
!( = !,
MATLAB code
in page 208 If " !* > " !,
!) = !*
"(!)
method operates by successively
narrowing the range of values on the
specified interval

Repeat the algorithm until

23 425
(2 − 1) ≤ :;
2678
!( !%&' !) !
!) or number of iterations max
© Cláudio Fonte, 2020
CHEN10050
Computational Methods for Chemical Engineering

5.2 – MATLAB functions

Cláudio P. Fonte
Department of Chemical Engineering and Analytical Science
MATLAB function fminbnd
The MATLAB function fminbnd can also be used for one-dimensional minimisation. It
combines different methods for function minimisation into a single algorithm for balanced
reliability and efficiency.
Its syntax is the following:

[xmin, fval] = fminbnd(function, x1, x2)

xmin and fval are the location and value of the minimum.

function is the name of the function being evaluated.

x1 and x2 are the bounds of the interval being searched.

© Cláudio Fonte, 2020


MATLAB function fminbnd
Given ! " = "$ − $" + ', find the values of ( that correspond to local minima and
maxima of )(()

To evaluate the local minimum

[xmin, fval] = fminbnd(@(x) x^3-3*x+5,0,3)


>> xmin = 1.0000
fval = 3
ü
What about the maximum?

fminbnd can only be used to find


minima of functions...
© Cláudio Fonte, 2020
MATLAB function fminbnd
The process of finding a maximum versus finding a minimum is essentially identical

The same value xoptimum that minimizes f(x) also maximizes − f(x)

optimum

© Cláudio Fonte, 2020


MATLAB function fminbnd
Given ! " = "$ − $" + ', find the values of ( that correspond
to local minima and maxima of )(()

To evaluate the local maximum

[xmin, fval]=fminbnd(@(x) –(x^3-3*x+5),-3,0)

>> xmin = -1.0000


fval = -7

Do not forget to change the sign of fval back if


you want the value of ! " at the maximum!

The local maximum value of ! " is 7 at " = −,


© Cláudio Fonte, 2020
MATLAB function fminsearch

MATLAB has a function fminsearch that can be used to determine minima of multi-
variable functions.
Its syntax is the following:

[xmin, fval] = fminsearch(function, x0)

xmin and fval are the location and value of the minimum.

function is the name of the function being evaluated.

x0 is the initial guess. x0 can be a scalar, vector or matrix.

© Cláudio Fonte, 2020


MATLAB function fminsearch
Given ! " = "$ − $" + ', find the values of ( that correspond to local minima and
maxima of )(()

To evaluate the local minimum


[xmin, fval] = fminsearch(@(x) x^3-3*x+5,0)
>> xmin = 1.0000
fval = 3

To evaluate the local maximum


[xmin, fval] = fminsearch(@(x) -(x^3-3*x+5),0)

>> xmin = -1.0000


fval = -7 Don’t forget to change the sign back!

© Cláudio Fonte, 2020


MATLAB function fminsearch
Given ! "# , "% = % + "# − "% + %"%# + %"# "% + "%% ,
find the values of )* and )+ that correspond to local minima of ,()*, )+)

f=@(x) 2+x(1)-x(2)+2*x(1)^2+2*x(1)*x(2)+x(2)^2;

[xmin, fval] = fminsearch(f,[-0.5,0.5])

>> xmin =
-1.0000 1.5000

fval = 0.7500

Check page 212 to learn how to generate


plots of 2D functions in MATLAB
© Cláudio Fonte, 2020
CHEN10050
Computational Methods for Chemical Engineering

5.3 – Worked example

Cláudio P. Fonte
Department of Chemical Engineering and Analytical Science
Worked example
$ A cylindrical pressure vessel with a hemispherical head and bottom
is needed for a process.
It needs to have a fixed volume ! = 10 m* given by
& 4 *
!= #$%& + #$
3
and a thickness + = 5 ×100* m.
The cost of the vessel is given by
3 = 45 + 46 2#$&+ + 48 4#$%+
Find the values of
where
; and < that
45 = £10 000 is the fixed costs of manufacture and delivery
minimise the cost
46 = £20 000/m* is the cost of the side wall
of the vessel.
48 = £50 000/m* is the cost of the head and bottom
© Cláudio Fonte, 2020
MATLAB function fminsearch

min ' = )* + ), 2./01 + )2 4./4 1


$, &

4 6
Subject to: ./40 + ./ = 7
3
7 = 10
1 = 5 ×10<6 4
7 − ./6
)* = 10000 0= 3
./4
), = 20000
)2 = 50000
/, 0 ≥ 0

© Cláudio Fonte, 2020


MATLAB function fminsearch
4
9 − 3 8.(
4 ( 0=
9 − 8. 8.=
min 6 = )* + )+ 28 3 ! + )- 48. = !
5 8.

Subject to: 9 = 10
! = 5 ×10'(
)* = 10000
)+ = 20000
)- = 50000
., 0 ≥ 0

© Cláudio Fonte, 2020


Summary
• Why and when optimisation problems can occur in Chemical Engineering
• How to locate minima of a function using the golden-section method
• How to use the MATLAB function fminbnd to find minima of a single-variable
function
• How to use the MATLAB function fminsearch to find minima of a single-variable
and multi-variable functions
• How to transform a maximisation problem into a minimisation problem so that it
can be solved with a minimisation algorithm

Try to solve now exercise sheet no. 5 with


suggested problems from the e-book

© Cláudio Fonte, 2020

You might also like