El programa siguiente nos sirve para resolver problemas de estadística relacionados al censo de resistencias generadas por una planta y así verificar si se producen los valores correctos. El código contiene comentarios destinados a explicar partes especificas y funciones del programa. Se incluyen dos ejemplos resueltos con el programa, al igual que sus gráficas descriptivas.
from pylab import *
#SE INGRESAN LOS VALORES DE MUESTRA Y LECTURA (estos determinan los limites para los ciclos siguientes)
nm=int(input("Numero de muestras: "))
nl=int(input("Numero de lecturas: "))
#SE DECLARAN LISTAS Y VARIABLES PERTINENTES AL CODIGO
r=0
may=0
mini=10000000000
col=0
suma=0
prom=0
rang=0
sump=0
sumr=0
lp=[ ]
lr=[ ]
a=[ ]
b=[ ]
#EL PRIMER CICLO Y SU SEGUNDO ANIDADO SE ENCARGA DE LLENAR LAS LISTAS CON LOS DATOS QUE INGRESA EL USUARIO
for r in range(nm):
print("{}a muestra: ".format(r+1))
for col in range(nl):
t=float(input("\t"))
#EL PAR DE IF'S NOS AYUDA A OBTENER EL VALOR MAXIMO Y MINIMO DE CADA TOMA DE LECTURAS
if(t>may):
may=t
elif(t<mini):
mini=t
a.append(t)
suma+=int(t)
t=0
#DENTRO DEL MISMO CICLO PODEMOS REALIZAR OPERACIONES QUE NOS SIRVEN PARA LAS FUTURAS FORMULAS
#TAMBIEN APROVECHAMOS LA OPORTUNIDAD PARA REINICIAR LOS VARIABLES DE CADA MUESTRA
prom=(suma)/nl
lp.append(prom)
sump+=prom
rang=abs((may)-(mini))
lr.append(rang)
sumr+=rang
a.append(prom)
a.append(rang)
b.append(a)
a=[ ]
suma=0
prom=0
rang=0
may=0
mini=10000000000
#LAS TUPLAS SIGUIENTES REPRESENTAN LA TABLA DE VALORES CORRESPONDIENTE AL NUMERO DE LECTURAS
A2=(0, 0, 1.880, 1.023, 0.729, 0.577, 0.483, 0.419, 0.373, 0.377, 0.308, 0.285, 0.266, 0.249, 0.235, 0.223)
D3=(0, 0, 0, 0, 0, 0, 0, 0.076, 0.136, 0.184, 0.223, 0.256, 0.284, 0.308, 0.329, 0.348)
D4=(0, 0, 3.268, 2.574, 2.282, 2.114, 2.004, 1.924, 1.864, 1.816, 1.777, 1.744, 1.717, 1.692, 1.671, 1.652)
D2=(0, 0, 1.128, 1.693, 2.059, 2.326, 2.534, 2.704, 2.847, 2.970, 3.078, 3.173, 3.258, 3.336, 3.407, 3.472)
#DECLARAMOS LAS VARIABLES QUE TOMARAN UN VALOR DE LA TUPLA
p=0
a2=0
d3=0
d4=0
d2=0
#ESTE CICLO SOLO ES PARA OTORGAR EL VALOR A LOS VARIABLES POR PARTE DE LAS TUPLAS
for p in range(nl):
a2=A2[p]
d3=D3[p]
d4=D4[p]
d2=D2[p]
#A CONTINUACION SE ENCUENTRAN LAS OPERACIONES DE PROMEDIO, LCI, LCS
i=0
promp=(sump)/nm
promr=(sumr)/nm
LCIP=promp-(a2*promr)
LCSP=promp+(a2*promr)
LCIR=d3*promr
LCSR=d4*promr
#ESTAS LISTAS VACIAS SE LLENARAN CON VALORES DE PROMEDIO, LCI, LCS PARA SU GRAFICACION
pp=[ ]
pr=[ ]
lcip=[ ]
lcsp=[ ]
lcir=[ ]
lcsr=[ ]
#ESTE CICLO LE OTORGA A LAS LISTAS EL MISMO VALOR VARIABLE MULTIPLES VECES PARA SU GRAFICACION
for i in range(nm):
pp.append(promp)
pr.append(promr)
lcip.append(LCIP)
lcir.append(LCIR)
lcsp.append(LCSP)
lcsr.append(LCSR)
#LO SIGUIENTE IMPRIME LOS VALORES DADOS Y ADQUIRIDOS PREVIAMENTE
print("\n\n\n")
print("\tNo muestra\t\tLecturas (En OHMS)\t\tPromedio\tRango")
for r in range(nm):
print("\t%.4f"%(r+1), end="\t\t")
for col in range(nl):
print(b[r][col], end="\t")
for col in range(2):
print("\t%.4f"%(b[r][col+nl]), end="\t")
print()
print("\t\t\t\t\t\t\tProm\t%.4f\t\t%.4f"%(promp,promr))
print("\t\t\t\t\t\t\tLCS\t%.4f\t\t%.4f"%(LCSP,LCSR))
print("\t\t\t\t\t\t\tLCI\t%.4f\t\t%.4f"%(LCIP,LCIR))
#POR ULTIMO SE GRAFICAN LOS RESULTADOS
plt.title("Promedios")
plt.grid(True)
plt.plot(lp,label="Promedios",marker='^')
plt.plot(pp,label="Promedio",marker='o')
plt.plot(lcsp,label="LCS",marker='*')
plt.plot(lcip,label="LCI",marker='p')
plt.legend()
plt.show()
plt.title("Rangos")
plt.grid(True)
plt.plot(lr,label="Rangos",marker='x')
plt.plot(pr,label="Promedio",marker='p')
plt.plot(lcsr,label="LCS",marker='^')
plt.plot(lcir,label="LCI",marker='*')
plt.legend()
plt.show()
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Ejemplo 1
Ejemplo 2








Comentarios
Publicar un comentario