



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




2
In[1]:= Needs@"OptimizationToolbox‘Unconstrained‘"D;
General::obspkg : LinearAlgebra‘MatrixManipulation‘ is now obsolete. The legacy version being loaded may conflict with current Mathematica functionality. See the Compatibility Guide for updating information. á
General::newpkg : NumericalMath‘NLimit‘ is now available as the Numerical Calculus Package. See the Compatibility Guide for updating information. á
SetDelayed::write : Tag Norm in Norm@v_D is Protected. á
SetDelayed::write : Tag Hessian in Hessian@f_List, vars_D is Protected. á
SetDelayed::write : Tag Hessian in Hessian@f_, vars_D is Protected. á
General::stop : Further output of SetDelayed::write will be suppressed during this calculation. á
In[2]:=? SteepestDescent
SteepestDescent@f, vars, x0, optsD. Computes a minimum of fHvarsL starting from x0 using the steepest descent method. The step length is computed using analytical line search. See Options@SteepestDescentD to see a list of options for the function. The function returns 8 x, hist<. x is either the optimum point or the next point after MaxIterations. hist contains history of values tried at different iterations.
In[3]:=? PlotSearchPath
PlotSearchPath@f, 8 x1, x1min, x1max<, 8 x2, x2min, x2max<, hist, optsD shows complete search path superimposed on a contour plot of the function f over the specified range. hist is assumed to be of the form 8 pt1, pt2, º<, where pt1 = 8 x1,x2< is the first point, etc. The function accepts all relevant options of the standard ContourPlot and the Graphics functions.
In[4]:= f^ =^ Hx^ +^ yL^ ^ 2^ +^ H^2 *****^ Hx ^ 2^ +^ y ^ 2^ -^1 L^ -^1 ê^3 L^ ^ 2; vars = 8 x, y<; x0 = 8 - 1.25, 0.25<;
In[6]:=^8 opt,^ hist<^ =^ SteepestDescent@f,^ vars,^ x0D;
f Æ Hx + yL^2 + I- ÄÄÄ^13 + 2 I- 1 + x^2 + y^2 MM
2
—f Æ
2 x - ÄÄÄÄÄÄÄÄ^ 50 y 3 + 16 x^2 y + 16 y^3
Optimum: 8 - 0.764703, 0.762588< after 27 iterations
In[7]:= xhist = Drop@Transpose@histD@@ 1 DD, 1D; PlotSearchPath@f, 8 x, - 1.4, - 0.5<, 8 y, 0, 1<, xhistD
Out[8]=
f Æ Hx + yL^2 + I- ÄÄÄ 1 3 +^2 I-^1 +^ x
(^2) + y (^2) MM^2
—f Æ
50 x 3 +^ 16 x
(^3) + 2 y + 16 x y 2
2 x - ÄÄÄÄÄÄÄÄ 50 y 3 +^ 16 x
(^2) y + 16 y 3
Optimum: 8 0.764703, - 0.762588< after 27 iterations
Out[13]=
0
1
2
x
y
2
2
In[14]:= f^ =^ Hx^ +^ yL^ ^ 2^ +^ H^2 *****^ Hx ^ 2^ +^ y ^ 2^ -^1 L^ -^1 ê^3 L^ ^ 2; vars = 8 x, y<; x0 = 8 - 1.25, 0.25<; 8 opt, hist< = ConjugateGradient@f, vars, x0D; xhist = Drop@Transpose@histD@@ 1 DD, 1D; PlotSearchPath@f, 8 x, - 1.4, - 0.5<, 8 y, 0, 1<, xhistD
f Æ Hx + yL^2 + I- ÄÄÄ 1 3 +^2 I-^1 +^ x
(^2) + y (^2) MM^2
—f Æ
50 x 3 +^ 16 x
(^3) + 2 y + 16 x y 2
2 x - ÄÄÄÄÄÄÄÄ 50 y 3 +^ 16 x
(^2) y + 16 y 3
Using the PolakRibiere method with Analytical line search
Optimum: 8 - 0.763759, 0.763766< after 6 iterations
Out[18]=
Using the Package provided by Mathematica
In[19]:= << Utilities‘CleanSlate‘ CleanSlate@D;
HCleanSlateL Contexts purged: 8 Global‘<
HCleanSlateL Approximate kernel memory recovered: 472 Kb