📖 Scenario: You are working on a simple electrical engineering problem where voltages and currents are represented as complex numbers. You need to create and manipulate complex numbers in MATLAB to find their magnitudes and phases.
🎯 Goal: Build a MATLAB script that creates complex numbers, calculates their magnitudes and phases, and displays the results.
📋 What You'll Learn
Create complex numbers using real and imaginary parts
Calculate magnitude using MATLAB's abs function
Calculate phase (angle) using MATLAB's angle function
Display results clearly using disp
💡 Why This Matters
🌍 Real World
Complex numbers are used in electrical engineering to represent voltages and currents that have both magnitude and phase.
💼 Career
Understanding complex numbers and how to manipulate them in MATLAB is important for engineers working with signals, circuits, and control systems.
Progress0 / 4 steps
1
Create complex numbers
Create two complex numbers called z1 and z2 with these exact values: z1 = 3 + 4i and z2 = 1 - 2i.
MATLAB
Hint
Use i to represent the imaginary unit in MATLAB.
2
Calculate magnitudes
Create two variables called mag1 and mag2 that store the magnitudes of z1 and z2 using the abs function.
MATLAB
Hint
Use abs(z) to get the magnitude of a complex number z.
3
Calculate phases
Create two variables called phase1 and phase2 that store the phases (angles) of z1 and z2 using the angle function.
MATLAB
Hint
Use angle(z) to get the phase of a complex number z.
4
Display results
Use disp to print the magnitudes and phases of z1 and z2 with clear messages exactly as shown: "Magnitude of z1: " followed by mag1 "Phase of z1: " followed by phase1 "Magnitude of z2: " followed by mag2 "Phase of z2: " followed by phase2.
MATLAB
Hint
Use disp(['text', num2str(value)]) to display text and numbers together.
Practice
(1/5)
1. Which of the following correctly represents a complex number with real part 3 and imaginary part 4 in MATLAB?
easy
A. 3 + 4
B. 3i + 4
C. 3 + 4i
D. 3 + 4j + 1
Solution
Step 1: Understand complex number format in MATLAB
Complex numbers are written as real part plus imaginary part times i or j, e.g., 3 + 4i.
Step 2: Check each option
3 + 4i uses 3 + 4i which is correct. 3 + 4 misses imaginary part. 3i + 4 swaps real and imaginary incorrectly. 3 + 4j + 1 adds extra 1.
Final Answer:
3 + 4i -> Option C
Quick Check:
Complex number = 3 + 4i [OK]
Hint: Use 'i' or 'j' after the imaginary part number [OK]
Common Mistakes:
Forgetting to include 'i' or 'j' for imaginary part
Swapping real and imaginary parts
Adding extra numbers outside complex format
2. Which of the following MATLAB commands correctly creates a complex number variable named z with real part 5 and imaginary part -2?
easy
A. z = complex(5, -2);
B. z = 5 + 2i;
C. z = 5 + -2;
D. z = 5 - 2;
Solution
Step 1: Recall MATLAB syntax for complex numbers
Using complex(real, imag) function is a clear way to create complex numbers.
Step 2: Analyze options
z = 5 - 2; is just a real number. z = 5 + 2i; creates 5 + 2i (wrong imaginary part). z = 5 + -2; is a real number. z = complex(5, -2); uses complex(5, -2) correctly.
Final Answer:
z = complex(5, -2); -> Option A
Quick Check:
complex(5, -2) creates correct complex number [OK]
Hint: Use complex(real, imag) for clear complex number creation [OK]
Common Mistakes:
Writing imaginary part without 'i' or 'j'
Using wrong sign for imaginary part
Confusing syntax of complex() function
3. What is the output of the following MATLAB code?
z1 = 2 + 3i; z2 = 1 - 4i; result = z1 * z2;
medium
A. 10 - 5i
B. 14 - 5i
C. 14 + 5i
D. 10 + 5i
Solution
Step 1: Multiply complex numbers (a+bi)(c+di)
Use formula: (ac - bd) + (ad + bc)i. Here a=2, b=3, c=1, d=-4.