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

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 2K views
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.
 
Physics 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