- ///////////////////////////////////////////////////////////
- // Fichier : uDichotomique.pas //
- // Auteur : Stéphane HAIMET //
- // Date de création : 12/02/08 //
- // Date de modification : 13/02/08 //
- ///////////////////////////////////////////////////////////
-
-
- unit uDichotomique;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls, Buttons;
-
- type
- TForm1 = class(TForm)
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- eIteration: TEdit;
- eRacine: TEdit;
- eNombre: TEdit;
- bCalculer: TBitBtn;
- bFermer: TBitBtn;
- lMessage: TLabel;
- procedure eNombreChange(Sender: TObject);
- procedure bCalculerClick(Sender: TObject);
- function psqrt(nombre:real):real;
- private
- { Déclarations privées }
- public
- { Déclarations publiques }
- end;
-
- var
- Form1: TForm1;
- //Variable publique :
- n: integer;
-
- implementation
-
- {$R *.dfm}
-
-
- //Quand on change l'édit nombre
- procedure TForm1.eNombreChange(Sender: TObject);
- begin
- lMessage.caption := '';
- eIteration.Text:='';
- eRacine.Text:='';
- end;
-
-
- //Quand on clique sur le bouton "calculer"
- procedure TForm1.bCalculerClick(Sender: TObject);
- var nombre, resultat : real;
- begin
- nombre:=strtofloat(eNombre.text);
- resultat:=psqrt(nombre);
- eIteration.text:=inttostr(n);
- eRacine.Text:=floattostr(resultat);
- end;
-
-
- //Fonction qui calcul la racine cubique
- function TForm1.psqrt(nombre:real):real;
- var bornInf, bornSup, bornMil : real;
- begin
- n:=0;
- bornMil:=(bornInf+bornSup)/2;
- //Si on a un nombre positif :
- if (nombre>0) then
- begin
- bornInf:=0;
- bornSup:=nombre;
- end
- else begin
- bornInf:=nombre;
- bornSup:=0;
- end;
- //On commence la boucle de recherche
- repeat
- if((bornMil*bornMil*bornMil)<nombre) then
- bornInf:=bornMil
- else
- bornSup:=bornMil;
- bornMil:=(bornInf+bornSup)/2;
- n:=n+1;
- until (((nombre-(bornMil*bornMil*bornMil))>-0.0001)
- AND (nombre-(bornMil*bornMil*bornMil)<0.0001));
- result:=bornmil;
- end;
-
-
- end.
///////////////////////////////////////////////////////////
// Fichier : uDichotomique.pas //
// Auteur : Stéphane HAIMET //
// Date de création : 12/02/08 //
// Date de modification : 13/02/08 //
///////////////////////////////////////////////////////////
unit uDichotomique;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
eIteration: TEdit;
eRacine: TEdit;
eNombre: TEdit;
bCalculer: TBitBtn;
bFermer: TBitBtn;
lMessage: TLabel;
procedure eNombreChange(Sender: TObject);
procedure bCalculerClick(Sender: TObject);
function psqrt(nombre:real):real;
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
//Variable publique :
n: integer;
implementation
{$R *.dfm}
//Quand on change l'édit nombre
procedure TForm1.eNombreChange(Sender: TObject);
begin
lMessage.caption := '';
eIteration.Text:='';
eRacine.Text:='';
end;
//Quand on clique sur le bouton "calculer"
procedure TForm1.bCalculerClick(Sender: TObject);
var nombre, resultat : real;
begin
nombre:=strtofloat(eNombre.text);
resultat:=psqrt(nombre);
eIteration.text:=inttostr(n);
eRacine.Text:=floattostr(resultat);
end;
//Fonction qui calcul la racine cubique
function TForm1.psqrt(nombre:real):real;
var bornInf, bornSup, bornMil : real;
begin
n:=0;
bornMil:=(bornInf+bornSup)/2;
//Si on a un nombre positif :
if (nombre>0) then
begin
bornInf:=0;
bornSup:=nombre;
end
else begin
bornInf:=nombre;
bornSup:=0;
end;
//On commence la boucle de recherche
repeat
if((bornMil*bornMil*bornMil)<nombre) then
bornInf:=bornMil
else
bornSup:=bornMil;
bornMil:=(bornInf+bornSup)/2;
n:=n+1;
until (((nombre-(bornMil*bornMil*bornMil))>-0.0001)
AND (nombre-(bornMil*bornMil*bornMil)<0.0001));
result:=bornmil;
end;
end.