from __future__ import division from mpmath import odefun data = open( 'simo-initial-conditions.txt', 'r' ) c = [] for line in data: d = [ float(i) for i in line.split() ] c.append( [ d[0], d[1], d[2], d[3], d[4] ] ) data.close() for n in range( 1, 346 ): c1 = c[n-1][0] c2 = c[n-1][1] c3 = c[n-1][2] c4 = c[n-1][3] c5 = c[n-1][4] x1 = -2 * c1 y1 = 0 x2 = c1 y2 = c2 u1 = 0 v1 = -2 * c4 u2 = c3 v2 = c4 sol = odefun( lambda t, f: [ f[4], f[5], f[6], f[7], - ( f[0] - f[2] ) / 3 / pow( ( f[0] - f[2] )**2 + ( f[1] - f[3] )**2, 3/2 ) - ( 2*f[0] + f[2] ) / 3 / pow( ( 2*f[0] + f[2] )**2 + ( 2*f[1] + f[3] )**2, 3/2 ), - ( f[1] - f[3] ) / 3 / pow( ( f[0] - f[2] )**2 + ( f[1] - f[3] )**2, 3/2 ) - ( 2*f[1] + f[3] ) / 3 / pow( ( 2*f[0] + f[2] )**2 + ( 2*f[1] + f[3] )**2, 3/2 ), ( f[0] - f[2] ) / 3 / pow( ( f[0] - f[2] )**2 + ( f[1] - f[3] )**2, 3/2 ) - ( 2*f[2] + f[0] ) / 3 / pow( ( 2*f[2] + f[0] )**2 + ( 2*f[3] + f[1] )**2, 3/2 ), ( f[1] - f[3] ) / 3 / pow( ( f[0] - f[2] )**2 + ( f[1] - f[3] )**2, 3/2 ) - ( 2*f[3] + f[1] ) / 3 / pow( ( 2*f[2] + f[0] )**2 + ( 2*f[3] + f[1] )**2, 3/2 ) ], 0, [ x1, y1, x2, y2, u1, v1, u2, v2 ] ) l1, l2, l3 = [], [], [] step = .005 t = 0 while t < c5: p = [ round( float(k), 4 ) for k in sol(t) ] l1.append( [ p[0], p[1] ] ) l2.append( [ p[2], p[3] ] ) l3.append( [ round( -p[0]-p[2], 4 ), round( -p[1]-p[3], 4 ) ] ) t += step print 'Saving choreography ' + str(n) output = open( 'simo-integrate/' + str(n) + '.txt', 'w' ) if n in [ 5, 19, 20, 21 ]: output.write( str( [ l3, l1, l2 ] ) ) else: output.write( str( [ l3, l2, l1 ] ) ) output.close print 'Done'