Java How to Get the Rectangular Form of a Complex Number in Java?

Click For Summary
The discussion centers on a mini-project in Java involving complex number calculations, particularly the natural logarithm of complex numbers in rectangular form. The user initially faced challenges with the Complex.java class but found a solution by discovering that the class includes a log() method, which can be used to obtain the logarithm of a complex number. This method allows access to the real and imaginary parts of the result, either through logZ.real() and logZ.imag() or logZ.toString() for a string representation. The user also expressed interest in finding alternative classes for handling complex powers but later resolved their issue independently.
pierce15
Messages
313
Reaction score
2
Hi, I'm doing a mini-project in java that involves some nasty calculations with complex numbers- particularly with complex numbers in exponents. Thus far, I've had success using this class: Complex.java . The problem that I'm encountering involves taking the natural logarithm of a complex number a + bi and getting the rectangular form of the new number. Is there any workaround for this? I feel like I'm missing something easy, since I can easily type in the natural logarithm of a complex number into google and it easily tells me the approximate rectangular value.

By the way, if someone knows of another class which would actually allow me to use complex powers to begin with, I would greatly appreciate it if you shared it with me.
 
Technology news on Phys.org
Actually, never mind, I figured out an alternate approach to the problem!
 
But the class you linked to has a method log() - isn't that exactly what you are looking for?
Code:
Complex z = ...;
Complex logZ = z.log();

// Use logZ.real() and logZ.imag() to get the rectangular form
// or logZ.toString() if you need the string representation
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

Replies
21
Views
13K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
22
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 6 ·
Replies
6
Views
11K
  • · Replies 47 ·
2
Replies
47
Views
8K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K