# Direct surface.py

(Difference between revisions)
 Revision as of 21:20, 22 September 2015Werner (Talk | contribs)← Previous diff Revision as of 21:41, 22 September 2015Werner (Talk | contribs) Next diff → Line 1: Line 1: + This page presents the program markov_disks_box.py, a Markov-chain algorithm for four disks in a square box of sides 1. + + __FORCETOC__ + =Description= + + =Program= + + import random + + L = [[0.25, 0.25], [0.75, 0.25], [0.25, 0.75], [0.75, 0.75]] + sigma = 0.15 + sigma_sq = sigma ** 2 + delta = 0.1 + n_steps = 1000 + for steps in range(n_steps): + a = random.choice(L) + b = [a + random.uniform(-delta, delta), a + random.uniform(-delta, delta)] + min_dist = min((b - c) ** 2 + (b - c) ** 2 for c in L if c != a) + box_cond = min(b, b) < sigma or max(b, b) > 1.0 - sigma + if not (box_cond or min_dist < 4.0 * sigma ** 2): + a[:] = b + print L + + =Version= + See history for version information. + + [[Category:Python]] + import random, math import random, math

## Revision as of 21:41, 22 September 2015

This page presents the program markov_disks_box.py, a Markov-chain algorithm for four disks in a square box of sides 1.

# Program

```import random

L = [[0.25, 0.25], [0.75, 0.25], [0.25, 0.75], [0.75, 0.75]]
sigma = 0.15
sigma_sq = sigma ** 2
delta = 0.1
n_steps = 1000
for steps in range(n_steps):
a = random.choice(L)
b = [a + random.uniform(-delta, delta), a + random.uniform(-delta, delta)]
min_dist = min((b - c) ** 2 + (b - c) ** 2 for c in L if c != a)
box_cond = min(b, b) < sigma or max(b, b) > 1.0 - sigma
if not (box_cond or min_dist < 4.0 * sigma ** 2):
a[:] = b
print L
```

# Version

See history for version information.

```import random, math

dimensions = 5
nsamples = 20
for sample in xrange(nsamples):
R = [random.gauss(0.0, 1.0) for d in xrange(dimensions)]
radius = math.sqrt(sum(x ** 2 for x in R))
print [x / radius for x in R]
```