[complex-numbers] Added new concept#390
Conversation
This reverts commit 90689eb.
| ## Basics | ||
|
|
||
| A `complex` number in R is a single value. | ||
| In use, however, it can be thought of as a pair of numbers: usually but not always floating-point. |
There was a problem hiding this comment.
What do you mean here? I find it confusing as ?complex states that: "Internally, complex numbers are stored as a pair of double precision numbers, either or both of which can be NaN(including NA, see NA_complex_ and above) or plus or minus infinity."
Nerwosolek
left a comment
There was a problem hiding this comment.
I had some suggestions, if you don't find them interesting just merge.
If you don't have time and would like to implement some of them, let me know if I can help.
| For now, all this means is that the imaginary part _by definition_ satisfies the following equality: | ||
|
|
||
| ```r | ||
| > 1i * 1i == -1 |
There was a problem hiding this comment.
I would even say that it satisfies: 1i * 1i == -1 + 0i.
R probably does some coercion before comparing different types or operator is defined that way it can compare different types.
But 1i * 1i results in complex number.
|
|
||
| Any [mathematical][math-complex] or [electrical engineering][engineering-complex] introduction to complex numbers will cover this, should you want to dig into the topic. | ||
|
|
||
| Alternatively, Exercism has a `Complex Numbers` practice exercise where you can implement a complex number class with these operations from first principles. |
There was a problem hiding this comment.
Maybe add link to that exercise as we have it merged already?
| > sqrt(z1) | ||
| [1] 1.414214+0.707107i | ||
|
|
||
| > sqrt(-1) # fails! |
There was a problem hiding this comment.
What about adding also positive example that sqrt(-1+0i) will work?
| - The `(real, imag)` representation of `z1` in effect uses Cartesian coordinates on the complex plane. | ||
| - The same complex number can be represented in `(r, θ)` notation, using polar coordinates. | ||
| - Here, `r` and `θ` are given by `abs(z1)` and `Arg(z1)` respectively. | ||
|
|
There was a problem hiding this comment.
What do you think about adding some example how can we rotate 2D vectors in R easily.
Like in here we rotate vector (1,2) by 90 degrees leftwise:
x <- 1
y <- 2
angle <- pi/2
rot_z <- complex(modulus = 1, argument = angle)
rot_z * (x + 1i*y)
As requested, though we still don't have a Concept Exercise to pair with it. I'll mark it draft until we can get an
introduction.md.Meanwhile, I had a look through some of the concepts I PR'd back in 2023, and was shocked how bad they are. That was before I had the highly educational experience of working with Bethany on the Python track (she's a very careful teacher). I've changed their status to draft, and I'll try to rewrite them sometime when I have the time, energy and functional brainpower simultaneously. I haven't looked at the old Concept Exercises yet, I hope they are in better shape.