-
-
Notifications
You must be signed in to change notification settings - Fork 41
[complex-numbers] Added new concept #390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.