MATLAB: How to use the Meshgrid and surf functions

MATLABmeshgridsurf

I need to create a script that uses the meshgrid and surf functions to generate a 3-D surface plot of the function z = cos(sqrt(x^2 + y^2)) in the domain −7 ≤ x ≤ 7 and −7 ≤ y ≤ 7 (use a step size of 0.1). How would you do this?

Best Answer

v = -7:0.1:7;
[x, y] = meshgrid(v, v);
z = cos(sqrt(x.^2 + y.^2));
surf(x, y, z, 'edgecolor', 'none')
Related Question