java - 我将复数提高到幂的方法有什么问题
问题描述
我的方法使用 De Moivre 定理将复数 a+bi 提高到幂。但是,我没有得到正确的答案。
我仔细检查了我所有的数学,似乎没问题,所以我想我可能做错了我的代码。
public class ComplexNumber {
//instance variables
private int real;
private int imaginary;
//constructors
public ComplexNumber(int a, int b) {
real = a;
imaginary = b;
//methods
public ComplexNumber pow(int x) {
int z = (int) Math.pow(this.getModulus(),x);
int T = (int) Math.atan(this.imaginary/this.real);
int a = (int) (z * Math.cos(x*T));
int b = (int) (z * Math.sin(x*T));
return new ComplexNumber(a, b);
}
public double getModulus() {
int z = (int) Math.sqrt(real*real + imaginary*imaginary);
return z;
}
例如,对于复数 3+4i 的 1 次方,我得到 5+0i。
解决方案
推荐阅读
- powershell - 在powershell中将日期字符串转换为日期时间
- reactjs - 将运行时数据从组件传递到 HoC?
- node.js - 有没有办法使用软件获取代理目标网址?
- generics - 如何解决我的 SICP Ex 2.85 实施中的奇怪错误?
- flutter - 如何让应用在各种屏幕上正确显示?
- java - Maven 通过指定 contextPath 的命令行运行 Jetty Plugin
- python - 无法使用 create_tweet() 发布推文
- elasticsearch - 得到响应代码“400”在 logstash 中的 URL 联系 Elasticsearch
- python - 将日期转换为具有相同值的十六进制
- python - 如何使用 for 循环重复函数