0% found this document useful (0 votes)
10 views

2 Graphical Optimization

Graphical Optimization

Uploaded by

B M Fakhor Uddin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

2 Graphical Optimization

Graphical Optimization

Uploaded by

B M Fakhor Uddin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

2 GRAPHICAL OPTIMIZATION

This book includes a large number of examples with two variables. Two-variable problems can be
displayed graphically and the solution obtained by inspection. Along with the usefulness of
obtaining the solution without applying mathematical conditions, the graphical representation of
the problem provides an opportunity to explore the geometry of many of the numerical
techniques we examine later. This is necessary for intuitively understanding the algorithm and its
progress toward the solution. In practical situations which usually involve over two variables,
there is no opportunity for neat graphical correlation because of the limitations of graphical
representation. It will be necessary to review the numbers to decide on convergence or the lack
thereof. What happens with many variables is an extension of the geometric features that are
observed in problems involving two variables. A good imagination is an essential tool for these
problems with many variables.
Contour plots provide the best graphical representation of the optimization problem in two
variables. The points on any contour (or curve) have the same value of the function. Several so 抗
ware packages are available to create and display these plots. MATLAB, Mathematica, Maple ,
and Mathcad are among the general-purpose software packages that can draw contour plots. In
this book, we will use MATLAB for graphical optimization.
2.1 PROBLEM DEFINITION
The standard format for optimization problems was established in Chapter 1. It is reintroduced
here for convenience:
Minimize fl..xJ,X2,.••,Xn)
Subject to: h,(x"X2,•••,Xn)=0
h2(x,・X2・・..,x,,)=O
ht(XI,X2・・...X,,)=0
gl(X"X2・・...Xn)三 o
g2(XI.X2・・..,Xn)SO
glll(X"X2・・...x,,)SO
x:gxi 三 X7.i=I,2,...,n
(2.1)
(2.2)
(2.3)
(2.4)
In this chapter, while adhering to the format, the necessity for zero on the right-hand side is
relaxed. This is being done for convenience and to aid comprehension. The right-hand side can
also have numerical values other than zero. The first example chosen for illustration is a simple
one using elementary functions whose graphical nature is well known. This simple example will
permit examination of the MATLAB code that will generate the curves and the solution. It will
also allow us to define the format for the disp1ay of solution to the graphical optimization
problem.
2.1.1 Example 2.1
The first example, Example 2.1, will have two equality constraints and two inequality constraints:
Minimize
fl..XI'X2)=(XI-
3)2+(X2-2)2(2.5)
Subjcct to: hl(xl.X2):2x1+x2=8
(2.6a)
h2(x"XU:(XI-
1)2+(ゐ-4)2=4(2.6b)
gl(X"X2):Xl+x2S7
(2.7n)
g2(x,.XU:
(2.7b)
oSXIS10;
OSX2S10
(2.8)
In the above definition, we have two straight lines, two circles, and a parabola. Note that two
equality constraints and two variables imply that there is no scope for optimization. The problem
will be determined by the equality constraints provided the two constraints are linearly
independent, which is true in this example. This example was created to help understand the
code in MATLAB that will be used to draw graphical solutions in this book.
Figure 2.1 illustrates the graphical solution to this problem. The figure also displays additional
information, related to the inequality constraints, placed on it after the principal graphic
information was generated and displayed.
2.1.2 Format for the Graphical Display
The graphical solution to Example 2.1, as seen in Figure 2.1, is generated using MATLAB [1,2]
except for the identification of the inequality constraints. All inequality constraints are
distinguished by hash marks. The hashed side indicates the infeasible region. In MATLAB5.2,
there is no feature to insert these marks through programming. An add-on program called
Matdraw was used to create the hash lines in the figure. It can be downloaded from the
MathWorks site. Beginning with Version5 .3 there is a figure (plotedit) editor that will allow you
to insert additional graphic elements to the figure. The student can also pencil in these hash lines
after obtaining the printout It is to be noted that the graphical solution is incomplete if the
inequality constraints are not distinguished, or if the feasible region has not been established in
some manner.
In the graphical display of solutions, only the objective function is drawn for several contours so
that the direction for the minimum can be identified. Each equality constraint is drawn as a single
curve for the numerical value on the right-hand side. They should be identified. Each inequality
constraint is similarly drawn for a value on the right-hand side. They need to be identified too.
The hash marks are drawn/penciled in on the figure or a printout of the figure. The extent of the
design region is established and the solution identified on the figure. The relevant region can be
zoomed for better accuracy. The data for the plot are obtained using MATLAB's matrix operations
after establishing the plotting mesh. This exploits MATLAB's natural speed for matrix operations.
2. 2 GRAPHI CAL SOLUTI ON
MATLAB poss 凶 s a powerful visualization engi ne that permi ts the solution of 白 e
two-vari able opti mi zati on probl em by inspection. There are three ways to lake
advantage of the graphi c features of M A TI . A B. 百】 e first is lhe use of M A TI . A B'S
hi gh-I evel graphi ng routines for data visualization. This will be 山巴 pri mary way to
solve graphi cal opli mi zati on probl ems in this book. Thi s w il1 also be 出 e way 10
i ncorporate graphi cal explorali on of numeri cal techni ques in 出 e book. For mo 隠
preci se control over the di splay of dat a , MATLAB allows us 巴 r intcraction through
programmi ng usi ng an obj ect -o riented system identified in M A TI . A B as Handl e
Graphi cs. The third use ofthe MATLAB graphi cs engi ne is to use the Handl e Graphi cs
system to devel op a Graphi cal User I nterface (GUI ) for the program or m-file. This
creales a facility for sophislicated user interaction. MOSl of the plotting needs can be
mel by the hi gh-I evel graphi cs functi ons available in MATLAB.
2. 2. 1 MATLAB Hi gh- Level Graphl cs Functl ons
τ 'h ere are three useful wi ndows duri ng a typical MATLAB scssion. The first is 白 e
MATLAB Command wi ndow through whi ch MATLAB recei ves instruction and di splays
al phanumeri c i nformati on. 百 le second wi ndow is the texl-editor wi ndow where
m- fiI es are coded. The third is the Fi gure wi ndow where the graphi c el ements are
di splayed. There can be more 白 anone figure wi ndow. The figure wi ndow is 出巴 targel
of the high-level graphi cs functions.
The graphi cs functi ons in MATLAB al l ow you to plot in 2 D or 3D. They al low
contour plots in 2 D and 3 D , mesh and su ば aωpl ots , bar , area , pie charts , hi
stograms ,
ani mati on , and gradi ent plots. Subplots can also be di splayed usi ng these functions.
In addi ti on they permi t operati on wi th i mages and 3 D model i ng. They allow basic
control of thc appear 阻 ce of the plot through color , line style , and markers , 蹴 is
ranges , and 鎚 pect ratio of the graph.τ 'h ey permi t annotati on of the graph in several
ways. Some of these functi ons will be used in the next section when we devcl op the m-file for
山 efirst exampl e. The followi ng i ntroduces some more useful I nform 姐 on
about the use of MATLAB ・ 8 high-I evcl graphi cs functions.
The two mai n graphi cal el ements 白紙 arc typically controlled usi ng the high-I evel
graphi cs functi ons are the figu 陀 and the axes. Usi ng Handl e Graphi cs you can control
most of the other graphi cal el ements , whi ch i nclude el em 巴 nts used in the G U I. These
other el ements are typically chi ldrcn of 山 e axes or fi gure. The fi gure functi on or
command creates a figure wi ndow wi th a number starting at one , or will creat 巴 anew
figure wi ndow i ncrementi ng the wi ndow count by one. Normal l y all graphi cs
functi ons are targeted to the c 町 rent figur 芭 wi ndow , whi ch is selected by clicking it
wi th the mouse or executi ng the command figure (number) , where number is the
number of the figure wi ndow 山 al will have lhe focus. A Il commands are i ssued in
command wi ndow. Graphi cs functi ons or commands will automati cally create a
wi ndow if none exists.
In voke hel p commandname at the MATLAB prompt to know more about the
functions or comrnands. The word handl e app 回 路 on m 加 y pla ぽ orms and in many
applications , particularly those that deal wi th graphics. They are wi del y prevalent in
object ・ ori ented programmi ng practice. M A TI . A B ・ s visualization system is object
oriented. Most graphi cal el ements are consi dered as objects. The “ handle" in M A TI . A B
is a sy 印 刷 oftware created number 白紙 can ident 汀 'y the specific graphi c obj ec t . If
this handl e is avai lable ,山 en properties of the obj ecl such as line size , marker type ,
color , and so on can be vi ewcd , set , or reset if neccssary. In MATLAB , Handl e Graphi
cs
is 出 e way to custorni ze 出 egraphi cal elements. In high-I evel gr 叩 hics functi ons 出 s
is used in a limited way. In this chapter , we will use it in a mi ni mal way to change 出 E
charactcristics of some of the graphi cal el ements on the figure.
To understand the concept of "handlcs" we will run 出 e followi ng code
interactively. It deals wi th creating a plot , whi ch was i ntroduced in Chapter 1. The
boldface comments in the code segment indicate the new fealures that are bei ng
emphasi zed.
Sta 武 MATLABand interactiveLy perform the followi ng:
> > X O: pi / 40: 2* pi ;
> > y X. 合 s i n (x) ;
>> pl ot ( x , y , ' b- ' ) ;
>> gr i d;
> > h pl ot ( x , y , ' b- ' ) 者 h i s t he handl e t o t he pl ot
> > 告 a new pl ot i s over wr i t t en i n t he same f i gur e wi ndow
> > 苦 a numer i cal val ue i s as s i gned t o h
> > 者 We can us e t he var i abl e name h or i t s val ue
> > 告 t o r ef er t o t he pl ot agai n
>>
>> set ( h , ' Li neWi dt h' , 2) ; も t hi s s houl d make your pl ot
> > 告 t hi cker bl ue
>> s et ( h , ' Li neWi dt h' , 3 , ' Li neSt yl e' ,' :', ' Col or' , ' r' )
> > 者 The handl e i s us ed t o r ef er t o t he obj ect
> > も whose pr oper t y i s bei ng changed
> > 者 Usual l y Pr oper t y i nf or mat i on occur s i n pai r s of
> > 者 pr oper t y- namej pr oper t y- val ue
> > も pr oper t y- val ue can be a t ext st r i ng or number
>>
> > get ( gca) も t hi s wi l l l i st t he pr oper t y of t he axes
> > 者 of t he cur r en 七 pl ot . Not e t her e ar e a si gni f i cant
> > 者 amount of pr oper t i es you can change t o cust omi ze
> > 者 t he appear ance of t he pl ot
>>
> > set ( gca , ' yti ck' , [-5 , ー 2. 5 , 0 , 2. 5 , 5] )
> > 告 you have r eset t he yt i ck mar ks on t he gr aph
> > set ( gca , ' FontName' ,' Ar i al ' , ' Font Wei ght ' , ...
> > ' bol d' , ' Font Si ze' , 14)
>>
> > 者 Changes t he f ont used f or mar ki ng t he axes
> > set ( gca , ' Xcol or' , ' bl ue' )
> > も changes t he x- axi s t o bl ue
> > % concl udes t he demonst r at i on of handl es
From the sessi on above it is evi dent 白紙 to fine-tune the plot you create , you
need to first identify the obj ect handle. You use the handl e to access 白 e obj ect
prop 凶 y. You change a property by setting its value. We will see more graphi cs
functi on as we obtai n the graphi cal solution to Exampl e 2.1 in 由巳 followi ng
sectlon.
2. 2. 2 Exampl e 2.1 ー- G raphi cal Sol uti on
Fi gure 2.1 is the graphi cal representati on of Exampl e 2.1. The range for the plots
matches the side constraints for the probl em. The intersection of the two equality
constraints identifies two possibl 巴 solutions to the probl em , approxi matel y (2.6 ,
2.8) and (1 , 6). The inequality constraint g2 makcs the poi nt (2.6 , 2.8)
unacceptable. Poi nt (1, 6) is acc 巴 ptable wi th respect to both constraints. Thc
soluti on is therefore at (1, 6). Whi l e the obj ecti ve functi on was not used to
determi ne thc solution , contours of the obj ecti ve functi on are drawn indicating 白巴
direction for 出 emi ni mum of the objecti v 巴 function. The solution can be identified
by i nspecti on of the ass 巴 mbl ed plots wi thout reference to the termi nol ogy or the
techni qucs of opti mi zati on. Recall , however. that this is onl y possi ble wi th one or
two desi gn variables in the probl em.
Th e code for 血 is ex 創 npl e i nvolves six m-files: a script m-fi le 白紙 will in c¥ ude
the MAT L AB statements to create and di splay 出 e data , and five m- fi 1 国一 one for
cach functi on i nvolved in Exampl e 2. 1. We begi n wi th the script m-fi l e-
Ex2_1. m.
File: Ex2 1. m
者 Chapt er 2: Opt i mi zat i on wi t h MATLAB
% Dr. P. Venkat ar aman
者 Exampl e 2_1 ( Sec 2. 1- 2. 2)

も gr aphi cal sol ut i on usi ng MATLAB ( two desi gn vari abl es)
毛 t he f ol l owi ng scr i pt shoul d al l ow t he di spl ay
苦 of gr aphi cal sol ut i on

も Mi ni mi ze f ( x1 , x2)
者 h1( x1 , x2)
者 h2( x1 , x2)
告 gl ( X1 , x2)
告 gl ( x1 , x2)

(x1 ・ 3) **2 + ( x2 ・ 2) **2
2x1 + x2 8
( x1- 1) ^2 + ( X2- 4) ^2 4
x1 + x2 < = 7
x 1 - 0. 25x2^2 < = 0. 0
% 0 < = x1 < = 10 0 < = x2 < = 10

も NOTE: The has h mar ks f or t he i nequal i t y
も const r ai nt s must be det er mi ned and dr awn out si de
者 of t hi s exer ci se and on t he pr i nt out
者ーーーーー- - - ・・白ーーーーーーーーーーー- - ーーーーーーーーーーーーーー" ・ー
・" ーーーーーー- -
x1=0: 0. 1: 10i 者 t he semi ・ col on at t he end pr event s
% t he echo
x2=0: 0. 1: 10i 者 t hese ar e al so t he si de const r ai nt s
者 x1 and x2 ar e vect or s f i l l ed wi t h number s st ar t i ng
苦 at 0 and endi ng at 10. 0 wi t h val ues at i nt erval s
告 of 0. 1
[X1 X2] meshgr i d( x1 , x2) i
者 gener at es mat r i ces X1 and X2 cor r espondi ng t o
% vect or s x1 and x2. I t i s a mes h of x1 and x2 val ues
者 at whi ch t he f unct i ons wi l l be eval uat ed
f 1 obj _exl ( X1 , X2) i 告 t he obj ect i ve f unct i on i s
者 eval uat ed over t he ent i r e mes h and st ored i n f 1
者 MATLAB wi l l comput e t he val ues f or t he obj ect i ve
も t hr ougha f unct i on m 田 f i l e cal l ed obj _exl . m
i neq1 i neconl ( Xl , X2) i 巷 t he i nequal i t y gl i s
者 eval uat ed over t he mes h
i neq2 i necon2( Xl , X2) i 者 t he i nequal i t y g2 i s
も eval uat ed over t he mes h
eq1 = eqcon1( Xl , X2) i 者 t he equal i t y h1 i s eval uat ed
者 over t he mes h
eq2 = eqco n 2 (X1 , X2) i 告 t he equal i t y h2 i s eval uat ed
者 over t he mesh
[C1 , han1] cont our ( χ1 , x 2 , i neq1 , [7 , 7) , ' r- ' ) i
も a si ngl e cont our pl ot of gl ( or i neql ) i s dr awn f or
者 t he val ue of 7 i n r ed col or as a cont i nuous l i ne
も dupl i cat i on of t he cont our val ue i s necessar y
も f or dr awi ng a si ngl e cont our
者 han1 i s t he handl e t o t hi s pl ot . Thi s handl e
者 can be us ed t o change t he pl ot di spl ay char act er i st i cs
告 Cl cont ai ns t he val ue of t he cont our
cl abel ( C1 , han1) i
も l abel s t he cont our wi t h t he val ues i n vect or C1
者 cont our( x1 , x2 , i neq1 , [ 7 , 7] , ' r- ' ) wi l l dr aw t he cont our
告 wi t hout l abel i ng t he val ue
hol d o n 告 al l ows mul t i pl e pl ot s i n t he same f i gur e
告 wi ndow
gt ext ( , gl ' ) i
も wi l l pl ace t he st r i ng ' gl ' on t he pl ot at t he spot
苦 sel ect ed by a mouse cl i ck. Thi s i s a t ext l abel
者 t hi s pr ocedur e i s r epeat ed f or r emai ni ng
も const r ai nt s
[C2 , han2] cont our ( x1 , x2 , i neq2 , [0 , 0] , ' r- ー , ) i
cl abel ( C2 , han2) i
gt ext ( ' g2' ) i
[C3 , han3] cont our ( x1 , x2 , eq1 , [8 , 8] , ' b- ' ) i
cl abel ( C3 , han3) i
gt ext ( , h1' ) i
[C4 , han4] cont our ( x1 , x2 , eq2 , [4 , 4] , ' b- - ' ) i
cl abel ( C4 , han4) i
gt ext ( , h2' ) i
[C , han] cont our ( x1 , x2 , f 1 , ' g' ) i
告 cont our of ' f' i s dr awn i n gr een col or. The number
苦 of cont our s ar e deci ded by t he def aul t val ue
cl abel (C , han) i
xl abel ( ' x1 val ues' , ' FontName' , ' ti mes' , ' FontSi ze' , 12 ,.
' Font Wei gh ヒ , , ' bol d' ) i も l abel f or x- axes
yl abel ( ' x2 val ues' , ' FontName' , ' ti mes' , ' FontSi ze' , 12 ,
' Font Wei ght ' , ' bol d' ) i
gr i d
hol d of f
The function m- fiI es are:
凪鑑 on1. m
f unct i on r et val i necon1( X1 , X2)
r et val X1 + X2i
も X1 , X2 ar e mat r i ces
者 r et val i s t he val ue bei ng r et ur ned af t er t he
告 comput at i on
者 Si nce X1 and X2 ar e mat r i ces r et va1 i s a1so a
告 mat r i x
者 By t hi s way t he ent i r e i nf or mat i on on t he mes h
者 i s gener at ed by a si ng1e cal l t o t he f unc ヒ i on
者 i necon1
凪血血 2 . m
f unct i on r et va1 i necon2( X1 , X2)
r et val Xl - 0. 2S* X2. ^2i
者 Not e t he us e of ^ oper at or f or el ement by e1ement
告 operat i on. That i s each e1ement of t he X2 mat r i x
者 i s squared. Wi t hout t he dot t he i mp1i cat i on i s a
者 mat r i x mul t i pl i cat i on - bet ween mat r i ces whose
者 i nner di mensi ons must agree. Si mi l ar oper at or s ar e
告 def i ned f or el ement by el ement mul ヒ i pl i cat i on
者 and di vi si on
盤 姐 Lm
f unct i on r et val eqcon1( X1 , X2)
r et val 2. 0* Xl + X2i
魁迎且 2 . m
f unct i on r et val eqcon2( X1 , X2)
r et val ( X1 - 1) . *( X1 ・ 1) + (X2 - 4) . * (X2 - 4) i
曲 U叫 掴
f unct i on r et val obj _ex1( X1 , X2)
r et val = (X1 - 3) . *( X1 - 3) +( X2 - 2) . 合 (X2 ・ 2) i
2. 2. 3 Di spl ayl ng the Graphi cs
A l 1 of lhc files required for graphical display of the probl em have been crcalcd. In the
Command wi ndow, lype addpatb followed by 出 ecompl el e path for thc directory 山 at
holds these files. At the prompt , type thc name of thc script file for the exampl e
wi thout the . m eXlensi on
>> E x 2 1

Th e first contour plot will appear. Move the mouse over to 白 e plot and a cross hair
appears. Cli cki ng on the plot w i1l plac 巴 the string "gl " at the cross hair. The second
contour plot should appear and there is a pause to plac 巴出 e text labe l . After the four
cons 住 aints , 出 eobj ecti ve functi on is plotted for several contour values. Finally the plot
shoul d app 伺 r ωi n Fi gure 2.1 wi thout the hash marks (and wi 山 your choi ce of 白 B
location for constraint labels). You can insert the hash marks through editing the plot
directly ( V ersion 5 .3 onw 釘 ds). 明記 solution for the probl em is at ( 1 , 6) , where four
plots intersec t . The value of the obj ective functi on is 20 鉱 山 esolution.
If the plot is acceptable , you can print the i nformali on on the figure by expo 凶 ngit
(usi ng an appropri ate extensi on) 10 a file and later i ncorporati ng it in another
documen t . You can also send it to 出 e printer from Ihe print command on the File
menu. Typi ng hel p pri nt in the Command wi ndow should I i st a set of commands you
can use to save 曲 efile.
>> pr i nt - depsc2 pl ot _ex_2_1. eps
w i1l c 路 ate the level 2 color postscript file called pl ocex_2_ l. eps in the worki ng
directory. A compl ete path name shoul d save the file to 白 e specified directory. You
can then execute standard operati ng system commands 10 dump the filc 10 出 e
applicabl 巴 printcr. You can also save the figure (ex 蜘 sion .fig) and later open it in
MATLAB usi ng the filc open command from menu b 釘 ortool bar.
2. 2. 4 Customl zl ng the Fl gure
In this section thc basic figure and plots creatcd abov 巴 w ilI be custorni zcd usi ng the
Handl e Graphi cs commands first explo 陀 di nS 巴 ction2.2. 1. All ofthe plots descri bi ng
白 e constraints will have a li newi dth of 2 points. 百 le objective functi on will have a
li newi dth of 1 poi n t . The text labels w i1l be in the "Ti mes" font. It w ilI be in boldface
wi th a font of size 14 and in 白 ecolor of the cons 回 in t . Th e x 叩 d Y tick marks will be
changed to establish a broader grid. Th e x 叩 d y lab e1 s will i nclude a subscri p t . A
two-row text w i1l be inserted at the poi nt selected through the mousc. The ncw figure
is shown in Fi gurc 2.2.
First ∞ py the file in 出 eprevi ous exerci se and rename i t.羽 lerenamed file will be
used ωmaket hen 配 essarych 佃 gesto 出 ecode. Th ese changes in c1 ude both new code
as we Il as repl acement of existing lines of code. In 出 e fo Il owi ng only 白 echanges to
出巴 code are i1I ustrated. Th e original code is shown in the italic style and identified
wi th three ellipsis points (. . .) at 出巴 begi nni ngof the line. The code to be inserted or
repl acement code is shown in norm 叫 styl 巴. If no replacemcnt is apparent , then the old
code is used 10 defi ne the locations whe 回 目 ew ∞ de is appended.
{ Cl , ha nl } c ont our ( x l , x 2 , i neql , { 7 , 7} , ' r - ' } ;
set ( han1 , ' Li neWi dt h' , 2) ; 者 set s 1i ne wi dt h of t he gl
も cont our t o 2 poi nt s
g t 儲 t ( ' gl ' ) ;
k1 gt e x t ( , gl ' ) ; 告 k1 i s t he handl e t o t he t ext el ement
set ( k1 , ' Font Name' , ' Ti mes' , ' Font Wei ght ' , ' bol d' ,
, Font Si ze' , 14 , ' Col or' , ' red' )
. . c l a bel ( C2 , ha n2} i
set ( han2 , ' Li neWi dt h' , 2)
k2 = gt ex t ( ' g2' ) ;
set ( k2 , ' Font Name' , ' Ti mes' , ' Font Wei ght ' , ' bol d' ,
, Font Si ze' , 14 , ' Col or' , ' red' )
c l a bel ( C3 , ha n3) ;
set ( han3 , ' Li neWi dt h' , 2)
k3 gt ex t ( ' h1' ) ;
set ( k3 , ' Font Name' , ' Ti mes' , ' Font Wei ght ' , ' bol d' ,
' Font Si ze' , 14 , ' Col or' , ' bl ue' )
c l a bel ( C4 , ha n4) ;
set ( han4 , , Li neWi dt h' , 2)
k4 gt ext ( ' h2' ) ;
set ( k4 , ' Font Name' , ' Ti mes' , ' Font Wei gh ヒ ' bo1d' ,
, Font Si ze' , 14 , ' Co1or' , ' b1ue' )
c: l abel (C , han) ;
set ( han , ' Li neWi dt h' , 1)
.. xl abel ( , x l val ues' , , FontName' , ' ti mes' ,
x1abe1( ' x 1 va1ues' , ' FontName' , ' ti mes' , , FontSi ze' , 12 ,.
, Font Wei ght ' , ' bo1d' ) i
y1abe1( ' x 2 val ues' , ' Font Name' , ' ti mes' ,'
Font Si ze' , 12 , ' Font Wei ght ' , ' bo1d' ) i
set ( gca , , xt i ck' , [0 2 4 6 8 10] ) 者 set xt i cks
s e ヒ ( gca , ' yti ck' , [0 2. 5 5. 0 7. 5 10] ) 昔 set yt i cks
k5 gt ext ( { ' Chapt er 2: Examp1e 1' ,
' pr et t y gr aphi cal di spl ay' } )
者 t he above gt ext descr i bes a st r i ng ar r ay
も st r i ng ar r ay i s def i ned usi ng cur l y br aces
set ( k5 , ' Font Name' , ' Ti mes' , ' Font Si ze' , 12 ,
, Font wei ght ' , ' bo1d' )
( at t he end)
c1ear C C1 C2 C3 C4 h h1 h2 h3 h4 k1 k2 k3 k4 k5
壱 get r i d of var i ab1es f r om t he wor kspace
Run the prograrn to sec 曲 e figure in Fi g 山 宮 2.2. Once the plot is custo mI z ed to your
satisfaction, you can make it 白巴 standardfor other plots you will pr 吋 U 四 i nMA 礼 As .
Thi s file coul d also be a template for general contour plotting. Note 白 at a 1 l function
i nformati on is obtai ned through function m- fiI es whi ch are coded outside the script
filc. Sctting up ncw probl ems or exampl cs only requires addi nglchangi ng new
function m- fi1 ω.
2. 3 ADDI TI ONAL EXAMPLES
Th e f0 1 l 0wi ng additional ex 創 nples will serve to iIl us 回 tebo 白 optimizationprobl ems 鎚
well as additional gmphi cal fcatures of M A TLA 白血 at will be useful in d 巴 velopinggraphical
solutions to optimization problems. 明 lC gr ョ phical routines in MATLAB are powerful 叩 d
回 SYto use. Th ey can gr ョ , phicallydisplay the probl ems 副 総 ve m1 ways wi 白 very si
mplc
∞ mm 阻 ds. Th e useful display is, however, detcnni ned by 血 euser. Th e first exampl e in
this section , Exampl e 2.2 , is a probl em in uncons 回 ined opt 泊前回 tion. 明記 second
cxampl e is a structu m1 engi neeri ng probl cm of reasonablc complcxi ty. 百 lC 白 凶 exar 即
Ic
demons 回 飽 s optimization in thc area of heat Ir ansfcr dcsign.
2.3.1 Exampl e 2. 2
Thi s cxampl c iII us 位置 tes scvcral diffcrent ways of gmphi caUy di splayi ng a function of
two variables. Th e probl em was uscd to iII uslrate global opti mi zati on in Reference 3.
Th e singlc objcctive function is
! (x I' X 2 ) cos(qx 2 ) -1- c + d
wi th
a = 1 , b = 2 , c = 0.3 , d = 0.4 , p = 3π , q = 4 π
(2.9)
Fi gurcs 2 .3 -2. 7 ar 宮山 e graphi cal display of solutions 泊 出 is section. The figures in
the book bei ng res 凶 ctedto black and whi te will not ∞ nvey 也 ei mpact of color i mages
you will see on the screen. Th cre are two files associatcd wi th the plots: the script
m- fiI e (ex2 .-2 . m) and thc functi on m- fiI e (obLex2. m) .
盟主. . z. m
者 Chapt er 2: Opt i mi zat i on wi t h MATLAB
者 Dr. P. Venkat ar aman
者 Examp1e 2. 2 Sec. 2. 3. 1

You might also like