Numerička integracija¶
In next video lecture we will say something about error that we make when we use Newton-Cotes formulas
In [1]:
from IPython.lib.display import YouTubeVideo
vid = YouTubeVideo("mjPBinappuI")
display(vid)
In the next part of the lecture we introduce composite numerical integration formulas and the error estimate for these formulas
In [2]:
vid = YouTubeVideo("9_E01OBrzbA")
display(vid)
Exercises¶
In the next part of the lecture we solve some problems related to numerical integration.
In [3]:
vid = YouTubeVideo("XGmjVD7DuhA")
display(vid)
Implementation of composite integration formulas¶
In [1]:
def trapez(f,a,b,N=50):
x = np.linspace(a,b,N+1)
y = f(x)
y_right = y[1:] # lijevi rub intervala
y_left = y[:-1] # desni rub intervala
h = (b - a)/N
Tn = np.sum(h*(y_right + y_left)/2)
return Tn
In [2]:
import numpy as np
from numpy import exp
from numpy import cos
from numpy import pi
trapez(lambda x : x*exp(-x)*cos(2*x),0,2*pi,6)
Out[2]:
-0.2269939761611912
For homework, try to implement the composite rectangular formula and the composite Simpson formula, following the example in the code above !!
In [ ]: