Skip to content

Instantly share code, notes, and snippets.

@cshjin
Created September 9, 2017 21:32
Show Gist options
  • Save cshjin/cf4d98c8ed473dda64f5cfd3d1645e78 to your computer and use it in GitHub Desktop.
Save cshjin/cf4d98c8ed473dda64f5cfd3d1645e78 to your computer and use it in GitHub Desktop.
Saddle point example
v = -5:0.5:5;
[x, y] = meshgrid(v);
z = x .* exp(x.^2 - y.^2) + y.*exp(-x.^2 + y.^2);
[px, py] = gradient(z);
figure
surf(x, y, z)
figure
contour(x, y, z);
hold on
quiver(x, y, px, py);
hold off
v = -5:0.5:5;
[x, y] = meshgrid(v);
z = (x.^2 - y.^2);
[px, py] = gradient(z);
figure
surf(x, y, z);
% hold on
% quiver3(x, y, px, py);
% hold off
figure
contour(x, y, z);
hold on
quiver(x, y, px, py);
hold off
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment