Challenge - 5 Problems
3D Line Plot Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a simple 3D line plot
What will be the output of the following MATLAB code snippet?
MATLAB
x = 1:5; y = x.^2; z = x + 1; plot3(x, y, z, '-o');
Attempts:
2 left
💡 Hint
Remember plot3 plots lines in 3D space using x, y, and z coordinates.
✗ Incorrect
The plot3 function connects points in 3D space with lines and markers. Here, x, y, and z are vectors of equal length, so it plots a 3D line with circle markers at each point.
🧠 Conceptual
intermediate1:30remaining
Understanding plot3 input vectors
Which of the following statements about the inputs to plot3(x,y,z) is TRUE?
Attempts:
2 left
💡 Hint
Think about how points in 3D space are defined for a line.
✗ Incorrect
plot3 connects points defined by corresponding elements in x, y, and z vectors. They must be the same length to form valid points.
🔧 Debug
advanced2:00remaining
Identify the error in 3D line plotting code
What error will the following MATLAB code produce?
MATLAB
x = 1:4; y = [2 4 6]; z = 1:4; plot3(x, y, z);
Attempts:
2 left
💡 Hint
Check the length of each vector used in plot3.
✗ Incorrect
The y vector has length 3, while x and z have length 4. plot3 requires all input vectors to be the same length.
📝 Syntax
advanced2:30remaining
Correct syntax for plotting multiple 3D lines
Which option correctly plots two separate 3D lines in one figure?
MATLAB
x1 = 1:3; y1 = [2 3 4]; z1 = [1 0 1]; x2 = 3:5; y2 = [5 6 7]; z2 = [2 2 2];
Attempts:
2 left
💡 Hint
Use hold on to plot multiple lines in the same figure.
✗ Incorrect
Option B plots the first line, then holds the plot to add the second line. Option B merges points into one line. Option B misses z for first line. Option B is invalid syntax.
🚀 Application
expert1:30remaining
Number of line segments in a 3D plot
Given vectors x, y, z each of length 10, how many line segments does plot3(x, y, z) draw?
Attempts:
2 left
💡 Hint
Each line segment connects two consecutive points.
✗ Incorrect
With 10 points, plot3 connects point 1 to 2, 2 to 3, ..., 9 to 10, making 9 segments.