\(\(\(
\)\( (*Definicia\ stylov\ popisov\ a\ fontov*) \)\(\($TextStyle = {FontFamily -> "Helvetica", FontSize -> 12, 
          FontWeight -> "Bold"};\)



    \(<< Statistics`ContinuousDistributions`;\)

    \)\)\)

n = 2;
\(f[x_] := \((\((x[\([\)\(1\)\(]\)] - 1)\)^2\ \  + 
            2\ 25 \((1 + \ 
                  Sin[x[\([\)\(1\)\(]\)]])\))\)*\ \((\((x[\([\)\(2\)\(]\)] - 
                  1)\)^2\ \  + 
            3\ 25 \((1 + \ 
                  Sin[x[\([\)\(2\)\(]\)]])\))\); 

\)
Plot3D[f[{x1, x2}],  {x1, -10, 23},  {x2, -20, 23},  
      PlotPoints -> 200, 
Mesh -> 
        False, 
ImageSize -> 
        6*72]; 

DensityPlot[
        f[{x1, x2}],  {x1, -10, 23},  {x2, -20, 
          23}, 
PlotPoints -> 
          200, 
ColorFunction -> Hue,  
        Mesh -> False, 
ImageSize -> 
          6*72];
grafcontour = 
        ContourPlot[
          f[{x1, x2}],  {x1, -10, 23},  {x2, -20, 
            23}, 
PlotPoints -> 
            200, 
Contours -> 
            Table[k^3, {k, 0, 50, 
                1.5}], 
ColorFunction -> 
            Hue, 
ImageSize -> 6*72];

(* 
      Startovaci bod pre vsetky metody *) 

xstart = {20. , 20. };

\(\(\(
\)\( (*\ 
      Algoritmus\ Newton - 
        Kantorovica\ na\ minimalizaciu\ funckie\ *) \)\(
\)\(
\)\(\(out = 
        FindMinimum[
          f[{x1, x2}], \ {x1, xstart[\([\)\(1\)\(]\)]}, {x2, 
            xstart[\([\)\(2\)\(]\)]}];\)


    \(x = {x1 /. out[\([\)\(2\)\(]\)], 
          x2 /. out[\([\)\(2\)\(]\)]};\)


    \(Print["  x =", \ x, \ " f(x) = ", \ 
        f[x]];\)


    \(alfa = f[x]/f[xstart];\)

    \(Print["  Redukcia alfa =", 
        alfa];\)


    \(grafmin = 
        Graphics[{{PointSize[ .02], RGBColor[1, 1, 1], 
              Text["minimum", \ {x[\([\)\(1\)\(]\)], 
                  x[\([\)\(2\)\(]\)] - 2}, \ 
                TextStyle -> {FontFamily -> "Helvetica", 
                    FontWeight -> "Bold", 
                    FontSize -> 16}]}, {PointSize[ .02], 
              RGBColor[1, 1, 1], Point[xstart]}, \ {PointSize[ .02], 
              RGBColor[1, 1, 1], 
              Text["start", \ {xstart[\([\)\(1\)\(]\)], 
                  xstart[\([\)\(2\)\(]\)] - 2}, \ 
                TextStyle -> {FontFamily -> "Helvetica", 
                    FontWeight -> "Bold", 
                    FontSize -> 16}]}, {PointSize[ .02], 
              RGBColor[1, 1, 1], 
              Point[x]}}
];\)

    \(Show[grafcontour, grafmin];\)\)\)\)

\(\(\( (*\ 
      Jednoduchy\ algoritmus\ stochastickej\ optimalizacie\ *) \)\(
\)\(
\)\( (*\ 
      Pocet\ iteracii\ pri\ danej\ teplote, \ 
      sigma\ perturbacii*) \)\(
\)\(
\)\(\(Nmax = 500;\)

    \(sigma = 2;\)



    \(dist = NormalDistribution[0, sigma];\)


    \(x = xstart;\)


    \(For[i = 1, \ i ≤ Nmax, 
        1, 
{
xnew = 
            x + Table[Random[dist], {j, 1, n}]; 
If[
            f[xnew] < f[x]\ , \ 
x = 
              xnew
, \ \ \ 
 (*\ 
              Nic\ *) \ ]; 

\(i++\);}];\)


    \(Print["  x =", \ x, \ " f(x) = ", \ 
        f[x]];\)


    \(alfa = f[x]/f[xstart];\)

    \(Print["  Redukcia alfa =", 
        alfa];\)


    \(grafmin = 
        Graphics[{{PointSize[ .02], RGBColor[1, 1, 1], 
              Text["minimum", \ {x[\([\)\(1\)\(]\)], 
                  x[\([\)\(2\)\(]\)] - 2}, \ 
                TextStyle -> {FontFamily -> "Helvetica", 
                    FontWeight -> "Bold", 
                    FontSize -> 16}]}, {PointSize[ .02], 
              RGBColor[1, 1, 1], Point[xstart]}, \ {PointSize[ .02], 
              RGBColor[1, 1, 1], 
              Text["start", \ {xstart[\([\)\(1\)\(]\)], 
                  xstart[\([\)\(2\)\(]\)] - 2}, \ 
                TextStyle -> {FontFamily -> "Helvetica", 
                    FontWeight -> "Bold", 
                    FontSize -> 16}]}, {PointSize[ .02], 
              RGBColor[1, 1, 1], 
              Point[x]}}
];\)



    \(Show[grafcontour, grafmin];\)

    \)\)\)

\(\(\(
\)\(
\)\( (*\ 
      ALGORITMUS\ SIMULOVANEHO\ ZIHANIA\ *) \)\(
\)\(
\)\( (*\ Boltzmanova\ konstatnta\ *) \)\(
\)\(\(k = 
        1;\)

 (*\ Pocet\ iteracii\ pri\ danej\ teplote, \ 
      sigma\ perturbacii*) 

    \(Nmax = 50;\)

    \(sigma = 2;\)

 (*\ 
      Rychlost\ ochladzovania\ teploty\ systemu\ T\  < \(-\ theta\)*
          T\ \ *) 

    \(theta = 0.95;\)

 (*\ 
      Startovacia\ teplota\ a\ teplota\ zatuhnutia\ systemu\ *) 

    \(Tstart = f[xstart];\)

    \(Tmin = 0.001;\)




    \(dist = NormalDistribution[0, sigma];\)


    \(x = xstart;\)


    \(xlist = {x};\)


    \(For[T = Tstart, \ 
        T ≥ 
          Tmin, \ , 
{
For[i = 1, \ 
            i ≤ Nmax, 
            1, 
{

xnew = x + Table[Random[dist], \ {j, 1, 
                      n}]; 

If[
                f[xnew] < f[x]\  || \ 
                  Random[] < Exp[\(-\((f[xnew] - f[x]\ )\)\)/\((k*T)\)], \ 
                x = xnew, \ \ \ \ ]; 

\(i++\); }]; 

xlist = 
            Join[xlist, {x}]; 

T = 
            theta*T; 
}];\)



    \(Print["  x =", \ x, \ " f(x) = ", \ 
        f[x]];\)


    \(alfa = f[x]/f[xstart];\)

    \(Print["  Redukcia alfa =", 
        alfa];\)


    \(grafmin = 
        Graphics[{{PointSize[ .02], RGBColor[1, 1, 1], 
              Text["minimum", \ {x[\([\)\(1\)\(]\)], 
                  x[\([\)\(2\)\(]\)] - 2}, \ 
                TextStyle -> {FontFamily -> "Helvetica", 
                    FontWeight -> "Bold", 
                    FontSize -> 16}]}, {PointSize[ .02], 
              RGBColor[1, 1, 1], Point[xstart]}, \ {PointSize[ .02], 
              RGBColor[1, 1, 1], 
              Text["start", \ {xstart[\([\)\(1\)\(]\)], 
                  xstart[\([\)\(2\)\(]\)] - 2}, \ 
                TextStyle -> {FontFamily -> "Helvetica", 
                    FontWeight -> "Bold", 
                    FontSize -> 16}]}, {PointSize[ .02], 
              RGBColor[1, 1, 1], 
              Point[x]}}
];\)


    \(grafdraha = 
        ListPlot[xlist, \ 
PlotJoined -> True, \ 
          PlotStyle -> 
            RGBColor[1, 1, 1], \ 
DisplayFunction -> 
            Identity];\)


    \(Show[grafcontour, grafmin];\)

    \(Show[grafcontour, grafmin, grafdraha];\)\)\)\)