gpt4 book ai didi

java - 处理:复数库?

转载 作者:行者123 更新时间:2023-12-01 17:17:33 25 4
gpt4 key购买 nike

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

(a + bi)(a + bi)


最佳答案

您可以用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);

关于java - 处理:复数库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20959989/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com