0
0
MATLABdata~20 mins

mesh and surf for surfaces in MATLAB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Surface Plot Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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);
ATwo figures: first shows a wireframe sine wave surface, second shows a colored smooth sine wave surface
BTwo figures: both show flat planes with no wave pattern
COne figure with two overlapping plots of sine wave surfaces
DError because meshgrid is used incorrectly
Attempts:
2 left
💡 Hint
Recall that mesh shows wireframe and surf shows colored surface.
Predict Output
intermediate
2: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;
AThe code will produce an error because shading is not a valid function
BThe surface will have flat color patches without smooth color transitions
CThe plot will show only the wireframe without any color fill
DThe surface will have smooth color gradients with lighting effects
Attempts:
2 left
💡 Hint
Check what shading flat does to surface plots.
🔧 Debug
advanced
2: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);
ANo error, code runs and plots a surface
BError: meshgrid requires two input vectors, but only one was given
CError: Z matrix dimensions do not match X and Y
DError: mesh function requires three input arguments
Attempts:
2 left
💡 Hint
Recall that meshgrid can accept one or two vector inputs.
Predict Output
advanced
2: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);
A40
B100
C2400
D60
Attempts:
2 left
💡 Hint
Remember meshgrid creates matrices with rows = length(y) and columns = length(x).
🧠 Conceptual
expert
2:00remaining
Difference between mesh and surf in 3D plotting
Which statement correctly describes the difference between mesh and surf functions in MATLAB?
A<code>mesh</code> automatically adds lighting, <code>surf</code> does not
B<code>mesh</code> creates a 2D plot, <code>surf</code> creates a 3D plot
C<code>mesh</code> requires fewer input arguments than <code>surf</code>
D<code>mesh</code> creates a wireframe surface without color filling, while <code>surf</code> creates a colored surface with shading
Attempts:
2 left
💡 Hint
Think about how the surface looks visually with each function.