Bird
0
0

What is the output of this MATLAB code?

medium📝 Predict Output Q4 of 15
MATLAB - Numerical Methods

What is the output of this MATLAB code?

x = linspace(1, 4, 4);
y = x .* 2;
y

A[2 4 6 8]
B[1 2 3 4]
C[1 4 9 16]
D[0.5 1 1.5 2]
Step-by-Step Solution
Solution:
  1. Step 1: Generate vector x

    linspace(1,4,4) creates [1 2 3 4].
  2. Step 2: Multiply each element by 2

    Element-wise multiplication x .* 2 results in [2 4 6 8].
  3. Final Answer:

    [2 4 6 8] -> Option A
  4. Quick Check:

    Multiply each x element by 2 [OK]
Quick Trick: Element-wise operations use .* for vectors [OK]
Common Mistakes:
  • Using * instead of .* for element-wise multiplication
  • Confusing linspace output
  • Assuming vector is squared

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes