Fractal Picture With Newton-Raphson

  1. # -*- coding: utf-8 -*-
  2. '''
  3. calculate the root of f=z**3-1 and plot fractal picture
  4. with  Newton-Raphson method
  5. '''
  6. import matplotlib.pyplot as plt
  7. import time
  8. start=time.time()
  9. X1,X2,X3,Y1,Y2,Y3=[],[],[],[],[],[]
  10. a=1.732  #np.sqrt(3)
  11. z=-1-1j
  12. #Newton-Raphson
  13. for i in range(0,2000):
  14.     z=z+0.001-z.imag*1j-1j
  15.     for j in range(0,2000):
  16.         z=z+0.001j
  17.         r=z
  18.         for k in range(0,15):
  19.             r2=r-(r**3-1)/(3*r*r)
  20.             r=r2
  21.             
  22.         if abs(r-1)<0.0001:
  23.             X1[len(X1):]=[z.real]
  24.             Y1[len(Y1):]=[z.imag]
  25.         elif abs(r+1/2-a/2*1j)<0.0001:
  26.              X2[len(X2):]=[z.real]
  27.              Y2[len(Y2):]=[z.imag]
  28.         elif abs(r+1/2+a/2*1j)<0.0001:
  29.              X3[len(X3):]=[z.real]
  30.              Y3[len(Y3):]=[z.imag]
  31.              
  32. plt.figure('frctal')
  33. plt.plot(X1,Y1,'r.',X2,Y2,'b.',X3,Y3,'g.')
  34. plt.show()
  35. stop=time.time()
  36. print("time=",stop-start)


  
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值