Code Samples

Numerical Optimization

f[{x_,y_}]:=Exp[Sin[50 x]]+Sin[60 Exp[y]]+Sin[70 Sin[x]]+Sin[Sin[80 y]]-Sin[10 (x+y)]+1/4 (x^2+y^2)
FMin=FindMinimum[ f[{x,y}],{x, 0.0},{y,0.1}]

NMin=NMinimize[f[{x,y}],{x,y}]

What is this doing and why does it think this is an answer!

Df[{x_,y_}]=D[f[{x,y}],{{x,y}}]
DDf[{x_,y_}]=D[f[{x,y}],{{x,y},2}]

Val=f[{x,y}]/.NMin[[2]]
{px,py}={x,y}/.NMin[[2]]
Grad=Df[{x,y}]/.NMin[[2]]
Hess=DDf[{x,y}]/.NMin[[2]]

ϵ=3 (10^(-2));
{
ContourPlot[
 f[{x,y}],
{x,(1-ϵ) px, (1+ϵ) px}, {y, (1-ϵ) py, (1+ϵ) py},
Epilog->{Red, PointSize[0.02],Point[{px,py}]}
],
ContourPlot[
 Val+(1/2)({x,y}-{px,py}).Hess.({x,y}-{px,py}),
{x,(1-ϵ) px, (1+ϵ) px}, {y, (1-ϵ) py, (1+ϵ) py},
Epilog->{Red, PointSize[0.02],Point[{px,py}]}
]}

Eigenvalues[Hess]

NMin=NMinimize[f[{x,y}],{x,y},
Method->{"RandomSearch","SearchPoints"->250}
]

Solving Equations

g[x_]=  -(((x-1))^2) (((x-(1/2)))^2) (((x-(1/3)))^2)
Plot[g[x],{x, 0.2,1}]

NewtonStep[x_]:= x - ((g'[x])/(g''[x]))
xx=0.8;
Table[
xx=NewtonStep[xx],
{12}]

xx=0.4;
Table[
xx=NewtonStep[xx],
{12}]

BisectionStep[{xLow_,xHigh_}]:= Module[
{xNew=((xLow+xHigh)/2)},
If[ 
g'[xLow] g'[xNew]≤0, 
{xLow,xNew},
{xNew, xHigh}
]
]
xx={xxLow, xxHigh}= {0.7,0.9};
g'[xx]
Table[
xx=BisectionStep[xx],
{12}]