Bird
0
0

Identify the mistake in this MATLAB code for 3D plotting:

medium📝 Debug Q6 of 15
MATLAB - 3D Plotting and Visualization
Identify the mistake in this MATLAB code for 3D plotting:
[X,Y] = meshgrid(-1:1, -1:1);
Z = X*Y;
surf(X,Y,Z);
AMatrix multiplication (*) is used instead of element-wise multiplication (.*)
Bmeshgrid inputs are invalid ranges
Csurf function cannot plot matrices
DZ should be a vector, not a matrix
Step-by-Step Solution
Solution:
  1. Step 1: Check operation on matrices

    X and Y are matrices from meshgrid; using * attempts matrix multiplication.
  2. Step 2: Correct element-wise operation

    To multiply corresponding elements, use element-wise operator .* instead of *.
  3. Final Answer:

    Matrix multiplication (*) is used instead of element-wise multiplication (.*) -> Option A
  4. Quick Check:

    Use .* for element-wise multiplication [OK]
Quick Trick: Use .* for element-wise multiplication [OK]
Common Mistakes:
  • Using * instead of .* for element-wise
  • Misunderstanding meshgrid output
  • Thinking surf can't plot matrices

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes