f[x_, y_] := 2 - x^2 - y^2
graf = 
      Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2}, 
        BoxRatios -> {1, 1, 1}]

D[f[x, y], x]
D[f[x, y], y]
D[f[x, y], {x, 2}]
D[f[x, y], {y, 2}]
D[D[f[x, y], x], y]
D[D[f[x, y], y], x]

f[x_, y_] := x^3  y - y^4 x^2
graf = 
      Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2}, 
        BoxRatios -> {1, 1, 1}]
D[f[x, y], x]
D[f[x, y], y]
D[f[x, y], {x, 2}]
D[f[x, y], {y, 2}]
D[D[f[x, y], x], y]
D[D[f[x, y], y], x]

f[x_, y_] := 2 - x^2 - y^2
graf = 
      Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2}, 
        BoxRatios -> {1, 1, 1}]
rov1 = 
      ParametricPlot3D[{x, 0, z}, {x, -2, 2}, {z, 
          2, -5}]
rov2 = 
      ParametricPlot3D[{0, y, z}, {y, -2, 2}, {z, 
          2, -5}]
Show[graf, rov1]
Show[graf, rov2]

f[x_, y_] := 2 - x^2 - y^2
prvydiferencial[f_, a_, 
        b_] := (D[f[x, y], x] /. {x -> a, y -> b})*(x - 
              a)  +  (D[f[x, y], y] /. {x -> a, 
                y -> b})*(y - b)

Plot3D[
      Evaluate[prvydiferencial[f, 0, 0]], {x, -2, 2}, {y, -2, 
        2}]
Plot3D[
      Evaluate[prvydiferencial[f, 1, 1]], {x, -2, 2}, {y, -2, 
        2}]
Plot3D[
      Evaluate[prvydiferencial[f, -1, 0]], {x, -2, 2}, {y, -2, 
        2}]

dotykovarovina[f_, a_, b_] := 
      f[a, b] + prvydiferencial[f, a, b]

dotyk = 
      Plot3D[Evaluate[dotykovarovina[f, 0, 0]], {x, -2, 2}, {y, -2, 
          2}]
Show[graf, dotyk]

dotyk = 
      Plot3D[Evaluate[dotykovarovina[f, 0, 2]], {x, -2, 2}, {y, -2, 
          2}]
Show[graf, dotyk]

normalovyvektor[f_, a_, 
        b_] := {{a, b, 
          f[a, b]}, -{D[f[x, y], x] /. {x -> a, y -> b}, 
            D[f[x, y], y] /. {x -> a, 
                y -> b}, -1}}

<< Graphics`PlotField3D`

sipka = 
        ListPlotVectorField3D[{normalovyvektor[f, 0, 0]}, 
          VectorHeads -> True, ColorFunction -> Hue, 
          DisplayFunction -> Identity];
Show[graf, sipka]

normalovyvektor[f, 0.1, -0.1]

sipka = 
        ListPlotVectorField3D[{normalovyvektor[f, 0.5, -0.2]}, 
          VectorHeads -> True, ColorFunction -> Hue, 
          DisplayFunction -> Identity];
Show[graf, sipka, ViewPoint -> {1.046,  -2.407,  0.637}, 
      BoxRatios -> Automatic]

grad[f_, a_, b_] := {D[f[x, y], x] /. {x -> a, y -> b}, 
        D[f[x, y], y] /. {x -> a, y -> b}}

a = grad[f, 0, 0]
Norm[a]
b = grad[f, 0.1, -0.1]
Norm[b]
c = grad[f, -0.2, -0.2]
Norm[c]

Needs["Graphics`ImplicitPlot`"]

g1 = 
      ImplicitPlot[
        Table[f[x, y] == c, {c, 0, 2, 0.25}], {x, -2, 
          2}, {y, -2, 2}, PlotPoints -> 50, 
        PlotRange -> All]

<< Graphics`Arrow`

a = 0.5; b = 0;
s1 = 
        Graphics[{RGBColor[1, 0, 0], 
            Arrow[{a, b}, {a + grad[f, a, b][[1]], 
                b + grad[f, a, 
                      b][[2]]}]}];
Show[g1, s1]

a = 1/Sqrt[2]; b = 1/Sqrt[2];
s1 = 
        Graphics[{RGBColor[1, 0, 0], 
            Arrow[{a, b}, {a + grad[f, a, b][[1]], 
                b + grad[f, a, 
                      b][[2]]}]}];
Show[g1, s1]

a = 1/Sqrt[2]; b = 1/Sqrt[2];
s1 = 
        Graphics[{RGBColor[1, 0, 0], 
            Arrow[{a, b}, {a - grad[f, a, b][[1]], 
                b - grad[f, a, 
                      b][[2]]}]}];
Show[g1, s1]

derivaciavsmere[f_, a_, b_, e_] := grad[f, a, b] . e

e = {1, 0};
dvs = derivaciavsmere[f, a, b, e]

a = 1/Sqrt[2]; b = 1/Sqrt[2];
e = {1, 0.2}
dvs = derivaciavsmere[f, a, b, e];
s1 = 
        Graphics[{RGBColor[1, 0, 0], 
            Arrow[{a, b}, {a + grad[f, a, b][[1]], 
                b + grad[f, a, 
                      b][[2]]}]}];
s2 = 
        Graphics[{RGBColor[0, 1, 0], 
            Arrow[{a, b}, {a + dvs *e[[1]], 
                b + dvs*e[[2]]}]}];
Show[g1, s1, s2]

f[x_, y_] := -1 + 
        Sqrt[x^2 + y^2]/(0.6 + 0.4 Sin[4 ArcTan[y/x]])

graf = 
      Plot3D[f[x, y], {x, -1, 1}, {y, -1, 1}, 
        BoxRatios -> {1, 1, 1}, PlotPoints -> 50]

g1 = 
      ImplicitPlot[
        Table[f[x, y] == c, {c, -1, 1, 0.1}], {x, -2, 
          2}, {y, -2, 2}, PlotPoints -> 50, 
        PlotRange -> All]

a = 1.5; b = 0.6;
s1 = 
        Graphics[{RGBColor[1, 0, 0], 
            Arrow[{a, 
                b}, {a + grad[f, a, b][[1]]/Norm[grad[f, a, b]], 
                b + grad[f, a, b][[2]]/
                    Norm[grad[f, a, b]]}]}];
Show[g1, s1]

a = 0.1; b = -0.5;
s1 = 
        Graphics[{RGBColor[1, 0, 0], 
            Arrow[{a, 
                b}, {a + grad[f, a, b][[1]]/Norm[grad[f, a, b]], 
                b + grad[f, a, b][[2]]/
                    Norm[grad[f, a, b]]}]}];
Show[g1, s1]

a = -0.45; b = 1;
s1 = 
        Graphics[{RGBColor[1, 0, 0], 
            Arrow[{a, 
                b}, {a + grad[f, a, b][[1]]/Norm[grad[f, a, b]], 
                b + grad[f, a, b][[2]]/
                    Norm[grad[f, a, b]]}]}];
Show[g1, s1]

f[x_, 
        y_] := -1 + (x - 1)^2 + (y + 
              2)^2
graf = 
      Plot3D[f[x, y], {x, -3, 5}, {y, -5, 1}, 
        BoxRatios -> {1, 1, 1}, PlotPoints -> 50]

Clear[a, b]

stacbod = 
      Solve[{D[f[x, y], x] == 0, D[f[x, y], y] == 0}, {x, 
          y}]

a = x /. stacbod[[1]]
b = y /. stacbod[[1]]
D[D[f[x, y], x], x]
D[D[f[x, y], x], x] /. {x -> a, y -> b}

Matica[a_, 
        b_] := {{D[D[f[x, y], x], x] /. {x -> a, y -> b}, 
          D[D[f[x, y], x], y] /. {x -> a, 
              y -> b}}, 
{D[D[f[x, y], y], 
              x] /. {x -> a, y -> b}, 
          D[D[f[x, y], y], y] /. {x -> a, y -> b}}}

Matica[a, b]

Det[Matica[a, b]]

f[x_, y_] := 
      1 - (x - 1)^2 - (y + 2)^2
graf = 
      Plot3D[f[x, y], {x, -3, 5}, {y, -5, 1}, 
        BoxRatios -> {1, 1, 1}, 
        PlotPoints -> 50]
stacbod = 
      Solve[{D[f[x, y], x] == 0, D[f[x, y], y] == 0}, {x, 
          y}]
a = x /. stacbod[[1]]
b = y /. stacbod[[1]]
Matica[a_, 
        b_] := {{D[D[f[x, y], x], x] /. {x -> a, y -> b}, 
          D[D[f[x, y], x], y] /. {x -> a, 
              y -> b}}, 
{D[D[f[x, y], y], 
              x] /. {x -> a, y -> b}, 
          D[D[f[x, y], y], y] /. {x -> a, 
              y -> b}}}
Matica[a, b]
Det[Matica[a, b]]

f[x_, y_] := x^3 + y^2 + x*y - x^2
graf = 
      Plot3D[f[x, y], {x, -1, 2}, {y, -2, 1}, 
        BoxRatios -> {1, 1, 1}, 
        PlotPoints -> 50]
stacbod = 
      Solve[{D[f[x, y], x] == 0, D[f[x, y], y] == 0}, {x, 
          y}]
a = x /. (stacbod[[1]])
b = y /. (stacbod[[1]])
Matica[a_, 
        b_] := {{D[D[f[x, y], x], x] /. {x -> a, y -> b}, 
          D[D[f[x, y], x], y] /. {x -> a, 
              y -> b}}, 
{D[D[f[x, y], y], 
              x] /. {x -> a, y -> b}, 
          D[D[f[x, y], y], y] /. {x -> a, 
              y -> b}}}
Matica[a, b]
Det[Matica[a, b]]

f[x_, y_] := x^3 + y^2 + x*y - x^2
graf = 
      Plot3D[f[x, y], {x, -1, 2}, {y, -2, 1}, 
        BoxRatios -> {1, 1, 1}, 
        PlotPoints -> 50]
stacbod = 
      Solve[{D[f[x, y], x] == 0, D[f[x, y], y] == 0}, {x, 
          y}]
a = x /. (stacbod[[2]])
b = y /. (stacbod[[2]])
Matica[a_, 
        b_] := {{D[D[f[x, y], x], x] /. {x -> a, y -> b}, 
          D[D[f[x, y], x], y] /. {x -> a, 
              y -> b}}, 
{D[D[f[x, y], y], 
              x] /. {x -> a, y -> b}, 
          D[D[f[x, y], y], y] /. {x -> a, 
              y -> b}}}
Matica[a, b]
Det[Matica[a, b]]