In [2]:
def dist(points):
    """
    Calculates the geometric mean of the distances between a given set of points on the line segment [-1, 1].
    
    Input: List of points on real line.
    Output: The nth diameter using the Fekete point system.
    Calculates: [PI(|x_j - x_k|)]^[2/n(n-1)], where 1 <= j < k <= n.
    Note: must be a minimum of three points.
    """
    product = 1.0
    exponent = 2.0/(len(points)*(len(points) - 1))
    for i in range(len(points)):
        for j in range(i + 1, len(points)):
            product *= abs(points[i] - points[j])
    return product**exponent

In [3]:
def grid(step):
    """
    Generates a grid of potential landing spots for Fekete points on interval (-1, 1)
    
    """
    gridpts = list()
    if step%2 != 0:
        step +=1
    for i in range(step + 1):
        gridpts.append(-1.0 + (2.0*i)/step)
    return gridpts

In [4]:
import itertools

In [5]:
def fekete(step, numpts):
    possibilities = list(itertools.combinations(grid(step), numpts))
    distanceList = list()
    for i in range(len(possibilities)):
        distanceList.append(dist(possibilities[i]))
    winner = possibilities[distanceList.index(max(distanceList))]
    maxdist = max(distanceList)
    print 'Points: '
    print winner
    print '\nMaximum Distance: '
    print maxdist
    print '\n\n'

In [6]:
for i in range(3, 10):
    print 'Number of points: ', i
    print 'Grid Points: 25'
    fekete(25, i)


Number of points:  3
Grid Points: 25
Points: 
(-1.0, 0.0, 1.0)

Maximum Distance: 
1.25992104989



Number of points:  4
Grid Points: 25
Points: 
(-1.0, -0.46153846153846156, 0.46153846153846145, 1.0)

Maximum Distance: 
1.02258549239



Number of points:  5
Grid Points: 25
Points: 
(-1.0, -0.6923076923076923, 0.0, 0.6153846153846154, 1.0)

Maximum Distance: 
0.903000502221



Number of points:  6
Grid Points: 25
Points: 
(-1.0, -0.7692307692307692, -0.3076923076923077, 0.3076923076923077, 0.7692307692307692, 1.0)

Maximum Distance: 
0.832476873355



Number of points:  7
Grid Points: 25
Points: 
(-1.0, -0.8461538461538461, -0.46153846153846156, 0.0, 0.46153846153846145, 0.8461538461538463, 1.0)

Maximum Distance: 
0.783925021675



Number of points:  8
Grid Points: 25
Points: 
(-1.0, -0.8461538461538461, -0.6153846153846154, -0.23076923076923073, 0.15384615384615374, 0.5384615384615385, 0.8461538461538463, 1.0)

Maximum Distance: 
0.747127463252



Number of points:  9
Grid Points: 25
Points: 
(-1.0, -0.9230769230769231, -0.6923076923076923, -0.3846153846153846, 0.0, 0.3846153846153846, 0.6923076923076923, 0.9230769230769231, 1.0)

Maximum Distance: 
0.721148624314




In [ ]: