首页 > 解决方案 > 我将复数提高到幂的方法有什么问题

问题描述

我的方法使用 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。

标签: javacomplex-numbers

解决方案


推荐阅读