0

私はPythonでジュリアセットを作ろうとしましたが、私の出力は初期のプロセスでNanです。何が原因かわかりません。告白のために言っておきますが、私のプログラミングのクラスは良くありません。自分が何をしているのかよくわかりません。これは主に、Google から学んだことによるものです。

コードは次のとおりです。

import matplotlib.pyplot as plt

c = complex(1.5,-0.6)
xli = []
yli = []
while True:
    z = c
    for i in range(1,101):
        if abs(z) > 2.0:
            break   
        z = z*z + c

    if i>0 and i <100:
        break

xi  = -1.24
xf = 1.4
yi = -2.9
yf = 2.1

#the loop for the julia set 
for k in range(1,51):
    x = xi + k*(xf-xi)/50   
    for n in range(51):
        y = yi + n*(yf-yi)/50
        z = z+ x + y* 1j 
        print z
        for i in range(51):
            z = z*z + c    #the error is coming from somewhere around here
            if abs(z) > 2:  #not sure if this is correct
                xli.append(x)
                yli.append(y)



plt.plot(xli,yli,'bo')
plt.show()      

print xli
print yli

前もって感謝します :)

4

1 に答える 1

1

告白のために: Julia セットや matplotlib については何も知りません。

pyplot は、解像度が低く、X と Y の横にあるベクトルとして色を指定できないという事実のため、奇妙な選択のようです。そして、書かれているとおりに機能して'bo'いれば、青い円のグリッドだけが生成されます。

実行可能と思われるものを選択したので、最初のwhile True:ループは必要ありませんc

これがあなたのコードの私のリワークです:

import matplotlib.pyplot as plt

c = complex(1.5, -0.6)

# image size
img_x = 100
img_y = 100

# drawing area
xi = -1.24
xf = 1.4
yi = -2.9
yf = 2.1

iterations = 8 # maximum iterations allowed (maps to 8 shades of gray)

# the loop for the julia set

results = {}  # pyplot speed optimization to plot all same gray at once

for y in range(img_y):
    zy = y * (yf - yi) / (img_y - 1)  + yi
    for x in range(img_x):
        zx = x * (xf - xi) / (img_x - 1)  + xi
        z = zx + zy * 1j
        for i in range(iterations):
            if abs(z) > 2:
                break
            z = z * z + c
        if i not in results:
            results[i] = [[], []]
        results[i][0].append(x)
        results[i][1].append(y)

for i, (xli, yli) in results.items():
    gray = 1.0 - i / iterations
    plt.plot(xli, yli, '.', color=(gray, gray, gray))

plt.show()      

出力

ここに画像の説明を入力

于 2016-05-04T22:12:26.130 に答える