Question

I've just started learning Processing and I'm curious if there is a library for modeling complex numbers of the form a + bi. Particularly one that can handle multiplication of complex numbers numbers like:

(a + bi)(a + bi)


Was it helpful?

Solution

You can write your own class in java or be inspired by this class. Also you can import classic java libraries like common-math.

If you need only multiplication just add this class to your sketch:

class Complex {
    double real;   // the real part
    double img;   // the imaginary part

    public Complex(double real, double img) {
        this.real = real;
        this.img = img;
    }

    public Complex multi(Complex b) {
        double real = this.real * b.real - this.img * b.img;
        double img = this.real * b.img + this.img * b.real;
        return new Complex(real, img);
    }
}

And then simple use for you example:

Complex first = new Complex(a, b);
complex result =  first.multi(first);

OTHER TIPS

The Qscript library handles complex numbers add, subtract, powers the shebang. You can add it from the GUI add library function

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top