### Skaitliskā integrēšana

```Skaitliskā integrēšana
y
f(x)
a
=
b
a
b x
f x dx
Kreisu taisnstūru metode
(−)2
=
* max ′()
2
≤≤
Labēju taisnstūru metode
Vidēju taisnstūru metode
(−)3
=
* max ′()
2
24
≤≤
Trapeču metode
−1

() ≈

(+1 −  )((+1) +   )/2
=0
(−)3
=
* max ′()
2
12
≤≤
Simpsona metode

ℎ
() ≈ ( 0 + ( ) +
3
−1
−1
2  +
=2,4,6,…
(−)3

=
*
max

()
4
180 ≤≤
4( ))
=1,3,…
Kreisu taisnstūru metodes realizācija
Delphi vidē
function pram_lev(x:vector):Real;
begin
Result := 0;
for i := 0 to n-1 do
Result := Result + (x[i+1]-x[i])*ffx(x[i]);
end;
Kreisu taisnstūru metodes realizācija
Delphi vidē
function pram_lev_1(a,b:Real;n:integer):Real;
var
rrr:Real;
begin
rrr := 0;
h:= (b-a)/n;
z := a - h;
while z <= b - h do
begin
z := z + h;
rrr := rrr + h*ffx(z);
end;
pram_lev_1 := rrr;
end;
Labēju taisnstūru metodes realizācija
Delphi vidē
function pram_prav(x:vector):Real;
begin
Result := 0;
for i := 1 to n do
Result := Result + (x[i]-x[i-1])*ffx(x[i]);
end;
Vidēju taisnstūru metodes realizācija
Delphi vidē
function pram_sred(x:vector):Real;
begin
Result := 0;
for i := 0 to n-1 do
Result := Result + (x[i+1]-x[i])*ffx((x[i+1]+x[i])/2);
end;
Trapeču metodes realizācija
Delphi vidē
function trapec (x:vector):Real;
begin
Result := 0;
for i := 0 to n-1 do
Result := Result + (x[i+1]x[i])*(ffx(x[i+1])+ffx(x[i]))/2;
end;
Simpsona metodes realizācija
Delphi vidē
function simpson1(a,b:Real;n:integer):real;
begin
Result := 0;
h:=(b-a)/n;
for i := 1 to n-1 do
begin
if i mod 2 = 0 then Result := Result + 2*ffx(x[i])
else Result := Result + 4*ffx(x[i])
end;
Result := h*(Result + ffx(a) + ffx(b))/3;
end;
2
f ( x )  x 
9
sin ( x )
10

i   f ( x ) dx
4
i 
Skaitliskā integrēšana Matlab vidē
function y = fx(x)
y = x.*x.*sin(x)/10;
i1 =
7.6301
Skaitliskā integrēšana Matlab vidē
n = 500;
i = 0:n;
a = 4;
b = 9;
h = (b-a)/n;
z=
x = a+h*i;
y = fx(x);
z = trapz(x,y)
7.6300
Skaitliskā integrēšana Matlab vidē
x = 4:0.0001:9;
y = x.*x.*sin(x)/10;
z = trapz(x,y)
x = 4:0.0001:9;
y = fx(x);
z = trapz(x,y)
z=
7.6300
```