- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我的程序不断收到 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
类,但我怀疑 multiply
和 add
方法会产生 ComplexNumber
结果,而您想要一个 double
。我会以不同的方式编写你的测试,如下所示:
double bigNum = aa.getReal() * aa.getReal() + aa.getImag() * aa.getImag();
return (bigNum > Controller.DIVERGENCE_BOUNDARY);
关于java Mandelbrot集发散边界,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5573123/
我现在在 Mandelbrot 集的 DirectX 11 版本上工作了几天。到目前为止,我所做的是创建一个带有纹理的四边形。我可以使用 Pixel Shader 为点着色,但由于某种原因,Pixel
我在 Javascript 上编写了一个程序,用于创建 mandelbrot 分形,并将其绘制在 html Canvas 中。我的渲染方法是每行迭代,从 0 到 500 像素,然后简单地执行一个循环,
我的类(class)布置了一项作业,要求我编写一个程序来绘制曼德尔布洛特图形。 我们必须基本上让程序绘制结果的位图。 问题是,我的 CalcMBF 函数只输出 2 作为 Mandelbrot 数。 我
我认为问题在于我如何将笛卡尔坐标转换为复数,但我现在知道如何操作了。你能解释一下我应该如何转换吗?这是我尝试过的: double c_Im = (y + (maxIm - minIm)) / heig
我是 C++ 编程的新手,为了改进,我正在尝试制作一个 mandelbrot set consol 应用程序。我已经让它几乎完美地工作:图像生成,我可以放大/缩小,并且非常容易地四处移动。不过,我遇到
我想使用 Java 生成 Mandelbrot 集的 PNG 照片,输出应该可以在 Google 图片搜索中轻松找到。 该集合定义为以下序列: z_n+1 = z_n^2 + c 其中 c 和 z 是
我用 Java 编写了一个 Mandelbrot 集分形,并包含了在一定程度上平移和放大分形的功能。唯一的问题是,当我平移图像并尝试放大时,它看起来好像试图放大中心并平移一点。平移和缩放并不是真正的平
我用 python 编写了 Mandelbrot 集,但它看起来很奇怪,所以我搜索了平滑的颜色。我已经使用对数和线性插值编写了一个平滑的着色函数,但无论我尝试什么,我都无法得到我想要的: self.p
我编写了一个简单的片段着色器来渲染 mandelbrot 集。我正在使用 c 语言和使用 glsl 的 opengl 执行此操作。 #version 330 core in vec2 fCoord;
我正在尝试制作一个程序,通过制作一个 .PPM 文件来生成标准 Mandelbrot 集的图像。该程序没有生成有效的 PPM 文件,我不知道为什么。 这是我的代码: #include #includ
我知道已经回答了很多关于此的问题。然而,我的略有不同。每当我们实现我所理解的平滑着色算法时。 mu = 1 + n + math.log2(math.log2(z)) / math.log2(2)
mandelbrot 集包含 mandelbrot 迭代有界的点,迭代点永远不会“逃逸”。 让我们将边界定义为点,其中迭代点在 N 次迭代后逃逸(逃逸我的意思是与原点的距离变得大于 2)。 是否可以保
我一直在做 Mandelbrot 集并尝试缩放,但缩放模式变得非常麻烦。当我缩放时,它会完美缩放,但图像尺寸会缩小到原始尺寸的一半。下次我再次缩放时,图片尺寸会增加并尝试跳过查看窗口。代码在 c++/
我目前正在编写一个程序来生成非常巨大的(65536x65536 像素及以上)Mandelbrot 图像,并且我想设计一个光谱和着色方案来使它们公平。 wikipedia featured mandel
谁能解释一下扰动是如何描述的in this paper加速渲染 Mandelbrot 集? 我知道如何使用对每个像素执行多次迭代的传统方法来渲染 Mandelbrot 集,但我不太明白那篇论文中描述的
这是我尝试使用 Pygame 模块在 Python 3.5 中编写 Mandelbrot 集。 import math, pygame pygame.init() def mapMandelbrot(
我正在使用 C 编写以下代码。到目前为止,它一直在工作,并且已缩放到正确的级别等,但是我正在努力让颜色按我想要的方式工作。理想情况下,无论颜色如何,我都希望得到这样的结果: 但是我的程序如下所示,目前
我可以生成从 minReal 到 maxReal 以及从 minImaginary 到 maxImaginary 的 Mandelbrot 集的 400x400 图像。所以, makeMandel(m
我正在编写绘制 Mandelbrot 集版本的代码。当它运行时,它接受两个输入 a 和 b,并将其转换为一个复数(例如 complex(a,b))。然后它绘制一个 Mandelbrot 集,其中 z
尝试使用与我在使用 TBB(线程构建块)运行时使用的代码相同的代码(有点)。 我对 OpenCL 没有太多经验,但我认为大部分主要代码是正确的。我相信错误在 .cl文件,它在那里进行数学运算。 这是我
我是一名优秀的程序员,十分优秀!