Documentos de Académico
Documentos de Profesional
Documentos de Cultura
ipynb - Colaboratory
Tarea de integrales
Nombre del alumno:
No. de cuenta:
1.Un cilindro cerrado de radio R y longitud L está lleno a la mitad con aceite de peso w, el cilindro está sobre su costado AB como se muestra
en la figura
La fuerza F que ejerce el aceite sobre los lados está dada por
https://colab.research.google.com/drive/1x2oCp8OihTQDYdsT__J6b0bOjA9-RP2q?usp=sharing#scrollTo=7uM4OHUjoBc0&printMode=true 1/6
22/4/23, 22:10 Integrales MN.ipynb - Colaboratory
1 def reglaRectangulos(f,a,b,n):
2 h=(b-a)/n
3 xs=np.linspace(a,b,n+1)
4 ys=f(xs)
5 return h*sum(ys[:n])
1 import numpy as np
2
3 def integrales(f,a,b,n,metodo='trap'):
4 '''
5 f es la funcion a integrar
6 a,b son los limites de integracion
7 n es el numero de intervalos
8 metodo es rect, trap, s13 s38
9 '''
10 #se valida que los intervalos sean positivos
11 if n<=0:
12 raise ValueError(f'n={n} no es valido')
13 #se valida que los intervalos sean pares
14 if metodo=='s13' and n%2>0:
15 raise ValueError(f'n={n} no es par')
16 #se valida que los intervalos sea multiplo de 3
17 if metodo=='s38' and n%3>0:
18 raise ValueError(f'n={n} no es multiplo de 3')
19
20 h=(b-a)/n #se calcula el tamano del intervalo
21 x=np.linspace(a,b,n+1) #se crean los puntos intermedios
22 fx=f(x) #se calcula la funcion
23 if metodo=='trap':
24 inte=h/2*(fx[0]+2*sum(fx[1:n])+fx[n])
25 elif metodo=='s13':
26 inte=h/3*(fx[0]+4*sum(fx[1:n:2])+2*sum(fx[2:n-1:2])+fx[n])
27 elif metodo=='s38':
28 inte=3*h/8*(fx[0]+3*sum(fx[1:n-1:3])+3*sum(fx[2:n:3])+2*sum(fx[3:n-2:3])+fx[n])
29 elif metodo=='rect':
30 inte=h*sum(fx[:n])
https://colab.research.google.com/drive/1x2oCp8OihTQDYdsT__J6b0bOjA9-RP2q?usp=sharing#scrollTo=7uM4OHUjoBc0&printMode=true 2/6
22/4/23, 22:10 Integrales MN.ipynb - Colaboratory
31
1 import numpy as np
1 def reglaRectangulos(f,a,b,n):
2 h=(b-a)/n
3 xs=np.linspace(a,b,n+1)
4 ys=f(xs)
5 return h*sum(ys[:n])
1 def f(x):
2 return 2*90*np.sqrt(4-(x**2))*x
1 f=lambda x:(2*90*np.sqrt(4-(x**2))*x)
a) Rectángulos
1 n=12
2 a=0
3 b=2
4 i=integrales(f,a,b,n,'rect')
5 i
469.1127644074264
b) Trapecios
1 n=12
2 a=0
3 b=2
4 i=integrales(f,a,b,n,'trap')
5 i
469.1127644074264
https://colab.research.google.com/drive/1x2oCp8OihTQDYdsT__J6b0bOjA9-RP2q?usp=sharing#scrollTo=7uM4OHUjoBc0&printMode=true 3/6
22/4/23, 22:10 Integrales MN.ipynb - Colaboratory
c) Simpson 1/3
1 n=12
2 a=0
3 b=2
4 i=integrales(f,a,b,n,'s13')
5 i
475.95054516105836
2.Estime la superficie del lago usando integrales, tome en cuenta los puntos discretos señalados
https://colab.research.google.com/drive/1x2oCp8OihTQDYdsT__J6b0bOjA9-RP2q?usp=sharing#scrollTo=7uM4OHUjoBc0&printMode=true 4/6
22/4/23, 22:10 Integrales MN.ipynb - Colaboratory
Integral Superior
x 1 2 7 8 9 10 11 14 15 18 20 21 25 26 27 31 32 33 34
y 14 15 16 17 18 19 20 21 21 21 22 22 23 23 23 22 21 20 19
1 import numpy as np
2 from scipy.integrate import trapz,simps
1 x=np.array([1,2,7,8,9,10,11,14,15,18,20,21,25,26,27,31,32,33,34])
2 y=np.array([14,15,16,17,18,19,20,21,21,21,22,22,23,23,23,22,21,20,19])
3
4 trapz(y,x)
662.0
Integral Inferior
x 1 1.5 6 9 10 12 13 14 15 20 21 22 24 25 29 31 33 34
y 8 6 6 3 2 1 1 1 1 2 2 2 3 4 8 9 10 16
1 import numpy as np
2 from scipy.integrate import trapz,simps
1 x=np.array([1,1.5,6,9,10,12,13,14,15,20,21,22,24,25,29,31,33,34])
2 y=np.array([8,6,6,3,2,1,1,1,1,2,2,2,3,4,8,9,10,16])
3
4 trapz(y,x)
145.5
1 662.0-145.5
516.5
https://colab.research.google.com/drive/1x2oCp8OihTQDYdsT__J6b0bOjA9-RP2q?usp=sharing#scrollTo=7uM4OHUjoBc0&printMode=true 5/6
22/4/23, 22:10 Integrales MN.ipynb - Colaboratory
https://colab.research.google.com/drive/1x2oCp8OihTQDYdsT__J6b0bOjA9-RP2q?usp=sharing#scrollTo=7uM4OHUjoBc0&printMode=true 6/6