Skaitliskā integrēšana

Download Report

Transcript Skaitliskā integrēšana

Skaitliskā integrēšana
y
f(x)
a
b x
Kreisu taisnstūru metode
Labēju taisnstūru metode
Vidēju taisnstūru metode
Trapeču metode
Simpsona metode
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;
Skaitliskā integrēšana Mathcad vidē
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=quad(@fx,4,9)
i1 =
7.6301
i1=quad(‘fx’,4,9)
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