0
0
MATLABdata~20 mins

contour plots in MATLAB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Contour Plot Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of Basic Contour Plot
What will be the output of this MATLAB code snippet that creates a contour plot?
MATLAB
x = -2:0.2:2;
y = -2:0.2:2;
[X,Y] = meshgrid(x,y);
Z = X.^2 + Y.^2;
contour(X,Y,Z,5);
AA contour plot with 5 contour lines representing levels of Z = X^2 + Y^2
BA 3D surface plot of Z = X^2 + Y^2
CA scatter plot of points (X,Y) colored by Z values
DAn error because contour requires a vector input, not matrices
Attempts:
2 left
💡 Hint
Recall that contour plots show lines of constant value for a function of two variables.
Predict Output
intermediate
2:00remaining
Contour Plot with Specified Levels
What does this MATLAB code produce?
MATLAB
x = linspace(-3,3,50);
y = linspace(-3,3,50);
[X,Y] = meshgrid(x,y);
Z = sin(X).*cos(Y);
contour(X,Y,Z,[-0.5 0 0.5]);
AAn error because contour levels must be positive
BA contour plot with default number of contour lines ignoring specified levels
CA filled contour plot with colors between levels -0.5, 0, and 0.5
DA contour plot with exactly three contour lines at levels -0.5, 0, and 0.5
Attempts:
2 left
💡 Hint
Check how contour levels are specified as a vector of values.
🔧 Debug
advanced
2:00remaining
Identify the Error in Contour Plot Code
This MATLAB code is intended to plot contours of Z = X^2 - Y^2, but it produces an error. What is the cause?
MATLAB
x = -2:0.1:2;
y = -2:0.2:2;
[X,Y] = meshgrid(x,y);
Z = X^2 - Y^2;
contour(X,Y,Z);
AUsing ^ operator on matrices instead of element-wise .^ causes an error
Bmeshgrid inputs must be column vectors, not row vectors
Ccontour requires Z to be a vector, not a matrix
DThe variable Z is not defined before calling contour
Attempts:
2 left
💡 Hint
Check how powers are applied to arrays in MATLAB.
📝 Syntax
advanced
2:00remaining
Syntax Error in Contour Plot Command
Which option contains the correct syntax to plot contours of Z with 10 levels in MATLAB?
MATLAB
x = -1:0.1:1;
y = -1:0.1:1;
[X,Y] = meshgrid(x,y);
Z = exp(-X.^2 - Y.^2);
Acontour(X,Y,Z,levels=10);
Bcontour(X,Y,Z,10);
Ccontour(X,Y,Z,levels 10);
Dcontour(X,Y,Z,10,);
Attempts:
2 left
💡 Hint
Check MATLAB function argument syntax carefully.
🚀 Application
expert
2:00remaining
Number of Contour Lines in Complex Plot
Given the code below, how many contour lines will be drawn by MATLAB's contour function?
MATLAB
x = linspace(-2,2,100);
y = linspace(-2,2,100);
[X,Y] = meshgrid(x,y);
Z = sin(3*X).*cos(2*Y);
contour(X,Y,Z);
AExactly 5 contour lines because of the sine and cosine frequencies
BAn error because contour requires explicit contour levels
CApproximately 10 contour lines (default number)
DNo contour lines because Z contains negative values
Attempts:
2 left
💡 Hint
If contour levels are not specified, MATLAB chooses a default number.