Mediante *Formula de Rydberg* es posible calcular la longitud de onda de las líneas del espectro del átomo de hidrógeno
$$\frac{1}{λ}=R( \frac{1}{m^2}-\frac{1}{n^2} )$$R es la constante de Rydberg $R=1.097 × 10^{-2} nm^{-1}$. Debe considerarse que $n>m$, los valores de m (1,2,3) son conocidos como series de Lyman, Balmer y Pashen.
Realice un programa para que imprima las primeras 5 longitudes de onda de cada una de las series.
Crédito : tbd
#1
R=1.097e-2
for m in [1,2,3]:
if m==1:
print("Series de Lyman \n")
elif m==2:
print("\n Series de Balmer \n")
else:
print("\n Series de Pashen \n")
for k in [1,2,3,4,5]:
n=m+k
ilam=R*(1/m**2-1/n**2)
print (1/ilam)
Series de Lyman 121.5436037678517 102.55241567912488 97.23488301428137 94.95594044363415 93.76220862091418 Series de Balmer 656.3354603463993 486.1744150714068 434.084299170899 410.2096627164995 397.04243897498225 Series de Pashen 1875.2441724182836 1281.9051959890612 1093.8924339106654 1005.013673655424 954.6697605038536
#2
R=1.097e-2
for m in [1,2,3]:
print(m)
for n in range(m+1,m+6):
ilam=R*(1/m**2-1/n**2)
print (1/ilam)
1 121.5436037678517 102.55241567912488 97.23488301428137 94.95594044363415 93.76220862091418 2 656.3354603463993 486.1744150714068 434.084299170899 410.2096627164995 397.04243897498225 3 1875.2441724182836 1281.9051959890612 1093.8924339106654 1005.013673655424 954.6697605038536
La serie de taylor es un aproximación de una función real o compleja mediante la suma de potencias enteras de polinomios $(x-a)^n$ en un punto a dado. La función debe ser derivable y poder calcular la n-esima derivada de esta, entonces:
$$ f(a)+ \frac{f'(x)}{1!}(x-a) + \frac{f''(x)}{2!}(x-a)^2+ ...+ \frac{f^n(x)}{n!}(x-a)^n $$en notación compacta sería:
$$ \sum_{i=0}^\infty \frac{f^i(a)}{i!}(x-a)^i$$import matplotlib.pyplot as plt
import numpy as np
e=np.exp(1)
n=16
fac=1
suma=0
listan=[]
for i in range(n):
if i==0:
fac=1
else:
fac=fac*i
suma=suma+1/fac
listan.append(suma)
#print(i,fac,1/fac,suma)
plt.axhline(e,0,10,color="red")
#plt.yscale("log")
plt.semilogy(range(n),(e-listan),'.-')
[<matplotlib.lines.Line2D at 0x7c2364a9fd90>]
lfb=np.zeros([10])
lfb[1]=1
for i in range(len(lfb)-2):
lfb[i+2]=lfb[i]+lfb[i+1]
print(lfb)
print(type(lfb))
[ 0. 1. 1. 2. 3. 5. 8. 13. 21. 34.] <class 'numpy.ndarray'>
Son un conjunto de simbolos y reglas que permiten representar información numéricamente. Son generalmente posicionales, eso es, el simbolo tien distinto valor acorde a la posición respecto a una cifra.
*Sistema decimal*
Es un sistema posicional que representan como base el número diez y se compone de 10 dígitos distintos (0,1,2,3,4,5,6,7,8,9). La posición de derecha izquierda asocian unidaes, decenas, centenas, etc.
*Sistema binario*
Utiliza dos digitos (0,1) el valor de cada posición se obtiene de una potencia de base 2
*Conversión decimal a digital*
Para convertir un número decimal a binario se realiza la divisón sobre 2 mientras el valor sea diferente a 0. los residuos se toman en orden inverso para obtener la conversión a binario.
Ejemplo conversión decimal a binario del número 30
Número | División | Residuo |
---|---|---|
30 | 15 | 0 |
15 | 7 | 1 |
7 | 3 | 1 |
3 | 1 | 1 |
1 | 0 | 1 |
print (7/2, 7//2, 7%2 )
3.5 3 1
value=30
print("Número División Residuo")
while value//2 != 0:
print(f"{value:5} {value//2:6} {value%2:6d}")
value=value//2
print(f"{value:5} {value//2:6} {value%2:6d}")
Número División Residuo 30 15 0 15 7 1 7 3 1 3 1 1 1 0 1
import numpy as np
value=354224848179261915075
vb=[]
#print("Número División Residuo")
#print(f"{División:10} ==> {Residuo:10d}")
while value//2 != 0:
#print(f"{value:5} {value//2:6} {value%2:6d}")
vb.append(value%2)
value=value//2
#print(f"{value:5} {value//2:6} {value%2:6d}")
vb.append(value)
print(vb)
print(len(vb))
[1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1] 69
import numpy as np
value=120
vb=np.zeros(8)
i=0
while value//2 != 0:
vb[i]=value%2
value=value//2
i+=1
vb[i]=value%2
np.flip(vb)
array([0., 1., 1., 1., 1., 0., 0., 0.])
import numpy as np
for value in range(10):
vbn=np.zeros(8)
#value=3
i=7
while value//2 != 0:
vbn[i]=value%2
i=i-1
value=value//2
vbn[i]=value%2
print(vbn)
[0. 0. 0. 0. 0. 0. 0. 0.] [0. 0. 0. 0. 0. 0. 0. 1.] [0. 0. 0. 0. 0. 0. 1. 0.] [0. 0. 0. 0. 0. 0. 1. 1.] [0. 0. 0. 0. 0. 1. 0. 0.] [0. 0. 0. 0. 0. 1. 0. 1.] [0. 0. 0. 0. 0. 1. 1. 0.] [0. 0. 0. 0. 0. 1. 1. 1.] [0. 0. 0. 0. 1. 0. 0. 0.] [0. 0. 0. 0. 1. 0. 0. 1.]
import numpy as np
import matplotlib.pyplot as plt
n=8
lim=np.power(2,n)
A=[]
fc=1
for value in range(50):
vb=np.zeros(n*fc)
i=(n*fc) -1
value=value*fc
#print(value)
while value//2 != 0:
vb[i]=(value%2)
value=value//2
i=i-1
vb[i]=(value%2)
#print(vb)
A.append(vb)
A=np.array(A)
plt.imshow(A.transpose())
<matplotlib.image.AxesImage at 0x7e05f79efbd0>
i
-17
import matplotlib.pyplot as plt
a=277987987987
lista=[]
while a!=1:
lista.append(a)
if a%2==0:
a=a/2
else:
a=(a*3)+1
plt.semilogy(lista)
vmax=max(lista)
i=1
while np.power(2,i)<vmax:
i=i+1
print(i)
n=i
A=[]
j=i
for value in lista:
#print(value)
vb=np.zeros(n)
j=n-1
while value//2 != 0:
vb[j]=(value%2)
value=value//2
j=j-1
vb[j]=(value%2)
#print(value,vb)
A.append(vb)
A=np.array(A)
plt.figure()
plt.imshow(A.transpose())
41
<matplotlib.image.AxesImage at 0x7e05f7655ed0>
import matplotlib.pyplot as plt
a,b=0,1
lista=[]
for i in range(90):
lista.append(a)
a,b=b,a+b
plt.plot(lista)
vmax=max(lista)
i=1
while np.power(2,i)<vmax:
i=i+1
print(i)
n=i
A=[]
j=i
for value in lista:
#print(value)
vb=np.zeros(n)
j=n-1
while value//2 != 0:
vb[j]=(value%2)
value=value//2
j=j-1
vb[j]=(value%2)
#print(value,vb)
A.append(vb)
A=np.array(A)
plt.figure()
plt.imshow(A.transpose())
61
<matplotlib.image.AxesImage at 0x7e05f7bdcc90>
import numpy as np
import matplotlib.pyplot as plt
plt.subplots(figsize=(20, 15))
n=512
lim=np.power(2,n)
A=[]
vale=1
for j in range(200):
vb=np.zeros(n)
i=n-1
vale=vale*7+1
value=vale
#print(j,value)
while value//2 != 0:
vb[i]=(value%2)
value=value//2
i=i-1
vb[i]=(value%2)
#print(vb)
A.append(vb)
A=np.array(A)
plt.imshow(A.transpose())
<matplotlib.image.AxesImage at 0x7e05d3ae13d0>
unos[:,3]=5
plt.matshow(unos,cmap="hot")
plt.colorbar()
<matplotlib.colorbar.Colorbar at 0x7e05d370ae90>
unos[:,3]=5
plt.matshow(unos,cmap="hot",interpolation='gaussian')
plt.colorbar()
<matplotlib.colorbar.Colorbar at 0x7e05d3783cd0>
import matplotlib.pyplot as plt
import numpy as np
ncx=200
ncy=500
A=np.zeros([ncx,ncy])
A[0,(ncy//2)]=1
#A[0,(nc//2)//2]=1
#A[0,(nc//2)//2+(nc//2)]=1
print(A)
for i in range(1,ncx):
for j in range(1,ncy-1):
if A[i-1,j-1] ==0 and A[i-1,j] ==0 and A[i-1,j+1] ==0: A[i,j]=1 # 000 - 1
elif A[i-1,j-1] ==0 and A[i-1,j] ==0 and A[i-1,j+1] ==1: A[i,j]=0 # 001 - 0
elif A[i-1,j-1] ==0 and A[i-1,j] ==1 and A[i-1,j+1] ==0: A[i,j]=1 # 010 - 1
elif A[i-1,j-1] ==0 and A[i-1,j] ==1 and A[i-1,j+1] ==1: A[i,j]=0 # 011 - 0
elif A[i-1,j-1] ==1 and A[i-1,j] ==0 and A[i-1,j+1] ==0: A[i,j]=1 # 100 - 1
elif A[i-1,j-1] ==1 and A[i-1,j] ==0 and A[i-1,j+1] ==1: A[i,j]=0 # 101 - 0
elif A[i-1,j-1] ==1 and A[i-1,j] ==1 and A[i-1,j+1] ==0: A[i,j]=0 # 110 - 0
else: A[i,j]=1 # 111 - 1
plt.matshow(A)
[[0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.] ... [0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.]]
<matplotlib.image.AxesImage at 0x7c07ac737f90>
import numpy as np
lista=np.zeros(10)
print(lista)
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams["figure.figsize"] = (15,10)
nc=400
A=np.zeros([nc,nc])
A[0,(nc//2)]=1
#A[0,(nc//2)//2]=1
#A[0,(nc//2)//2+(nc//2)]=1
value=30 #22, 124, 126, 200
vb=np.zeros(8)
j=0
while value//2 != 0:
vb[j]=(value%2)
value=value//2
j=j+1
vb[j]=(value%2)
for i in range(1,nc-1):
for j in range(1,nc-1):
if A[i-1,j-1] ==0 and A[i-1,j] ==0 and A[i-1,j+1] ==0: A[i,j]= vb[0]
elif A[i-1,j-1] ==0 and A[i-1,j] ==0 and A[i-1,j+1] ==1: A[i,j]=vb[1]
elif A[i-1,j-1] ==0 and A[i-1,j] ==1 and A[i-1,j+1] ==0: A[i,j]=vb[2]
elif A[i-1,j-1] ==0 and A[i-1,j] ==1 and A[i-1,j+1] ==1: A[i,j]=vb[3 ]
elif A[i-1,j-1] ==1 and A[i-1,j] ==0 and A[i-1,j+1] ==0: A[i,j]=vb[4]
elif A[i-1,j-1] ==1 and A[i-1,j] ==0 and A[i-1,j+1] ==1: A[i,j]=vb[5]
elif A[i-1,j-1] ==1 and A[i-1,j] ==1 and A[i-1,j+1] ==0: A[i,j]=vb[6]
else: A[i,j]= vb[7]
plt.matshow(A)
<matplotlib.image.AxesImage at 0x7c07819bac10>
(imagen tomada de Wikipedia)
vb[3]
1.0
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams["figure.figsize"] = (15,10)
fig, axs = plt.subplots(4,4,subplot_kw={'xticks': [], 'yticks': []})
lmaps=[]
for im in range(15,32):
nc=400 #tamaño de la matriz
A=np.zeros([nc,nc])
A[0,(nc//2)]=1 #un 1 en el centro de la primer renglon
#A[0,(nc//2)//2]=1
#A[0,(nc//2)//2+(nc//2)]=1
value=30 #22, 124, 126, 200
value=im
vb=np.zeros(8)
j=0
while value//2 != 0:
vb[j]=(value%2)
value=value//2
j=j+1
vb[j]=(value%2)
for i in range(1,nc-1):
for j in range(1,nc-1):
if A[i-1,j-1] ==0 and A[i-1,j] ==0 and A[i-1,j+1] ==0: A[i,j]= vb[0]
elif A[i-1,j-1] ==0 and A[i-1,j] ==0 and A[i-1,j+1] ==1: A[i,j]=vb[1]
elif A[i-1,j-1] ==0 and A[i-1,j] ==1 and A[i-1,j+1] ==0: A[i,j]=vb[2]
elif A[i-1,j-1] ==0 and A[i-1,j] ==1 and A[i-1,j+1] ==1: A[i,j]=vb[3 ]
elif A[i-1,j-1] ==1 and A[i-1,j] ==0 and A[i-1,j+1] ==0: A[i,j]=vb[4]
elif A[i-1,j-1] ==1 and A[i-1,j] ==0 and A[i-1,j+1] ==1: A[i,j]=vb[5]
elif A[i-1,j-1] ==1 and A[i-1,j] ==1 and A[i-1,j+1] ==0: A[i,j]=vb[6]
else: A[i,j]= vb[7]
lmaps.append(A)
lmaps=np.array(lmaps)
z=0
for i in range(4):
for j in range(4):
axs[i,j].matshow(lmaps[z])
z=z+1
La indexación y la segmentación (Indexing and Slicing) en Numpy
indexación: Se selecciona solo un elemento
segmentación: seleccion un rango o secuenciad de elementos
Una dimensión
a[i] Selecciona un solo elemento ubicado en el i-ésimo lugar (índice i), i es un entero, en la mayoria de los lenguajes se empieza a contar desde 0.
a[-i] Selecciona un solo elemento ubicado en el i-ésimo lugar, desde el final del arreglo, i es un entero y empieza en 1. El último elemento de la matriz se puede obtener con el valor de i=-1 (a[-1]) el penúltimo con i=-2 (a[-2]) y así sucesivamente.
-a[m:n]Selecciona todos los elementos entre el valor m y el valor n-1 (m,n son enteros).
-a[:n] Selecciona todos los elementos empezando en el índice 0 hasta n-1. -a[m:] Selecciona todos los elementos empezando en el índice m hasta el último elemento. -a[m:n:p] Selecciona todos los elementos empezando en el índice 0 hasta n exclisivo con incrementos de p. -a[::-1] Selecciona todos los elementos y los pone en orden inverso.
Se aplican las misma operaciones que en la de una dimensión, el resultado es una matriz reducida
import numpy as np
a=np.random.randint(1, 100, (15))
print(a)
print (a[1])
print(a[-3])
print(a[2:10])
print(a[:])
print(a[:7])
print(a[9:])
print(a[3:14:3])
print(a[::-1])
[43 85 71 7 42 97 45 66 42 3 18 56 57 68 94] 85 57 [71 7 42 97 45 66 42 3] [43 85 71 7 42 97 45 66 42 3 18 56 57 68 94] [43 85 71 7 42 97 45] [ 3 18 56 57 68 94] [ 7 45 3 57] [94 68 57 56 18 3 42 66 45 97 42 7 71 85 43]
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = (15,10)
fig, (ax1, ax2, ax3) = plt.subplots(1, 3)
siz=5
unos=np.zeros([siz,siz])
ax1.set_title("matriz original")
ax2.set_title("valor de 10 a la columna 2")
ax3.set_title("valor de 10 al renglon 2")
ax1.matshow(unos)
unos[:,2]=10
ax2.matshow(unos)
unos=np.zeros([siz,siz])
unos[2,:]=2
ax3.matshow(unos)
<matplotlib.image.AxesImage at 0x797e4cb23110>
f = lambda m, n: n + 10 * m
A = np.fromfunction(f, (6, 6), dtype=int)
plt.rcParams["figure.figsize"] = (15,10)
fig, (ax1, ax2, ax3) = plt.subplots(1, 3)
vx = np.zeros((3,4,4))
vx[1,:,:]=10
vx[1,1:3:,1:3]=5
vx[1,1,2]=1
vx[1,2,2]=1
print(vx)
ax1.set_title("plano zx")
ax2.set_title("plano xy")
ax3.set_title("plano zy")
ax1.imshow(vx[:,1,:])
ax2.imshow(vx[1,:,:])
ax3.imshow(vx[:,:,2])
[[[ 0. 0. 0. 0.] [ 0. 0. 0. 0.] [ 0. 0. 0. 0.] [ 0. 0. 0. 0.]] [[10. 10. 10. 10.] [10. 5. 1. 10.] [10. 5. 1. 10.] [10. 10. 10. 10.]] [[ 0. 0. 0. 0.] [ 0. 0. 0. 0.] [ 0. 0. 0. 0.] [ 0. 0. 0. 0.]]]
nc=6
A=np.zeros([nc,nc])
for i in range(nc):
for j in range(nc):
A[i,j]=i*2+j
print(A)
#print("*"*30)
#print(A[0,:])
#print("*"*30)
#print(A[:,2])
#print("*"*30)
print(A[0:3,0:3])
print(A[0:3,1:4])
print(A[0:3,2:5])
print(A[0:3,3:6])
print(A[1:4,0:3])
print(A[3:6,3:6])
[[ 0. 1. 2. 3. 4. 5.] [ 2. 3. 4. 5. 6. 7.] [ 4. 5. 6. 7. 8. 9.] [ 6. 7. 8. 9. 10. 11.] [ 8. 9. 10. 11. 12. 13.] [10. 11. 12. 13. 14. 15.]] [[0. 1. 2.] [2. 3. 4.] [4. 5. 6.]] [[1. 2. 3.] [3. 4. 5.] [5. 6. 7.]] [[2. 3. 4.] [4. 5. 6.] [6. 7. 8.]] [[3. 4. 5.] [5. 6. 7.] [7. 8. 9.]] [[2. 3. 4.] [4. 5. 6.] [6. 7. 8.]] [[ 9. 10. 11.] [11. 12. 13.] [13. 14. 15.]]
import matplotlib.pyplot as plt
import numpy as np
nc=1000
radio=70
A=np.zeros([nc,nc])
ca=nc//2
#plt.matshow(A,cmap="grey")
for i in range(nc):
for j in range(nc):
if (i-ca)**2+(j-ca)**2 <= radio**2:
A[i,j]+=10
if (i-(ca-50))**2+(j-(ca-50))**2 <= radio**2:
A[i,j]+=20
plt.matshow(A,cmap="grey")
<matplotlib.image.AxesImage at 0x7a4744716e90>
from types import new_class
import numpy as np
nc=6
a=np.zeros([nc,nc])
for i in range(nc):
for j in range(nc):
a[i,j]=i*2+j
print(a)
gf=np.array([[1,1,1],[1,5,1],[1,1,1]])
for i in range(1,nc-1):
for j in range(1,nc-1):
print(i,j, i-1,i+2 , j-1,j+2)
print(a[i-1:i+2,j-1:j+2])
print(np.sum(a[i-1:i+2,j-1:j+2]*gf))
#print(gf[1,1],gf[0,0],gf[0,1],gf[0,2])
#print(a[i-1:j+2,i-1:j+2])
print(" ")
#print(a[i,j],a[i-1,j-1],a[i-1,j],a[i-1,j+1])
[[ 0. 1. 2. 3. 4. 5.] [ 2. 3. 4. 5. 6. 7.] [ 4. 5. 6. 7. 8. 9.] [ 6. 7. 8. 9. 10. 11.] [ 8. 9. 10. 11. 12. 13.] [10. 11. 12. 13. 14. 15.]] 1 1 0 3 0 3 [[0. 1. 2.] [2. 3. 4.] [4. 5. 6.]] 39.0 1 2 0 3 1 4 [[1. 2. 3.] [3. 4. 5.] [5. 6. 7.]] 52.0 1 3 0 3 2 5 [[2. 3. 4.] [4. 5. 6.] [6. 7. 8.]] 65.0 1 4 0 3 3 6 [[3. 4. 5.] [5. 6. 7.] [7. 8. 9.]] 78.0 2 1 1 4 0 3 [[2. 3. 4.] [4. 5. 6.] [6. 7. 8.]] 65.0 2 2 1 4 1 4 [[3. 4. 5.] [5. 6. 7.] [7. 8. 9.]] 78.0 2 3 1 4 2 5 [[ 4. 5. 6.] [ 6. 7. 8.] [ 8. 9. 10.]] 91.0 2 4 1 4 3 6 [[ 5. 6. 7.] [ 7. 8. 9.] [ 9. 10. 11.]] 104.0 3 1 2 5 0 3 [[ 4. 5. 6.] [ 6. 7. 8.] [ 8. 9. 10.]] 91.0 3 2 2 5 1 4 [[ 5. 6. 7.] [ 7. 8. 9.] [ 9. 10. 11.]] 104.0 3 3 2 5 2 5 [[ 6. 7. 8.] [ 8. 9. 10.] [10. 11. 12.]] 117.0 3 4 2 5 3 6 [[ 7. 8. 9.] [ 9. 10. 11.] [11. 12. 13.]] 130.0 4 1 3 6 0 3 [[ 6. 7. 8.] [ 8. 9. 10.] [10. 11. 12.]] 117.0 4 2 3 6 1 4 [[ 7. 8. 9.] [ 9. 10. 11.] [11. 12. 13.]] 130.0 4 3 3 6 2 5 [[ 8. 9. 10.] [10. 11. 12.] [12. 13. 14.]] 143.0 4 4 3 6 3 6 [[ 9. 10. 11.] [11. 12. 13.] [13. 14. 15.]] 156.0
import matplotlib.pyplot as plt
import numpy as np
nc=100
radio=20
A=np.zeros([nc,nc])
ca=nc//2
#plt.matshow(A,cmap="grey")
for i in range(nc):
for j in range(nc):
if (i-ca)**2+(j-ca)**2 <= radio**2:
A[i,j]+=10
B=np.zeros([nc,nc])
gf=np.array([[1,1,1],[1,1,1],[-1,-1,-1]])
for i in range(1,nc-1):
for j in range(1,nc-1):
B[i,j]=np.sum(A[i-1:i+2,j-1:j+2]*gf)
plt.matshow(A,cmap="grey")
plt.matshow(B,cmap="grey")
plt.colorbar()
<matplotlib.colorbar.Colorbar at 0x7a4744772950>