处理:复数的库?

问题描述 投票:0回答:1

我刚刚开始学习处理,很想知道是否有一个用于对a + bi形式的复数建模的库。特别是可以处理复数数字乘法的数字,例如:

(a + bi)(a + bi)


java math processing complex-numbers
1个回答
5
投票

您可以用Java编写自己的类,或者从this class中得到启发。您也可以导入经典的Java库,例如common-math

如果只需要乘法,只需将此类添加到草图中即可:

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);
    }
}

然后为您简单使用示例:

Complex first = new Complex(a, b);
complex result =  first.multi(first);
© www.soinside.com 2019 - 2024. All rights reserved.