Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % use meshgrid to create a rectangular grid
- [x,y]=meshgrid(-2:.2:2,-1.8:.2:1.8);
- % compute function values at the points of the grid
- % dest - z=x.*exp(-x.^2-y.^2);
- z = sin(x.^2 + 3 * y.^2 + 1) / (x.^2 + 3 * y.^2 + 1);
- % compute gradients
- % dx – partial derivative in respect of x; dy – partial derivative in respect of y
- [dx,dy]=gradient(z);
- % plot contourlines
- contour(x,y,z)
- % the next plot will be constructed on top of the existing figure
- hold on
- % plot gradients
- quiver(x,y,dx,dy)
- % finish drawing
- hold off
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement