Está en la página 1de 3

1/11/21 20:36 Untitled7 - Jupyter Notebook

In [14]: import numpy as np


def f(x):
return 1 + np.exp(-x)*np.sin(4*x)

#Fórmula compuesta del trapecio con 5 nodos

In [10]: xmin = 0
xmax = 1
nodes = 5
h = (xmax-xmin)/(nodes-1)
#-------------------primer trapecio ->son 4 trapecios por la h
x0 = xmin
x1 = x0 + h
f0 = f(x0)
f1 = f(x1)
A1 = 0.5*h*(f0+f1)
##--h/2
print('A1 ='+str(A1))
#-------------------segundo trapecio
x0 = x1
x1 = x0 + h
f0 = f(x0)
f1 = f(x1)
A2 = 0.5*h*(f0+f1)
##--h/2
print('A2 ='+str(A2))
#-------------------tercer trapecio
x0 = x1
x1 = x0 + h
f0 = f(x0)
f1 = f(x1)
A3 = 0.5*h*(f0+f1)
##--h/2
print('A3 ='+str(A3))
#-------------------cuarto trapecio
x0 = x1
x1 = x0 + h
f0 = f(x0)
f1 = f(x1)
A4 = 0.5*h*(f0+f1)
##--h/2
print('A4 ='+str(A4))
#-----------------------aproximacion a la integral
print('Atotal ='+str(A1+A2+A3+A4))

A1 =0.331917282737532

A2 =0.40085687875847964

A3 =0.32727214248720055

A4 =0.22353103658487372

Atotal =1.283577340568086

##---b)fórmula compuesta de simpson 5 nodos

localhost:8888/notebooks/Untitled7.ipynb?kernel_name=python3 1/3
1/11/21 20:36 Untitled7 - Jupyter Notebook

In [11]: xmin = 0
xmax = 1
nodes = 5
h = (xmax-xmin)/(nodes-1)
#-------------------primer integral de simpson
x0 = xmin
x1 = x0 + h
x2 = x1 + h
f0 = f(x0)
f1 = f(x1)
f2 = f(x2)
A1 = (h/3)*(f0+4*f1+f2)
##--h/3
print('A1 ='+str(A1))
#-------------------primer integral de simpson
x0 = x2
x1 = x0 + h
x2 = x1 + h
f0 = f(x0)
f1 = f(x1)
f2 = f(x2)
A2 = (h/3)*(f0+4*f1+f2)
##--h/3
print('A2 ='+str(A2))
##aproximación a la integral
print('Atotal ='+str(A1+A2))

A1 =0.764405817980717

A2 =0.5449788480030534

Atotal =1.3093846659837705

##fórmula simple de boole

In [15]: xmin = 0
xmax = 1
nodes = 5
h = (xmax-xmin)/(nodes-1)
#-------------------primer trapecio ->son 4 trapecios por la h
x0 = xmin
x1 = x0 + h
x2 = x1 + h
x3 = x2 + h
x4 = x3 + h
f0 = f(x0)
f1 = f(x1)
f2 = f(x2)
f3 = f(x3)
f4 = f(x4)
A1 = (2*h/45)*(7*f0+32*f1+12*f2+32*f3+7*f4)
##--
print('A1 ='+str(A1))

A1 =1.3085919215646966

localhost:8888/notebooks/Untitled7.ipynb?kernel_name=python3 2/3
1/11/21 20:36 Untitled7 - Jupyter Notebook

In [ ]: ​

localhost:8888/notebooks/Untitled7.ipynb?kernel_name=python3 3/3

También podría gustarte