Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exponential form of complex number

Tags:

java

math

I have the following problem:

I need to extend following class Complex (representing complex number) and add field with exponential form of it, additionaly overload methods from Complex:

class Complex{
public double re;
public double im;

public Complex(double r, double i){
    re =r;
    im = i;
}

public Complex add(Complex a,Complex b){
    return new Complex(a.re + b.re,a.im + b.im );
}

public Complex sub(Complex a,Complex b){
    return new Complex(a.re - b.re,a.im - b.im);
}

//more code
}

My class is like following

class ComplexE extends Complex{
   public double exponential;
    public ComplexE(double a, double b){
        re=a;
        im = b;
    }
    public ComplexE(double _exp){
        super(0,0);
        this.exponential = _exp;
    }

   public void setExpFromComplex(Complex comp){
    double module = Math.sqrt(Math.pow(comp.re,2) + Math.pow(comp.im,2));
    double fi = Math.atan2(comp.re,comp.im);
    this.exponential = module * Math.pow(Math.E, fi);
   } 

   public ComplexE add(ComplexE a,ComplexE b){
        return new ComplexE(a.exponential + b.exponential );
    }

}

My questions are: am I doing it right? Does my way of finding exponential form is correct?

Edit: The math way i tried to use is:

z = |z|*(cos(phi) + i*sin(phi)) = |z|*e^(i*phi).
like image 356
Axxxon Avatar asked Nov 20 '12 21:11

Axxxon


People also ask

What is complex exponential function?

The complex exponential. The exponential function is a basic building block for solutions of ODEs. Complex numbers expand the scope of the exponential function, and bring trigonometric functions under its sway.

How do you write in exponential form?

In exponential notation, a number usually is expressed as a coefficient between one and ten times an integral power of ten, the exponent. To express a number in exponential notation, write it in the form: c × 10n, where c is a number between 1 and 10 (e.g. 1, 2.5, 6.3, 9.8) and n is an integer (e.g. 1, -3, 6, -2).

What is exponential polar form?

Recall that the polar form of a complex number z = a + b i is: z = r ( c o s θ + i s i n θ ) So, by substituting Euler's formula to the polar form formula, we get the exponential form of a complex number: z = r e i θ , where is in radians.

What are the forms of complex numbers?

Complex numbers have three primary forms: the general form, z=a+ib; the polar form, z=r(cosθ+isinθ); and the exponential form, z=rexp(iθ).


1 Answers

You have a number of mistakes. First of all, I assume by exponential you mean polar coordinates, i.e. r*e^(i*theta). Except rectangular complex numbers and polar complex numbers are ISOMORPHIC, that is, you can convert one to the other and back again.

This suggests that you shouldn't have exponential complex numbers inherit from regular complex numbers... the difference is in the IMPLEMENTATION, i.e. how the numbers are stored in memory. In other words, your interface:

public interface IComplex {
    public double getReal();
    public double getImag();
    public double getR();
    public double getTheta();
    public IComplex add(IComplex first, IComplex second);
    public IComplex sub(IComplex first, IComplex second);
    // Etc.
}

And the rectangular implementation:

public class RectComplex implements IComplex {
    private double realPart; // note privacy... use getters and setters
    private double imagPart;

    public RealComplex (double real, double imag) {
        realPart = real;
        imagPart = imag;
    }

    public double getReal() {
        return realPart;
    }

    public double getR() {
        return Math.sqrt(realPart * realPart + imagPart * imagPart);
    }

    // Etc.
}

And the exponential implementation:

public class ExpComplex implements IComplex {
    private double r;
    private double theta;

    public double getReal() {
        return r * Math.cos(theta);
    }

    public double getR() {
        return r;
    }

    // Etc.
}

This prevents redundant fields. Think about the difference between an ArrayList and a LinkedList. They're both lists, (the above are both Complex numbers), but they work totally differently from an implementation perspective. But any code that USES these classes wouldn't care, but they would choose the correct one based on performance, probably. Make sense?

like image 142
durron597 Avatar answered Sep 28 '22 05:09

durron597