散度边界的java Mandelbrot集

散度边界的java Mandelbrot集,java,double,boolean,Java,Double,Boolean,我的程序一直在获取bigNum变量的死亡红线。我试着测试它是否在边界内 public class ComplexNumber { private final MyDouble real; // To be initialized in constructors private final MyDouble imag; // To be initialized in constructors // constructor initializing public ComplexNumber(My

我的程序一直在获取bigNum变量的死亡红线。我试着测试它是否在边界内

public class ComplexNumber {

private final MyDouble real; // To be initialized in constructors
private final MyDouble imag; // To be initialized in constructors
// constructor initializing

public ComplexNumber(MyDouble realIn, MyDouble imagIn) {

    this.real = realIn;
    this.imag = imagIn;

}

public ComplexNumber(MyDouble realnumber) {
    this.real = realnumber;
    this.imag = new MyDouble(0);

}

public MyDouble getReal() {
    return real;
}

public MyDouble getImag() {
    return imag;
}

// copy constructor
public ComplexNumber(ComplexNumber c) {
    this(c.getReal(), c.getImag());
}

// addition of complex numbers
public ComplexNumber add(ComplexNumber a) {

    // this.real.add(a.getReal());

    return new ComplexNumber(this.real.add(a.getReal()), this.imag.add(a
            .getImag()));

}// subtraction of complex numbers

public ComplexNumber subtract(ComplexNumber s) {

    return new ComplexNumber(this.real.subtract(s.getReal()), this.imag
            .subtract(s.getImag()));

}

// Multiplication of complex numbers
public ComplexNumber multiply(ComplexNumber m) {
    MyDouble first = (this.real.multiply(m.getReal()));
    MyDouble outside = (m.getReal().multiply(this.imag));
    MyDouble inside = (m.getImag().multiply(this.real));
    MyDouble last = (this.imag.multiply(m.getImag()));

    return (new ComplexNumber(first.subtract(last), (outside.add(inside))));

}

// dividing complex numbers
// double check again but should work
public ComplexNumber divide(ComplexNumber x) {

//  MyDouble topReal1 = this.real.multiply(d.getReal());
//  MyDouble topReal2 = this.imag.multiply(d.getImag());
//  MyDouble topImag1 = this.imag.multiply(d.getReal());
//  MyDouble topImag2 = d.getReal().multiply(this.imag);
//  MyDouble bottomReal = this.real.multiply(this.real);
//  MyDouble bottomImag = d.getImag().multiply(d.getImag());
//  MyDouble realSet = topReal1.add(topReal2);
//  MyDouble imagSet = topImag1.subtract(topImag2);
//  MyDouble top = realSet.add(imagSet);
//  MyDouble bottom = bottomReal.add(bottomImag);
//
//  return new ComplexNumber(realSet.divide(bottom), imagSet.divide(bottom));


    MyDouble demon = x.real.multiply(x.real).add(x.imag.multiply(x.imag));
    MyDouble r = real.multiply(x.real).add(imag.multiply(x.imag));
    MyDouble i = imag.multiply(x.real).subtract(real.multiply(x.imag));
    return new ComplexNumber(r.divide(demon),i.divide(demon));


}

// equals method
public boolean equals(ComplexNumber n) {

    return this.real.equals(n.getReal()) && this.imag.equals(n.getImag());

}

// compare to method
//public int compareTo(MyDouble x) {
//  int imagNum = x.compareTo(this.getImag());
//  int realNum = x.compareTo(this.getReal());
//  return realNum + imagNum;

//if ( this.norm(x.equals(x.))

//}

// string to string method
public String toString() {
    // thinking how to get negative values since if else didnt work out too
    // well
    return getReal()+"+"+getImag()+"i";

}

// annoying square root function does not work and api is not as useful
// complex norm method static
public static MyDouble norm(ComplexNumber n) {
    MyDouble imag = (n.imag.multiply(n.getImag()));
    MyDouble poly = imag.add((n.real.multiply(n.getReal())));

    return n.real.multiply(n.real).add(n.imag.multiply(n.imag)).sqrt();

}

// parse method to clear the spaces between the numbers and characters
public static ComplexNumber parse(String s) {
    s.replace(" ", "");
    String realstring;
    String imagstring;
    if (s.indexOf('+') != -1) {
        realstring = s.substring(0, s.indexOf("+"));
        imagstring = s.substring(s.lastIndexOf("+") + 1, s.indexOf("i"));
    } else {
        realstring = s.substring(0, s.lastIndexOf("-"));
        imagstring = s.substring(s.lastIndexOf("-") - 1, s.indexOf("i"));
    }
    return new ComplexNumber(new MyDouble(Double.parseDouble(realstring)),
            new MyDouble(Double.parseDouble(imagstring)));

}
}

如果将光标悬停在代码中的红线或左边距中的红色圆圈上,您应该会看到更详细的错误消息

不过,我还是可以猜测:

我不知道您的
ComplexNumber
类,但我怀疑
乘法
add
方法会产生
ComplexNumber
结果,而您需要的是
双精度
。我会以不同的方式编写您的测试,如下所示:

double bigNum = aa.getReal() * aa.getReal() + aa.getImag() * aa.getImag();
return (bigNum > Controller.DIVERGENCE_BOUNDARY);

如果将光标悬停在代码中的红线或左边距中的红色圆圈上,您应该会看到更详细的错误消息

不过,我还是可以猜测:

我不知道您的
ComplexNumber
类,但我怀疑
乘法
add
方法会产生
ComplexNumber
结果,而您需要的是
双精度
。我会以不同的方式编写您的测试,如下所示:

double bigNum = aa.getReal() * aa.getReal() + aa.getImag() * aa.getImag();
return (bigNum > Controller.DIVERGENCE_BOUNDARY);

如果不知道您的
ComplexNumber
类来自何处以及
getReal()
getImag()
返回的内容,就很难回答您的问题。@biziclop,我猜OP指的是IDE标记的错误。@asgs啊,应该是这样的。但它们通常伴随着一条漂亮的错误消息,这至少是一个可能出错的提示如果不知道您的
ComplexNumber
类来自何处以及
getReal()
getImag()
返回的内容,就很难回答您的问题。@biziclop,我猜OP指的是IDE标记的错误。@asgs啊,应该是这样的。但它们通常伴随着一条漂亮的错误消息,这至少是一个可能出错的提示正如你所看到的,我在编程方面是个十足的傻瓜,正如你所看到的,我在编程方面是个十足的傻瓜