Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.52 KB | None | 0 0
  1. % use meshgrid to create a rectangular grid
  2. [x,y]=meshgrid(-2:.2:2,-1.8:.2:1.8);
  3. % compute function values at the points of the grid
  4. % dest - z=x.*exp(-x.^2-y.^2);
  5. z = sin(x.^2 + 3 * y.^2 + 1) / (x.^2 + 3 * y.^2 + 1);
  6. % compute gradients
  7. % dx – partial derivative in respect of x; dy – partial derivative in respect of y
  8. [dx,dy]=gradient(z);
  9. % plot contourlines
  10. contour(x,y,z)
  11. % the next plot will be constructed on top of the existing figure
  12. hold on
  13. % plot gradients
  14. quiver(x,y,dx,dy)
  15. % finish drawing
  16. hold off
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement