This is a simple problem to keep the posting rhythm.
Given an array a of N elements, we keep fixed the first element at 0.0 and the last element at 1.0, while all the other elements are initialized to 0.5. In each time step, all the element in the middle of the array are set to the average of their adjacent elements.
For example, if we have N = 4,
[0.0, 0.5, 0.5, 1.0] # Initialization [0.0, 0.25, 0.75, 1.0] # After first step [0.0, 0.375, 0.675, 1.0] # After second step ...
We can easily express it in numpy:
import numpy as np N = 4 S = 10 a = 0.5 * np.ones(N) a[0] = 0.0 a[-1] = 1.0 print a for i in xrange(S): a[1:-1] = 0.5 * (a[:-2] + a[2:]) print a
The three questions are:
- Does the array converge to a limit?
- If it does, does it depend on its initial values?
- Assuming it converges and given a tolerance
, how many steps does it take to get to a distance
of the limit?
Answers in the next post.