Método del trapecio
an anonymous user
·
Python
import numpy as np
def f(x):
return 5 * np.sin(x)
def metodo_trapecio(a, b, n):
h = (b - a) / n
suma = f(a) + f(b)
for i in range(1, n):
suma += 2 * f(a + i * h)
return (h / 2) * suma
# Intervalo
a = 0
b = np.pi
# Cálculos
I_n8 = metodo_trapecio(a, b, 8)
I_n16 = metodo_trapecio(a, b, 16)
print("Resultado con n=8:", round(I_n8, 4))
print("Resultado con n=16:", round(I_n16, 4))
Output
Embed on website
To embed this program on your website, copy the following code and paste it into your website's HTML:
Comments
This comment belongs to a banned user and is only visible to admins.
This comment belongs to a deleted user and is only visible to admins.