You are on page 1of 49

KOMPUTASI NUMERIK

LECTURE #4 - OPTIMIZATION
Dr. Aries Subiantoro
Research Center for Advanced Vehicle (RCAVe)
Sources

Presentation based on materials from:

• Chapra chapter 7
• Papalambros & Wilde (2000): Principles of optimal design

3
Chapter Objectives

DTE
ko m n u m
4
Introduction
The difference between roots and optima

5
Optimization Problem Formulation

The mathematical problem formulation is to the


heart of the success of design optimization

6
Example: Airtank Design

7
Example: Airtank Design

8
Design Optimization

Design optimization is the selection of the best


design with the available means

(Papalambros & Wilde, 2000)

9
Design Optimization

1) Select design variables


2) Select objective criterion in terms of design variables
(to minimize or maximize)
3) Determine constraints in terms of design variables
which must be satisfied
4) Determine design variable values which minimize
(maximize) the objective while satisfying all constraints

10
Mathematical Problem Formulation

11
Formulation Examples

12
Example: Airtank Design 1-D

13
Unconstrained Problem

14
Existence

15
Taylor Series Expansion

16
16 3/1/2022 Add a footer
Optimality

17
17 3/1/2022 Add a footer
Example 1

18
18 3/1/2022 Add a footer
Example 2

19
One Variable Minimization

20
One Variable Minimization

21
One Variable Minimization: Sectioning

22
One Variable Minimization: Golden Section

23
Example: Golden Section
Iterasi #1 Iterasi #2

Iterasi #3 Iterasi #8

24
One Variable Minimization: Quadratic Interpolation

1 𝛼 −𝛼 𝑓 𝛼 + 𝛼 −𝛼 𝑓 𝛼 + 𝛼 − 𝛼 𝑓(𝛼 )
𝛼 =
2 𝛼 −𝛼 𝑓 𝛼 + 𝛼 −𝛼 𝑓 𝛼 + 𝛼 − 𝛼 𝑓(𝛼 )

25
Example: Quadratic Interpolation
Iterasi #1 Iterasi #2

Iterasi #3 Iterasi #8

26
Multi Dimensional Optimization

27
Steepest Descent Direction

28
Gradient Algorithm

29
Example

min f (x)  ( x1  3) 2  ( x2  2) 2
x

h1(x1,x2): 2x1 + x2 =8
h2(x1,x2): (x1-1)2 + (x2-4)2 = 4
g1(x1,x2): x1 + x2 ≤ 7
g2(x1,x2): x1 – 0.25x22 ≤ 0

0 ≤x1 ≤10; 0 ≤x2 ≤10;


function retval = obj_ex1(x1, x2)

retval = (x1-3).*(x1-3) + (x2-2).*(x2-2);

inecon1.m
function retval =inecon1(x1, x2)

retval = x1 + x2;
30
Example

inecon2.m
function retval = inecon2(x1,x2)

retval = x1 - 0.25*x2.^2;

eqcon1.m
function retval = eqcon1(x1, x2)

retval = 2*x1 + x2;

eqcon2.m
function retval = eqcon2(x1, x2)

retval = (x1-1).*(x1-1) + (x2-4).*(x2-4);

31
Example
% Minimize f(x1,x2) = (x1-3)**2 + (x2-2)**2
%
% h1(x1,x2) = 2x1 + x2 = 8
% h2(x1,x2) = (x1-1)^2 + (x2-4)^2 = 4
% g1(x1,x2) : x1 + x2 <= 7
% g2(x1,x2) : x1 - 0.25x2^2 <= 0.0
%
% 0 <= x1 <= 10 ; 0 <= x2 <= 10

x1=0:0.1:10; % the semi-colon at the end prevents the echo


x2=0:0.1:10; % these are also the side constraints
% x1 and x2 are vectors filled with numbers starting
% at 0 and ending at 10.0 with values at intervals of 0.1

[X1 X2] = meshgrid(x1,x2);


% generates matrices X1 and X2 correspondin
% vectors x1 and x2

f1 = obj_ex1(X1,X2);% the objecive function is evaluated over the entire mesh


ineq1 = inecon1(X1,X2);% the inequality g1 is evaluated over the mesh
ineq2 = inecon2(X1,X2);% the inequality g2 is evaluated over the mesh
eq1 = eqcon1(X1,X2);% the equality 1 is evaluated over the mesh
eq2 = eqcon2(X1,X2);% the equality 2 is evaluated over the mesh
32
Example

eq1 = eqcon1(X1,X2);% the equality 1 is evaluated over the mesh


eq2 = eqcon2(X1,X2);% the equality 2 is evaluated over the mesh

[C1,h1] = contour(x1,x2,ineq1,[7,7],'r-');
clabel(C1,h1);
set(h1,'LineWidth',2)
% ineq1 is plotted [at the contour value of 8]
hold on % allows multiple plots
k1 = gtext('g1');
set(k1,'FontName','Times','FontWeight','bold','FontSize',14,'Color','red')
% will place the string 'g1' on the lot where mouse is clicked

[C2,h2] = contour(x1,x2,ineq2,[0,0],'r--');
clabel(C2,h2);
set(h2,'LineWidth',2)
k2 = gtext('g2');
set(k2,'FontName','Times','FontWeight','bold','FontSize',14,'Color','red')

[C3,h3] = contour(x1,x2,eq1,[8,8],'b-');
clabel(C3,h3);
set(h3,'LineWidth',2)
k3 = gtext('h1');
set(k3,'FontName','Times','FontWeight','bold','FontSize',14,'Color','blue')
33
Example
% will place the string 'g1' on the lot where mouse is clicked
[C4,h4] = contour(x1,x2,eq2,[4,4],'b--');
clabel(C4,h4);
set(h4,'LineWidth',2)
k4 = gtext('h2');
set(k4,'FontName','Times','FontWeight','bold','FontSize',14,'Color','blue')

[C,h] = contour(x1,x2,f1,'g');
clabel(C,h);
set(h,'LineWidth',1)

% the equality and inequality constraints are not written


% with 0 on the right hand side. If you do write them that way
% you would have to include [0,0] in the contour commands

xlabel(' x_1 values','FontName','times','FontSize',12,'FontWeight','bold');


% label for x-axes
ylabel(' x_2 values','FontName','times','FontSize',12,'FontWeight','bold');

set(gca,'xtick',[0 2 4 6 8 10])
set(gca,'ytick',[0 2.5 5.0 7.5 10])

k5 = gtext({'Chapter 2: Example 1','pretty graphical display'})


set(k5,'FontName','Times','FontSize',12,'FontWeight','bold')
34
Example: Pretty Graphical Display

35
Additional Examples (Filled Labelled Contour)
x1=-1:0.01:1; % the semi-colon at the end prevents the echo
x2=-1:0.01:1; % these are also the side constraints
% x1 and x2 are vectors filled with numbers starting
% at 0 and ending at 10.0 with values at intervals of 0.1

[X1 X2] = meshgrid(x1,x2);


% generates matrices X1 and X2 correspondin
% vectors x1 and x2

% filled contour with default colormap


% help graph3d gives you the choices for colormap
f1 = obj_ex2(X1,X2);% the objecive function is evaluated over the entire mesh
[C1,h1] = contourf(x1,x2,f1,...
[0 0.1 0.3 0.6 0.8 1.0 1.2 1.5 1.8 2.0 2.2 2.4 2.6 2.8 3.0]);
clabel(C1,h1);
colorbar % illustrates the scale
grid
set(gca,'xtick',[-1 -0.5 0.0 0.5 1.0])
set(gca,'ytick',[-1 -0.5 0.0 0.5 1.0])
grid
xlabel(' x_1 values','FontName','times','FontSize',12); % label for x-axes
ylabel(' x_2 values','FontName','times','FontSize',12);
title({'Filled Labelled Contour','default color'}, ...
'FontName','times','FontSize',10)
grid
36
Additional Examples(Filled Labelled Contour)

37
Additional Examples (2D Contour with Gradient Vectors)

% a new figue is used


% basic contour plot superimposed with gradient information
% information is generated on a larger mesh to keep the
% figure tidy. grid is removed for clarity

figure
y1 = -1:0.1:1.0;
y2 = -1:0.1:1;
[Y1,Y2] = meshgrid(y1,y2);
f2 = obj_ex2(Y1,Y2);
[C2,h2] = contour(y1,y2,f2,[0 0.5 0.75 1.0 1.5 1.75 2.0 2.5 2.5 3.0]);
clabel(C2,h2)
[GX, GY] = gradient(f2,0.2);
hold on
quiver(Y1,Y2,GX,GY);
hold off
set(gca,'xtick',[-1 -0.5 0.0 0.5 1.0])
set(gca,'ytick',[-1 -0.5 0.0 0.5 1.0])
xlabel(' x_1 values','FontName','times','FontSize',12); % label for x-axes
ylabel(' x_2 values','FontName','times','FontSize',12);
title({'2D Contour','with Gradient Vectors'}, ...
'FontName','times','FontSize',10)
38
Additional Examples (2D Contour with Gradient Vectors)

x2

x1

39
Additional Examples (Coarse Mesh Plot)

% a mesh of the function


figure
colormap(cool)

mesh(y1,y2,f2)
set(gca,'xtick',[-1 -0.5 0.0 0.5 1.0])
set(gca,'ytick',[-1 -0.5 0.0 0.5 1.0])
colorbar
xlabel(' x_1 values','FontName','times','FontSize',12); % label for x-axes
ylabel(' x_2 values','FontName','times','FontSize',12);
title({'Coarse Mesh Plot','colormap - cool'}, ...
'FontName','times','FontSize',10)

grid

40
Additional Examples (Coarse Mesh Plot)

41
Additional Examples (Coarse Surface Plot)

% surface plot with default colormap


figure
colormap(jet)
surf(y1,y2,f2)
grid
colorbar
set(gca,'xtick',[-1 -0.5 0.0 0.5 1.0])
set(gca,'ytick',[-1 -0.5 0.0 0.5 1.0])
title({'Coarse Surface Plot','colormap - jet/default'}, ...
'FontName','times','FontSize',10)
grid

xlabel(' x_1 values','FontName','times','FontSize',12); % label for x-axes


ylabel(' x_2 values','FontName','times','FontSize',12);

42
Additional Examples (Coarse Surface Plot)

x2

x1

43
Unconstrained Optimum – 2D Examples

44
Case Study: 2D Equilibrium Potential Energy

45
Homework

• Chapra chapter 7 nomor: 7.7, 7.16, 7.28 dan 7.34


• Platform pengumpulan tugas: Sistem EMAS
• Deadline: Senin, 7 Maret 2022, pukul 08.00 WIB
• Format file PDF: [NPM]_[Nama]_[Tugas #2]
• Tugas presentasi pekan depan:
• Kelompok V: soal 7.16
• Kelompok VI: soal 7.34

DTE
ko m n u m
46
ThankYou
Aries Subiantoro
021-7270078
aries.subiantoro@ui.ac.id
RCAVe

DTE
ko m n u m
47
Tugas

48
Tugas

49

You might also like