处理:复数库?

Pin*_*ade 0 java math processing complex-numbers

我刚刚开始学习处理,并且很好奇是否有一个用于对表单的复数建模的库a + bi。特别是可以处理复数数字乘法的数字,例如:

(a + bi)(a + bi)


Run Code Online (Sandbox Code Playgroud)

小智 5

您可以使用Java编写自己的类,或者从此类中获得启发。您也可以导入经典的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);
    }
}
Run Code Online (Sandbox Code Playgroud)

然后为您简单使用示例:

Complex first = new Complex(a, b);
complex result =  first.multi(first);
Run Code Online (Sandbox Code Playgroud)