I am attempting to create a tool to visualize gradient, eigenvector, and eigenvalue information for a 2D surface. I want to show a contour plot of an inputted function and overlay the gradient and eigenvectors based at a point selected by a Locator. The problem is when I move the Locator point the contour plot redraws -- which is slow. So I'd like for the gradient and eigenvector information to change but the contour plot to stay (unless the function is changed).
Manipulate[
Module[{},
p1 = ContourPlot[expr /. {x -> x, y -> y}, {x, -5, 5}, {y, -5, 5}, Contours -> 20];
grad = D[expr, {{x, y}}];
ngrad = grad /. {x -> Dynamic[pt[[1]]], y -> Dynamic[pt[[2]]]} ;
p2 = Graphics[{Red, Arrow[{pt, pt + ngrad}]}];
Show[p1, p2]
],
{{pt, {1, 1}}, {-5, -5}, {5, 5}, Locator},
{{expr, 2*x*Cos[y] - x*y + 10, "f(x,y)"}, InputField},
{locx, pt[[1]], InputField},
{locy, pt[[2]], InputField},
{locval, expr /. {x -> pt[[1]], y -> pt[[2]]}, InputField}]
I expect this can be done using Dynamic, but everything I've tried so far has not worked. Any help would be greatly appreciated.