-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPyLagrange.py
More file actions
137 lines (111 loc) · 3.76 KB
/
PyLagrange.py
File metadata and controls
137 lines (111 loc) · 3.76 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import os
import subprocess
import PyGnuplot as gp
import time
##################################################################################################################################################
M1=str(input('Masa del primer objeto: '))
M2=str(input('Masa del segundo objeto: '))
color=str(input('Color: [v]erde, [r]ojo, [a]zul:'))
if color=='v':
chcolor='ylgn'
chline=str(2)
elif color=='r':
chcolor='ylorbr'
chline=str(4)
elif color=='a':
chcolor='gnbu'
chline=str(3)
else:
chcolor='ylorbr'
chline=str(4)
###keywords para cambiar en el doc
kw1='inputM1\n'
kw2='inputM2\n'
kwCline='Cline\n'
###abrir doc original, crear uno a partir de este
XZinput=open("2D.gp","r")
XZoutput=open("output/2DPyOut.gp","w")
#guardar el documento como lista de strings
XZstrList=XZinput.readlines()
#leer lista y remplazar los valores donde hay keywords
for i in range(len(XZstrList)):
if kw1 == XZstrList[i]:
XZstrList[i]=str('M1='+M1+'\n')
if kw2 == XZstrList[i]:
XZstrList[i]=str('M2='+M2+'\n')
if kwCline == XZstrList[i]:
XZstrList[i]=str('plot f(x) t \'V\' ls '+chline+'\n')
if i!=2 and i!=3:
gp.c(XZstrList[i])
##crear el documento nuevo y cerrar ambos
XZoutput.writelines(XZstrList)
XZinput.close()
XZoutput.close()
time.sleep(0.5)
print('De la gráfica localice los tres máximos y computelos: \n')
xA=(str(input('Posición x del primer máximo: ')))
xB=(str(input('Posición x del segundo máximo: ')))
xC=(str(input('Posición x del tercer máximo: ')))
#keywords
kwA='inputxA\n'
kwB='inputxB\n'
kwC='inputxC\n'
kwColor='Cpalette\n'
###abrir doc original, crear uno a partir de este
Dinput=open("Potencial3DconVerticales.gp","r")
Doutput=open("output/3DPyOut.gp","w")
#guardar el documento como lista de strings
DstrList=Dinput.readlines()
#leer lista y remplazar los valores donde hay keywords
for i in range(len(DstrList)):
if kw1 == DstrList[i]:
DstrList[i]=str('M1='+M1+'\n')
if kw2 == DstrList[i]:
DstrList[i]=str('M2='+M2+'\n')
if kwA == DstrList[i]:
DstrList[i]=str('xA='+xA+'\n')
if kwB == DstrList[i]:
DstrList[i]=str('xB='+xB+'\n')
if kwC == DstrList[i]:
DstrList[i]=str('xC='+xC+'\n')
if kwColor == DstrList[i]:
DstrList[i]=str('load \'../'+chcolor+'.pal\''+'\n')
##crear el documento nuevo y cerrar ambos
Doutput.writelines(DstrList)
Dinput.close()
Doutput.close()
###abrir doc original, crear uno a partir de este
Mapinput=open("PotencialMap.gp","r")
Mapoutput=open("output/MapPyOut.gp","w")
#guardar el documento como lista de strings
MapstrList=Mapinput.readlines()
#leer lista y remplazar los valores donde hay keywords
for i in range(len(MapstrList)):
if kw1 == MapstrList[i]:
MapstrList[i]=str('M1='+M1+'\n')
if kw2 == MapstrList[i]:
MapstrList[i]=str('M2='+M2+'\n')
if kwA == MapstrList[i]:
MapstrList[i]=str('xA='+xA+'\n')
if kwB == MapstrList[i]:
MapstrList[i]=str('xB='+xB+'\n')
if kwC == MapstrList[i]:
MapstrList[i]=str('xC='+xC+'\n')
if kwColor == MapstrList[i]:
MapstrList[i]=str('load \'../'+chcolor+'.pal\''+'\n')
##crear el documento nuevo y cerrar ambos
Mapoutput.writelines(MapstrList)
Mapinput.close()
Mapoutput.close()
x1=float(M2)/(float(M2)+float(M1))
x2=x1-1
p=str((x1+x2)/2)
Data=open("output/Puntos.dat","w")
Data.writelines([xA+',0\n',xB+',0\n',xC+',0\n','-'+p+',0.866\n',p+',0.866\n'])
Data.close()
print('Los putos de Lagrange están aproximadamente en:')
print(xA+',0\n'+xB+',0\n'+xC+',0\n'+'-'+p+',0.866\n'+p+',0.866\n')
process1 = subprocess.Popen("cd output/ \n gnuplot 2DPyOut.gp 3DPyOut.gp MapPyOut.gp", shell = True)
os.waitpid(process1.pid, 0)
process2 = subprocess.Popen("cd output/ \n eog Map.png", shell= True)
os.waitpid(process2.pid, 0)