Skip to content

Commit

Permalink
fix: complex to polar makes sense
Browse files Browse the repository at this point in the history
As pointed out in Issue lukew3#423, the `complex_to_polar` function did not make sense. Now it gives a complex number in component form, for a student to convert into polar form.

This is not a perfect function, but at least it is usable now. In future, we may want to have the theta be chosen from amongst a set of multiples/fractions of pi, that tend to make for nicer questions and answers.
  • Loading branch information
MaciejWdev committed Aug 3, 2023
1 parent f6e411a commit 090c8f4
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions mathgenerator/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def complex_to_polar(min_real_imaginary_num=-20, max_real_imaginary_num=20):
| Ex. Problem | Ex. Solution |
| --- | --- |
| $19.42(-19.0\theta + i-4.0\theta)$ | $-2.93$ |
| Convert $-14.0+13.0i$ into polar form | $19.1(cos(2.39)+isin(2.39))$ |
"""
num = complex(
random.randint(min_real_imaginary_num, max_real_imaginary_num),
Expand All @@ -185,9 +185,13 @@ def complex_to_polar(min_real_imaginary_num=-20, max_real_imaginary_num=20):
b = num.imag
r = round(math.hypot(a, b), 2)
theta = round(math.atan2(b, a), 2)
print(a)
print(b)

problem = rf'${r}({a}\theta + i{b}\theta)$'
return problem, f'${theta}$'

solution = rf'${r}(cos({theta})+isin({theta}))$'
problem = rf'Convert ${a}+{b}i$ into polar form'
return problem, solution


def decimal_to_roman_numerals(max_decimal=4000):
Expand Down

0 comments on commit 090c8f4

Please sign in to comment.