1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TOperation = function(const X: Extended): Extended;
type
TF_Main = class(TForm)
Btn_Integration: TButton;
procedure Btn_IntegrationClick(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
F_Main: TF_Main;
implementation
{$R *.dfm}
{ ========================================================================= }
function Integrale(const X1,X2 : Extended; const Fonction: TOperation): Extended;
Var
N, i : Integer ;
Somme, XDeb, XFin, Pas : Extended ;
YDeb, YFin : Extended ;
begin
N := 100 ;
Somme := 0 ;
Pas := (X2 - X1)/N ;
For i := 1 to N Do
Begin
XDeb := X1 + (i-1) * Pas ;
XFin := Xdeb + Pas ;
YDeb := Fonction(XDeb) ;
YFin := Fonction(XFin) ;
Somme := Somme + (YDeb + YFin) / 2 * Pas ;
End ;
result := Somme ;
end;
{ ========================================================================= }
function Carre(const X: Extended): Extended ;
begin
result := X * X;
end;
{ ========================================================================= }
function Cube(const X: Extended): Extended ;
begin
result := X * X * X ;
end;
{ ========================================================================= }
procedure Test;
var X,Y,A,M : Extended ;
begin
X := 1.00 ;
Y := 2.00 ;
A := Integrale(X, Y, Carre);
M := Integrale(X, Y, Cube);
// ShowMessage(Format('X= %*.*f, Y= %*.*f // Intégrale Carré= %*.*f // Intégrale Cube= %*.*f',[X, Y, A, M]));
ShowMessage ('Intégration entre :'+Chr(10)+Chr(13)+
' X1 = '+FloatToStr(X)+Chr(10)+Chr(13)+
' X2 = '+FloatToStr(Y)+Chr(10)+Chr(13)+
' Fonction y=x2 : '+FloatToStr(A)+Chr(10)+Chr(13)+
' Fonction y=x3 : '+FloatToStr(M));
end;
{ ========================================================================= }
procedure TF_Main.Btn_IntegrationClick(Sender: TObject);
begin
Test ;
end;
end. |
Partager