microsoft/qdk

Public

mirrored from https://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.3.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

katas/content/complex_arithmetic/cartesian_to_polar/solution.md

24lines · modecode

1We need to calculate the $r$ and $\theta$ values as seen in the complex plane.
2$r$ should be familiar to you already, since it is the modulus of a number (exercise 6):
3
4$$ r = \sqrt{a^2 + b^2} $$
5
6$\theta$ can be calculated using trigonometry: since we know that the polar and the Cartesian forms of the number represent the same value, we can write
7
8$$ re^{i \theta} = a + bi $$
9
10Euler's formula allows us to express the left part of the equation as
11
12$$ re^{i \theta} = r \cos \theta + i r \sin \theta $$
13
14For two complex numbers to be equal, their real and imaginary parts have to be equal. This gives us the following system of equations:
15
16$$ \begin{cases} a = r \cos \theta \\ b = r \sin \theta \end{cases} $$
17
18To calculate $\theta$, we can divide the second equation by the first one to get
19
20$$ \tan \theta = \frac{b}{a} $$
21
22$$ \theta = \arctan \left(\frac{b}{a}\right) $$
23
24@[solution]({"id": "complex_arithmetic__cartesian_to_polar_solution", "codePath": "Solution.qs"})
25