нужна помощь в решении задачи
найти площадь фигуры, ограниченной линиями
по формуле Симпсона!!!
мой адрес grigorievam@mail.ru
найти площадь фигуры, ограниченной линиями
по формуле Симпсона!!!
мой адрес grigorievam@mail.ru
Проблема в том что надо составить алгоритм , А я не знаю как!!!unit Unit1;
interface
uses
Windows, Messages, SysUtils,Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Math;
type
TIntegratorForm = class(TForm)
Label1: TLabel;
GroupBox1: TGroupBox;
Label2: TLabel;
Edit_k: TEdit;
Label3: TLabel;
Edit_a: TEdit;
GroupBox2: TGroupBox;
Label4: TLabel;
Label5: TLabel;
Edit_x1: TEdit;
Edit_x2: TEdit;
Btn_calc: TButton;
Label8: TLabel;
Edit_nDiv: TEdit;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Edit_b: TEdit;
Edit_c: TEdit;
Edit_d: TEdit;
GroupBox3: TGroupBox;
Lb_exact: TLabel;
Lb_trap: TLabel;
procedure Btn_calcClick(Sender: TObject);
private
{ Private declarations }
k, a, b, c, d, x1, x2: double;
nDiv: integer;
function f(x: double):double;
function int_f(x: double):double;
public
{ Public declarations }
end;
var
IntegratorForm: TIntegratorForm;
implementation
{$R *.dfm}
function TIntegratorForm.f(x: double):double;
//Ôóíêöèÿ f(x)
begin
result:=k*arccos(a*x+b)+c*x+d;
end;
function TIntegratorForm.int_f(x: double):double;
{Ïåðâîîáðàçíàÿ f(x)}
begin
result:=(((a*x+b)*arccos(a*x+b)-sqrt(1-sqr(a*x+b)))*k)/a+0.5*c*sqr(x)+d*x;
end;
procedure TIntegratorForm.Btn_calcClick(Sender: TObject);
var s, s_exact, x, dx: double;
i: integer;
const sExactResFmt='Òî÷íûé: %0.8f';
sTrapResFmt='Ïî òðàïåöèÿì: %0.9f';
begin
Btn_calc.Enabled:=false;
try
k :=StrToFloat(Edit_k.Text);
a :=StrToFloat(Edit_a.Text);
b :=StrToFloat(Edit_b.Text);
c :=StrToFloat(Edit_c.Text);
d :=StrToFloat(Edit_d.Text);
x1 :=StrToFLoat(Edit_x1.Text);
x2 :=StrToFloat(Edit_x2.Text);
nDiv:=StrToInt (Edit_nDiv.Text);
if (nDiv<1) then
begin
MessageBox(Handle, 'Íåîáõîäèì ïî êðàéíåé ìåðå 1 îòðåçîê ðàçáèåíèÿ', 'Îøèáêà', MB_OK or MB_ICONEXCLAMATION);
Edit_nDiv.SetFocus;
Btn_calc.Enabled:=true;
exit;
end;
except
MessageBox(Handle, 'Ñëåäóåò ââåñòè ÷èñëî', 'Îøèáêà', MB_OK or MB_ICONEXCLAMATION);
Edit_k.SetFocus;
Btn_calc.Enabled:=true;
exit;
end;
{Ðàñ÷åò ïëîùàäè}
s:=0;
dx:=(x2-x1)/nDiv;
x:=x1;
try
for i:=1 to nDiv do
begin
s:=s+f(x+0.5*dx)*dx;
x:=x+dx;
end;
s_exact:=int_f(x2)-int_f(x1);{Ôîðìóëà Íüþòîíà-Ëåéáíèöà}
except
On EMathError do
begin
MessageBox(Handle, 'Çàäàííûå ïàðàìåòðû ïðèâåëè ê âûõîäó çà ïðåäåëû ÎÄÇ',
'Íàðóøåíèå ÎÄÇ', MB_OK or MB_ICONEXCLAMATION);
Btn_calc.Enabled:=true;
exit;
end;
end;
Lb_exact.Caption:=Format(sExactResFmt, [s_exact]);
Lb_trap.Caption :=Format(sTrapResFmt, [s]);
Btn_calc.Enabled:=true;
end;
end.
interface
uses
Windows, Messages, SysUtils,Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Math;
type
TIntegratorForm = class(TForm)
Label1: TLabel;
GroupBox1: TGroupBox;
Label2: TLabel;
Edit_k: TEdit;
Label3: TLabel;
Edit_a: TEdit;
GroupBox2: TGroupBox;
Label4: TLabel;
Label5: TLabel;
Edit_x1: TEdit;
Edit_x2: TEdit;
Btn_calc: TButton;
Label8: TLabel;
Edit_nDiv: TEdit;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Edit_b: TEdit;
Edit_c: TEdit;
Edit_d: TEdit;
GroupBox3: TGroupBox;
Lb_exact: TLabel;
Lb_trap: TLabel;
procedure Btn_calcClick(Sender: TObject);
private
{ Private declarations }
k, a, b, c, d, x1, x2: double;
nDiv: integer;
function f(x: double):double;
function int_f(x: double):double;
public
{ Public declarations }
end;
var
IntegratorForm: TIntegratorForm;
implementation
{$R *.dfm}
function TIntegratorForm.f(x: double):double;
//Ôóíêöèÿ f(x)
begin
result:=k*arccos(a*x+b)+c*x+d;
end;
function TIntegratorForm.int_f(x: double):double;
{Ïåðâîîáðàçíàÿ f(x)}
begin
result:=(((a*x+b)*arccos(a*x+b)-sqrt(1-sqr(a*x+b)))*k)/a+0.5*c*sqr(x)+d*x;
end;
procedure TIntegratorForm.Btn_calcClick(Sender: TObject);
var s, s_exact, x, dx: double;
i: integer;
const sExactResFmt='Òî÷íûé: %0.8f';
sTrapResFmt='Ïî òðàïåöèÿì: %0.9f';
begin
Btn_calc.Enabled:=false;
try
k :=StrToFloat(Edit_k.Text);
a :=StrToFloat(Edit_a.Text);
b :=StrToFloat(Edit_b.Text);
c :=StrToFloat(Edit_c.Text);
d :=StrToFloat(Edit_d.Text);
x1 :=StrToFLoat(Edit_x1.Text);
x2 :=StrToFloat(Edit_x2.Text);
nDiv:=StrToInt (Edit_nDiv.Text);
if (nDiv<1) then
begin
MessageBox(Handle, 'Íåîáõîäèì ïî êðàéíåé ìåðå 1 îòðåçîê ðàçáèåíèÿ', 'Îøèáêà', MB_OK or MB_ICONEXCLAMATION);
Edit_nDiv.SetFocus;
Btn_calc.Enabled:=true;
exit;
end;
except
MessageBox(Handle, 'Ñëåäóåò ââåñòè ÷èñëî', 'Îøèáêà', MB_OK or MB_ICONEXCLAMATION);
Edit_k.SetFocus;
Btn_calc.Enabled:=true;
exit;
end;
{Ðàñ÷åò ïëîùàäè}
s:=0;
dx:=(x2-x1)/nDiv;
x:=x1;
try
for i:=1 to nDiv do
begin
s:=s+f(x+0.5*dx)*dx;
x:=x+dx;
end;
s_exact:=int_f(x2)-int_f(x1);{Ôîðìóëà Íüþòîíà-Ëåéáíèöà}
except
On EMathError do
begin
MessageBox(Handle, 'Çàäàííûå ïàðàìåòðû ïðèâåëè ê âûõîäó çà ïðåäåëû ÎÄÇ',
'Íàðóøåíèå ÎÄÇ', MB_OK or MB_ICONEXCLAMATION);
Btn_calc.Enabled:=true;
exit;
end;
end;
Lb_exact.Caption:=Format(sExactResFmt, [s_exact]);
Lb_trap.Caption :=Format(sTrapResFmt, [s]);
Btn_calc.Enabled:=true;
end;
end.
Авторизуйтесь, чтобы принять участие в дискуссии.