Challenge - 5 Problems
Surface Plot Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of mesh and surf with sine wave
What is the output of the following MATLAB code snippet that uses
mesh and surf to plot a sine wave surface?MATLAB
x = linspace(-2*pi, 2*pi, 30); y = linspace(-2*pi, 2*pi, 30); [X,Y] = meshgrid(x,y); Z = sin(sqrt(X.^2 + Y.^2)); figure; mesh(X,Y,Z); figure; surf(X,Y,Z);
Attempts:
2 left
💡 Hint
Recall that mesh shows wireframe and surf shows colored surface.
✗ Incorrect
mesh function plots a wireframe grid of the surface, while surf plots a colored surface with shading. Both use the same data, so the sine wave pattern appears in both but with different visual styles.❓ Predict Output
intermediate2:00remaining
Effect of shading on surf plot
What will be the visual difference after running this MATLAB code?
MATLAB
x = linspace(-3,3,50); y = linspace(-3,3,50); [X,Y] = meshgrid(x,y); Z = exp(-X.^2 - Y.^2); figure; surf(X,Y,Z); shading flat;
Attempts:
2 left
💡 Hint
Check what
shading flat does to surface plots.✗ Incorrect
shading flat removes smooth color interpolation and lighting, resulting in flat color patches on each face of the surface.🔧 Debug
advanced2:00remaining
Identify the error in meshgrid usage
What error does this MATLAB code produce and why?
MATLAB
x = 1:5; y = 1:5; [X,Y] = meshgrid(x); Z = X + Y; mesh(X,Y,Z);
Attempts:
2 left
💡 Hint
Recall that meshgrid can accept one or two vector inputs.
✗ Incorrect
No error occurs. MATLAB's
meshgrid function accepts a single input vector, producing X and Y as square matrices both of size length(x)-by-length(x). Here, it creates 5x5 matrices, Z = X + Y is valid, and mesh plots the surface successfully.❓ Predict Output
advanced2:00remaining
Number of grid points in meshgrid output
How many points are in the X matrix created by this code?
MATLAB
x = linspace(0,1,40); y = linspace(0,2,60); [X,Y] = meshgrid(x,y);
Attempts:
2 left
💡 Hint
Remember meshgrid creates matrices with rows = length(y) and columns = length(x).
✗ Incorrect
X is a matrix with size length(y) rows and length(x) columns, so total elements = 60 * 40 = 2400.
🧠 Conceptual
expert2:00remaining
Difference between mesh and surf in 3D plotting
Which statement correctly describes the difference between
mesh and surf functions in MATLAB?Attempts:
2 left
💡 Hint
Think about how the surface looks visually with each function.
✗ Incorrect
mesh draws a grid-like wireframe surface without color filling, while surf draws a solid surface with color and shading effects.