Challenge - 5 Problems
Plot Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this plot command?
Consider the following MATLAB code snippet:
What does this plot show?
x = 1:5;
y = x.^2;
plot(x, y)
What does this plot show?
MATLAB
x = 1:5; y = x.^2; plot(x, y)
Attempts:
2 left
💡 Hint
The plot() function connects points with lines by default.
✗ Incorrect
The plot(x, y) command in MATLAB creates a line plot connecting the points defined by vectors x and y. Here, y = x squared, so the points are (1,1), (2,4), (3,9), (4,16), (5,25).
❓ Predict Output
intermediate2:00remaining
What color and marker style does this plot use?
Look at this MATLAB code:
What does the plot look like?
x = 0:0.5:2;
y = sin(pi*x);
plot(x, y, 'ro--')
What does the plot look like?
MATLAB
x = 0:0.5:2; y = sin(pi*x); plot(x, y, 'ro--')
Attempts:
2 left
💡 Hint
The format string 'ro--' means red color, circle marker, dashed line.
✗ Incorrect
In MATLAB plot format strings, 'r' means red color, 'o' means circle marker, and '--' means dashed line. So the plot shows red circles connected by dashed lines.
🔧 Debug
advanced2:00remaining
Why does this plot command cause an error?
Examine this MATLAB code:
What error occurs and why?
x = 1:5;
y = [2, 4, 6];
plot(x, y)
What error occurs and why?
MATLAB
x = 1:5; y = [2, 4, 6]; plot(x, y)
Attempts:
2 left
💡 Hint
Check if x and y have the same number of elements.
✗ Incorrect
The plot function requires x and y to have the same length. Here, x has 5 elements but y has only 3, so MATLAB throws an error about dimension mismatch.
🧠 Conceptual
advanced2:00remaining
What happens if you call plot with a single vector?
In MATLAB, what does the command
plot([3 1 4 1 5]) do?MATLAB
plot([3 1 4 1 5])
Attempts:
2 left
💡 Hint
When only one vector is given, MATLAB uses indices as x values.
✗ Incorrect
If plot is called with one vector, MATLAB plots the vector values on the y-axis and uses the indices (1,2,3,...) as x-axis values.
❓ Predict Output
expert3:00remaining
What is the output of this multi-line plot command?
Consider this MATLAB code:
What does the plot show?
x = 0:pi/4:pi;
y1 = sin(x);
y2 = cos(x);
plot(x, y1, '-b', x, y2, ':r')
What does the plot show?
MATLAB
x = 0:pi/4:pi; y1 = sin(x); y2 = cos(x); plot(x, y1, '-b', x, y2, ':r')
Attempts:
2 left
💡 Hint
The format '-b' means blue solid line, ':r' means red dotted line.
✗ Incorrect
The plot command plots two lines: sin(x) with a blue solid line and cos(x) with a red dotted line, using the specified format strings.