Menu

[r8864]: / trunk / py4science / examples / glass_dots1_skel.py  Maximize  Restore  History

Download this file

81 lines (58 with data), 1.9 kB

 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
Moire patterns from random dot fields
http://en.wikipedia.org/wiki/Moir%C3%A9_pattern
See L. Glass. 'Moire effect from random dots' Nature 223, 578580 (1969).
"""
import cmath
import numpy as np
import numpy.linalg as linalg
import matplotlib.pyplot as plt
# search for TODO to find the places you need to fix
TODO = None
def myeig(M):
"""
compute eigen values and eigenvectors analytically
Solve quadratic:
lamba^2 - tau*lambda +/- Delta = 0
where tau = trace(M) and Delta = Determinant(M)
if M = | a b |
| c d |
the trace is a+d and the determinant is a*d-b*c
Return value is lambda1, lambda2
Return value is lambda1, lambda2
"""
# TODO : compute the real values here. 0, 1 is just a place holder
return 0, 1
# Generate and shape (2000,2) random x,y points in the
# interval [-0.5 ... 0.5]
X1 = TODO
# these are the scaling factor sx, the scaling factor sy, and the
# rotation angle 0
name = 'saddle'
sx, sy, angle = 1.05, 0.95, 0.
# OPTIONAL: try and find other sx, sy, theta for other kinds of nodes:
# stable node, unstable node, center, spiral, saddle
# convert theta to radians: theta = angle * pi/180
theta = TODO
# Create a 2D scaling array
# S = | sx 0 |
# | 0 sy |
S = TODO
# create a 2D rotation array
# R = | cos(theta) -sin(theta) |
# | sin(theta) cos(theta) |
R = TODO
# do a matrix multiply M = S x R where x is *matrix* multiplication
M = TODO
# compute the eigenvalues using numpy linear algebra
vals, vecs = linalg.eig(M)
print 'numpy eigenvalues', vals
# compare with the analytic values from myeig
avals = myeig(M)
print 'analytic eigenvalues', avals
# transform X1 by the matrix
# X2 = M x X1 where x is *matrix* multiplication
X2 = np.dot(M, X1)
# plot the original x,y as green dots and the transformed x, y as red
# dots
TODO
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.