【Python】科学计算(一)——Mandelbrot集合
来源:互联网 发布:网络执法官3.56破解版 编辑:程序博客网 时间:2024/06/10 22:11
一. 分形与混沌
自然界的很多事物,如树木、云彩、山脉、雪花、海岸线等,都呈现出传统几何学所不能描述的形状,这些形状都有如下的特性:
- 有着十分精细的不规则结构
- 整体与局部相似
二. Mandelbrot集合
Mandelbrot(曼德布洛特)集合是在复平面上组成分形的点的集合。Mandelbrot集合可以用下面的复二次多项式定义:
其中c是一个复数。对于每一个c,从z=0开始对函数进行迭代。序列的值或者延伸到无限大,或者只停留在有限半径的圆盘内。Mandelbrot集合就是使以上序列不发散的所有c点的集合。用程序绘制Mandelbrot集合时不能进行无限次迭代,最简单的方法是使用逃逸时间(迭代次数)进行绘制,具体算法如下:
- 判断每次调用函数得到的结果是否在半径R之内,即复数的模小于R
- 记录下模大于R时的迭代次数
- 迭代最多进行N次
- 不同的迭代次数的点使用不同的颜色绘制
三. Mandelbrot程序
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import
numpy as np
import
pylab as pl
import
time
from
matplotlib
import
cm
def
iter_point(c):
z
=
c
for
i
in
xrange
(
1
,
100
):
if
abs
(z)>
2
:
break
z
=
z
*
z
+
c
return
i
def
draw_mandelbrot(cx,cy,d):
x0,x1,y0,y1
=
cx
-
d,cx
+
d,cy
-
d,cy
+
d
y,x
=
np.ogrid[y0:y1:
200j
,x0:x1:
200j
]
c
=
x
+
y
*
1j
start
=
time.clock()
mandelbrot
=
np.frompyfunc(iter_point,
1
,
1
)(c).astype(np.
float
)
print
"time="
,time.clock()
-
start
pl.imshow(mandelbrot,cmap
=
cm.Blues_r,extent
=
[x0,x1,y0,y1])
pl.gca().set_axis_off()
x,y
=
0.27322626
,
0.595153338
pl.subplot(
231
)
draw_mandelbrot(
-
0.5
,
0
,
1.5
)
for
i
in
range
(
2
,
7
):
pl.subplot(
230
+
i)
draw_mandelbrot(x,y,
0.2
*
*
(i
-
1
))
pl.subplots_adjust(
0.02
,
0
,
0.98
,
1
,
0.02
,
0
)
pl.show()
参考文献:
1. 用Python做科学计算
0 0
- 【Python】科学计算(一)——Mandelbrot集合
- python科学计算一:pandas
- Python科学计算(一)
- 【Python】科学计算环境 —— Anaconda
- Python科学计算环境——Anaconda
- Python科学计算——Numpy知识点
- Python科学计算——使用Anaconda
- python科学计算——pandas
- Python科学计算发行版—Anaconda
- 【Python】一、部分IDE和软件包介绍——《用Python做科学计算》
- python 科学计算Numpy的自学(一)
- Python科学计算-----NumPy(一)
- Python科学计算环境简介——Anaconda Python
- Python科学计算环境简介——Anaconda Python
- 【Python】二、Numpy——《用Python做科学计算》
- 【Python】三、Scipy——《用Python做科学计算》
- 【Python】四、Sympy——《用Python做科学计算》
- 【Python】五、Matplotlib——《用Python做科学计算》
- leetcode_num168&171_excel title&number
- Simple_Wallet 在服务器端通过RPC操纵钱包
- 函数对象
- Linux系统cpuinfo详解
- Google Hosts
- 【Python】科学计算(一)——Mandelbrot集合
- Configuration(AnnotationConfiguration)
- 深入浅出的讲解傅里叶变换(2)
- pow函数总结
- HDU 1012 u Calculate e
- 泛型参数Generic
- android开发ViewPager按比例显示图片(显示下一张图片的一部分)
- Andorid-15k+的面试题
- String,StringBuffer与StringBuilder的区别??