dobrý den,
mohl by mi někdo poradit s tímto úkolem?Výpočet určitého integrálu x^2*e^-x v mezích <0,2> v delphi pomocí lichoběžníkového pravidla s přesností 10^-5.
moc děkuji
Fórum › Delphi
Integrál v delphi

A co se inspirovat zde? http://programujte.com/?akce=diskuze&kam=vlakno&tema=4740-integral-v-delphi-poradte-prosim-
vidím, že žádná inspirace, tak tady je fce co to umí:
function LichobeznikovaMetoda:String;
var i,n,p,pre:Integer;
a,b,x,dx,S,S1:Extended;
pres: String;
k:array of Extended;
function VypInt(var x:Extended):Extended;
begin
Result := Power(x,2)*exp(x)-x;
end;
begin
a := 0; b :=2;
n := 2;
tol := 1e-5;
p := 1;
S := 0; S1 := tol+1;
pre := Length(FloatToStr(S1))-1;
while (abs(S-S1)/p>tol)and(n<100000) do
begin
S1 := S;
S := 0;
dx := (b-a)/n;
SetLength(k,0);
SetLength(k,n+1);
for i := 0 to n do
k[i] := 1;
x := a; k[0] := 1/2; k[n] := 1/2; p := 3;
for i := 0 to n do
begin
S := S+k[i]*VypInt(x)*dx;
x := x+dx;
end;
n := 2*n;
end;
S := S+abs(S-S1)/p;
pres := '%.'+IntToStr(pre)+'f';
Result := Format(pres, [S]);
end;
To Honzc : moc děkuji,ale fce ,co jste použil jsme se neučili.Dá se říct,že je to stejné jako tato šablona?
program integr_lich;
{$APPTYPE CONSOLE}
uses
SysUtils;
var
i,n:integer;
h,DM,HM,SK,SV,INT:real;
function f(x:real):real;
begin
f:=sqr(x);
end ;
begin
write('Zadej DM: ');
readln(DM);
write('Zadej HM: ');
readln(HM);
write('Zadej N: ');
readln(N);
h:=(HM-DM)/N;
SK:=f(DM)+f(HM);
SV:=0;
for i:=1 to N-1 do
SV:=SV+f(DM+i*h);
INT:=h*(SK/2+SV);
writeln('INTEGRAL= ',INT:10:6);
readln;
{ TODO -oUser -cConsole Main : Insert code here }
end.
To lusishka:
To co jsi napsal je výpočet Integrálu, ale s daným počtem dělení (n)
Nevím ovšem proč si necháváš zadat DM a HM, když jsou dané, a také ta funkce je nějaká jiná.
Jinak já jsem v tom svém příkladu nějak špatně přečetl tu tvou funkci. (asi proto, že je špatně zapsaná)
Takže i když nevím jaké funkce jste nebrali tak to napiš viz níže:
program integr_lich;
{$APPTYPE CONSOLE}
uses
SysUtils;
procedure LichobeznikovaMetoda;
var i,n:Integer;
x,dx,S,S1:Real;
function VypInt(var x:Real):Real;
begin
Result :=sqr(x)*exp(-x);
end;
begin
n := 2;
S := 0; S1 := 1;
while (abs(S-S1)>1e-5) do
begin
S1 := S;
S := 0;
x :=0;
dx := 2/n;
for i := 0 to n do
begin
if (i=0)or(i=n) then
S := S+VypInt(x)*dx/2
else
S := S+VypInt(x)*dx;
x := x+dx;
end;
n := 2*n;
end;
S := S+(S-S1)/3;
WriteLn('S = ',S:8:6);
end;
begin
WriteLn;
WriteLn('Vysledek vypoctu integralu x^2*x^(-x) v mezich <0,2>:');
WriteLn;
LichobeznikovaMetoda;
ReadLn; //Po stisku ENTER se program ukonci
end.

Přidej příspěvek
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
































Uživatelé prohlížející si toto vlákno
Podobná vlákna
Integral v Delphi - poraďte prosím :) — založil Pomeranc
Integrál — založil hazard
INTEGRAL — založil XANI
Integrál — založil ukulele
Integrál 2 — založil ukulele