Problem 45281. A "Complex" Converter: Rectangular Form <-> Polar Form
BACKGROUND / MOTIVATION:
Complex numbers can be an important tool in an electrical engineer's toolbox because they can help us describe / work with sinusoidal signals.
Sinusoidal signals can be found all over the place in day-to-day life (in music, light, communication systems, power systems, etc.):
- "Why Study Sinusoids?": https://www.youtube.com/watch?v=yXjXJ5OlNyQ
- "Euler's formula": https://www.khanacademy.org/science/electrical-engineering/ee-circuit-analysis-topic/ee-ac-analysis/v/ee-eulers-formula
When working with complex numbers, sometimes it's easier to work with the "rectangular/Cartesian form" (z = x + j*y) and sometimes it's easier to work with the "polar form" (r ∠ θ).
- Using the rectangular form is sometimes like using decimals: it can make the numbers easier to add / subtract
- Using the polar form is sometimes like using fractions: it can the numbers easier to multiply / divide
- In the end, the two forms are equivalent, but sometimes they're easier to work with in one form instead of another.
Write a function which converts between the rectangular form and the polar form.
You can view a comparison of the two forms here: https://www.khanacademy.org/science/electrical-engineering/ee-circuit-analysis-topic/ee-ac-analysis/v/ee-complex-numbers
The variable "form" will be used to determine whether the function converts from rectangular to polar or from polar to rectangular.
The function takes the following inputs:
- "input1" - a variable which is either "x" (the real component in rectangular form) or "r" (the radius in polar form)
- "input2" - a variable which is either "y" (the complex component in rectangular form) or "theta" (the angle, in degrees, in polar form)
- "form" - a variable which is set to either "r2p" (to convert from rectangular to polar) or "p2r" (to convert from polar to rectangular)
The function will output the variable "output" in the form of a column vector [output1;output2] where:
- "output1" - a component of the output which is either "x" (the real component in rectangular form) or "r" (the radius in polar form)
- "output2" - a component of the output which is either "y" (the complex component in rectangular form) or "theta" (the positive angle, in degrees, in polar form)
The test suite will round the components of your output vector to 4 decimal places.
Please feel free to leave feedback on this problem in the comments! :)
Solution CommentsShow comments
Problem Recent Solvers29