MATLAB: analyticoptsymbolic477
← ChE 477: Process Optimization
close all
clear all
clc
% SYMBOLIC COMPUTATIONS FOR ANALYTICAL OPTIMIZATION
% Example
% copyright © 2000 by Paul Green and Jonathan Rosenberg
% minor modifications by Ugur Akman
% A three dimensional example.
syms x y z;
g=x^3+y^3+z^3+x^2+y^2+z^2+4*x*y+5*y*z
% The MATLAB function "jacobian" will be used to compute both the gradient
% and the Hessian of g as functions of the variables.
gradg=jacobian(g,[x,y,z])
hessg=jacobian(gradg,[x,y,z])
% Note: If, at this step, the Hessian is constant then you do not need
% to use the "solve" command to find the stationary points for
% classification of the function. You may directly go to the computation of
% the eigenvalues.
% g clearly has a critical point at the origin; let us see if we can find
% another. The arguments of MATLAB's solve command are functions that are
% to be set to 0, in this case the three components of the gradient of g.
% Solve will accept additional arguments specifying the variables to be
% solved for, but in this case they are not necessary because MATLAB simply
% assumes it is supposed to solve the three equations for the three
% variables. The following "double" command displays the solutions in an
% easily readable form. (Try it with simply [xc,yc,zc] after the semi-colon
% to see what double accomplishes here.)
[xc,yc,zc]=solve(gradg(1),gradg(2),gradg(3));double([xc,yc,zc])
% Note: Since the gradiets are quadratic equations the "solve" command were
% able to find all the solutions (roots), real & complex. For cases where
% the gradient functions are not polynomials, the roots will depend on the
% initial guess of the "solve" algorithm.
% We see from the output that g has four real critical points. We now
% select the four real ones and name them crit1 through crit4.
% Note that select the real solutions (disregard the complex ones)
% On my machine, the solve statement above gave the 1st, 2nd, 5th, and 6th
% components as real.
crits=[xc,yc,zc];
crit1=double(crits(1,1:3))
crit2=double(crits(2,1:3))
crit3=double(crits(5,1:3))
crit4=double(crits(6,1:3))
% Now we proceed to classify the critical points.
% Use the "subs" coammand to substitute the critical (stationary) points to
% evaluate the Hessian at those points.
hess1=subs(hessg,[x,y,z],crit1)
eig(hess1)
% The critical point at the origin is a cone (saddle) point.
hess2=subs(hessg,[x,y,z],crit2)
eig(hess2)
% Another cone (saddle) point.
hess3=subs(hessg,[x,y,z],crit3)
eig(hess3)
% Another cone (saddle) point.
hess4=subs(hessg,[x,y,z],crit4)
eig(hess4)
% This is a local maximum.
g =
x^3+y^3+z^3+x^2+y^2+z^2+4*x*y+5*y*z
gradg =
[ 3*x^2+2*x+4*y, 3*y^2+2*y+4*x+5*z, 3*z^2+2*z+5*y]
hessg =
[ 6*x+2, 4, 0]
[ 4, 6*y+2, 5]
[ 0, 5, 6*z+2]
ans =
Columns 1 through 2
0 0
1.21675274346428 -1.71874180077804
0.54215481157050 + 1.35565057350059i 0.88681507250733 - 1.78028400859777i
-0.51055655173971 + 0.92892034501451i 0.70694703701300 + 0.24693937977994i
-1.55074391583310 -1.02823306145348
-2.39587201395944 -3.10721602347581
-0.51055655173971 - 0.92892034501451i 0.70694703701300 - 0.24693937977994i
0.54215481157050 - 1.35565057350059i 0.88681507250733 + 1.78028400859777i
Column 3
0
-2.05834950110525
0.64133222880632 + 1.52213237524055i
-0.13761060692665 - 1.05139970335229i
1.01753042004827
-2.63329082936903
-0.13761060692665 + 1.05139970335229i
0.64133222880632 - 1.52213237524055i
crit1 =
0 0 0
crit2 =
1.21675274346428 -1.71874180077804 -2.05834950110525
crit3 =
-1.55074391583310 -1.02823306145348 1.01753042004827
crit4 =
-2.39587201395944 -3.10721602347581 -2.63329082936903
hess1 =
2 4 0
4 2 5
0 5 2
ans =
-4.40312423743285
2.00000000000000
8.40312423743285
hess2 =
9.30051646078570 4.00000000000000 0
4.00000000000000 -8.31245080466822 5.00000000000000
0 5.00000000000000 -10.35009700663149
ans =
-14.71123711031647
-4.87501480637114
10.22422056617359
hess3 =
-7.30446349499859 4.00000000000000 0
4.00000000000000 -4.16939836872088 5.00000000000000
0 5.00000000000000 8.10518252028964
ans =
-10.50762482719680
-2.85472380612339
9.99366928989037
hess4 =
-12.37523208375661 4.00000000000000 0
4.00000000000000 -16.64329614085488 5.00000000000000
0 5.00000000000000 -13.79974497621419
ans =
-21.58923579446277
-12.97539991348116
-8.25363749288175
Published with MATLAB® 7.0