3
私はこのalgorithmをクロージャに移植しようとしています。Clojure/Java Mandelbrotフラクタル描画
私のコードは
(defn calc-iterations [x y]
(let [c (struct complex x y)]
(loop [z (struct complex 0 0)
iterations 0]
(if (and (< 2.0 (abs z))
(> max-iterations iterations))
iterations
(recur (add c (multiply z z)) (inc iterations))))))
で乗算、加算およびABS関数は、彼らが必要として働いています。私は電卓でそれらをテストしました。ただし、次の値のために:
(calc-iterations 0.60703135 -0.33984375) ; should give me 2, instead I get 4
(calc-iterations -1.8421874 0.3515625) ; should give me 1, instead I get 3
私はネット上で見つけた別のJavaアプレットを使用して、正しい反復数をチェックしています。それは正しい出力を生成するので動作しているようです。その反復関数は
protected int calcIterations(float x, float y) {
int iterations = 0;
float xn = x, yn = y;
while (iterations < MAX_ITERATIONS) {
float xn1 = xn*xn - yn*yn;
float yn1 = 2*xn*yn;
xn = xn1 + x;
yn = yn1 + y;
float magsq = xn*xn + yn*yn;
if (magsq > 4)
break;
iterations++;
}
System.out.println(x + " " + y + " " + iterations);
return iterations;
}
私のエラーになりますか?