You are on page 1of 5

INSTITUTO TECNOLÓGICO DE CHIHUAHUA II

Chihuahua, Chih. Noviembre 2010

ELIMINACIÓN DE
GAUSS

Laura Antonia Ortega Chávez

Ing. Sistemas Computacionales


Alfonso Orrantia Vega
07550470
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
Dialogs, StdCtrls, math;

type
TForm1 = class(TForm)
capturar: TButton;
Label1: TLabel;
matriz: TMemo;
bs: TMemo;
Button1: TButton;
Button2: TButton;
matriz2: TMemo;
bs2: TMemo;
det: TLabel;
Label2: TLabel;
Label3: TLabel;
x1: TLabel;
procedure capturarClick(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
a: array of array of double;
b,x: array of double;
n:integer;
factor:double;

implementation
{$R *.dfm}
function Redondear(Valor: Real; Redondeo: Integer):Real;
begin
Redondear := Trunc(Valor * Power(10, Redondeo)) /
Power(10,Redondeo);
end;

procedure TForm1.capturarClick(Sender: TObject);


var
i,j:integer;
renglona:string;
begin
matriz.Clear;
bs.Clear;
matriz2.Clear;
bs2.Clear;
label1.Caption:= 'n=';
det.Caption:= 'D=';
x1.Caption:= '';
n:=strtoint(InputBox('Question', 'Tamaño de matriz: ', 'Default'));
label1.Caption:= 'n='+inttostr(n);
SetLength(a,n,n);
SetLength(b,n);
SetLength(x,n);
for j:=0 to n-1 do
begin
for i:=0 to n-1 do
begin
a[j][i]:=strtofloat(InputBox('Question', 'Introduzca el valor de la
columna '+inttostr(j+1) + ' y renglón '+ inttostr(i+1), ''));
renglona:= renglona + floattostr(a[j][i]) + ' ';
end;
matriz.Lines.Add(renglona);
b[j]:= strtofloat(InputBox('Question', 'Introduzca el valor de
b'+inttostr(j+1), ''));
bs.Lines.Add(floattostr(b[j]));
renglona:='';
end;
button1.Enabled:=true;
end;

procedure TForm1.Button2Click(Sender: TObject);


begin
close;
end;

procedure TForm1.Button1Click(Sender: TObject);


var
k,i,j: integer;
sum,d:double;
renglona:string;
begin
for k:=1 to n-1 do
begin
for i:=k+1 to n do
begin
factor:=redondear(a[i-1][k-1]/a[k-1][k-1],9);
for j:=1 to n do
begin
a[i-1][j-1]:=redondear(a[i-1][j-1]-factor*a[k-1][j-1],9);
if a[i-1][j-1] < 0.0000001 then
if a[i-1][j-1]> 0 then
a[i-1][j-1]:=0;
end;
b[i-1]:=redondear(b[i-1]-factor*b[k-1],9);
end;
end;
x[n-1]:=redondear(b[n-1]/a[n-1][n-1],9);
d:=1;

//calcular determinante
for i:=0 to n-1 do
d:= redondear(d*a[i][i],9);
det.Caption:='D=' + floattostr(d);

for j:=0 to n-1 do


begin
for i:=0 to n-1 do
begin
renglona:= renglona + floattostr(a[j][i]) + ' ';
end;
matriz2.Lines.Add(renglona);
bs2.Lines.Add(floattostr(b[j]));
renglona:='';
end;

for i:=n-1 downto 1 do


begin
sum:=b[i-1];
for j:=i+1 to n do
begin
sum:=redondear(sum-a[i-1][j-1]*x[j-1],9);
end;
x[i-1]:=redondear((sum)/a[i-1][i-1],9);
end;
for i:=0 to n-1 do
begin
renglona:=renglona+'X'+inttostr(i+1)+':'+floattostr(x[i])+' ';
end;
x1.Caption:=renglona;
button1.Enabled:=false;
end;

end.

You might also like