Challenge - 5 Problems
Contour Plot Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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);
Attempts:
2 left
💡 Hint
Recall that contour plots show lines of constant value for a function of two variables.
✗ Incorrect
The code creates a grid of points and calculates Z = X^2 + Y^2 at each point. The contour function then draws 5 contour lines representing levels of Z. It does not create a 3D plot or scatter plot, and the inputs are valid matrices for contour.
❓ Predict Output
intermediate2: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]);
Attempts:
2 left
💡 Hint
Check how contour levels are specified as a vector of values.
✗ Incorrect
The contour function draws contour lines at the exact levels specified in the vector [-0.5 0 0.5]. It does not fill the areas between contours (that would be contourf). Negative levels are allowed.
🔧 Debug
advanced2: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);
Attempts:
2 left
💡 Hint
Check how powers are applied to arrays in MATLAB.
✗ Incorrect
In MATLAB, ^ is matrix power and requires square matrices. X and Y are matrices, so X^2 and Y^2 cause an error. The element-wise power operator .^ should be used instead.
📝 Syntax
advanced2: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);
Attempts:
2 left
💡 Hint
Check MATLAB function argument syntax carefully.
✗ Incorrect
MATLAB contour function takes the number of contour levels as a numeric argument without keywords or commas. Options A, B, and D have invalid syntax.
🚀 Application
expert2: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);
Attempts:
2 left
💡 Hint
If contour levels are not specified, MATLAB chooses a default number.
✗ Incorrect
When contour levels are not specified, MATLAB automatically selects about 10 contour levels spanning the range of Z values, regardless of the function's frequency.