Sei sulla pagina 1di 5

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons,

Grids; type TForm1 = class(TForm) lblTitulo: TLabel; BitBtn1: TBitBtn; GroupBox2: TGroupBox; Label1: TLabel; Label2: TLabel; txtGrado: TEdit; BitBtn2: TBitBtn; txtCoefi: TEdit; lstCoeficientes: TListBox; btnIngresar: TButton; btnOrdenar: TButton; sg_Sistema: TStringGrid; lstResultados: TListBox; txtraiz: TListBox; Label3: TLabel; btnCalcular: TButton; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Edit4: TEdit; Edit5: TEdit; Edit6: TEdit; Label4: TLabel; Label5: TLabel; Label6: TLabel; Label7: TLabel;

Label8: TLabel; Label9: TLabel; procedure btnIngresarClick(Sender: TObject); procedure btnOrdenarClick(Sender: TObject); procedure btnCalcularClick(Sender: TObject); procedure BitBtn2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; grado: Integer; i: Integer; repetida: Integer; bandera: Integer; j: Integer; l: Integer; v: Integer; k: Integer; m: Integer; fila: Integer; columna: Integer; expo: Integer; ncoefi: Integer; compa: Double; mayor: Double; orden: Integer; eps: Double; raiz: Double; aux: Double; coefi:Array[1..30,1..30]of Double; coefiaux:Array[1..30,1..30]of Double;

valores:Array[1..30]of Double; valoresaux:Array[1..30]of Double; implementation {$R *.dfm} procedure TForm1.btnIngresarClick(Sender: TObject); begin if ((j<ncoefi)) then begin coefi[i,j]:=StrToInt(txtCoefi.text); lstCoeficientes.Items.Add(FloatToStr(coefi[i,j])+'x^'+FloatToStr(expo)); txtCoefi.Text:=''; txtCoefi.SetFocus; expo:=expo-1; j:=j+1; end Else begin coefi[i,j]:=StrToInt(txtCoefi.text); lstCoeficientes.Items.Add('= '+FloatToStr(coefi[i,j])); txtCoefi.Text:=''; txtCoefi.SetFocus; j:=1; i:=i+1; if (i<ncoefi) then //Determino el ingreso de cada acuacion para mi sistema begin expo:=grado; ShowMessage('Ingrese la siguiente ecuacin'); end Else begin ShowMessage('Ya estan ingresadas las ecuaciones'); txtcoefi.visible:=False; btnIngresar.Visible:=False;

btnOrdenar.Visible:=True; end; end; end; procedure TForm1.btnOrdenarClick(Sender: TObject); begin for i:=1 to fila do begin mayor:=coefi[i,1]; orden:=1; if (mayor<0) then begin mayor:=mayor*(-1); end; for j:=2 to columna-1 do begin compa:=coefi[i,j]; if (compa<0) then begin compa:=compa*(-1); end; if (mayor<compa) then begin orden:=j; mayor:=compa; end; end; for k:=1 to columna do begin coefiaux[orden,k]:=coefi[i,k]; end; end; //Muestra en el stringGrind la matriz

for i:=1 to fila do begin for j:=1 to columna do begin sg_Sistema.Cells[j,i]:=FloatToStr(coefiaux[i,j]); end; end; end; //Termino de la funcion ordenar procedure TForm1.btnCalcularClick(Sender: TObject); begin for l:=1 to grado do begin Valores[l]:=0; valoresaux[l]:=0; end; while(bandera=0)do begin //fores que me moviliza por mi vectores y determinar el valor de aux for i:=1 to fila do begin aux:=0; for j:=1 to columna-1 do begin if (i<>j) then begin aux:=aux-(Coefiaux[i,j]*valoresaux[j]); end; end; valoresaux[i]:=(Coefiaux[i,columna]+aux)/Coefiaux[i,i]; end;

raiz:=0; //For que me calcula la raiz for k:=1 to grado do begin raiz:=raiz+(Abs(valores[k]-valoresaux[k])*Abs(valores[k]valoresaux[k])); end; raiz:=sqrt(raiz); //yo muestro ac for v:=1 to grado do begin lstResultados.Items.Add(FloatToStr(valoresaux[v])); end; //Me reemplaza mis valores viejos por los nuevos for l:=1 to grado do begin valores[l]:=valoresaux[l]; end; //Me cuenta el numero de vueltas ya que maximo tiene que ser 100 repetida:=repetida+1; //Me compara qcuando llegamos a la raiz y cuando se han repetido las 100 veces if ((raiz<=eps)or(repetida=100))then begin bandera:=1; end; end; //cierra el while

if grado=2 then begin edit1.Text:=(FloatToStr(valoresaux[1])); edit2.Text:=(FloatToStr(valoresaux[2])); end; if grado=3 then begin edit1.Text:=(FloatToStr(valoresaux[1])); edit2.Text:=(FloatToStr(valoresaux[2])); edit3.Text:=(FloatToStr(valoresaux[3])); end; if grado=4 then begin edit1.Text:=(FloatToStr(valoresaux[1])); edit2.Text:=(FloatToStr(valoresaux[2])); edit3.Text:=(FloatToStr(valoresaux[3])); edit4.Text:=(FloatToStr(valoresaux[4])); end; if grado=5 then begin edit1.Text:=(FloatToStr(valoresaux[1])); edit2.Text:=(FloatToStr(valoresaux[2])); edit3.Text:=(FloatToStr(valoresaux[3])); edit4.Text:=(FloatToStr(valoresaux[4])); edit5.Text:=(FloatToStr(valoresaux[5])); end; if grado=6 then begin edit1.Text:=(FloatToStr(valoresaux[1])); edit2.Text:=(FloatToStr(valoresaux[2]));

edit3.Text:=(FloatToStr(valoresaux[3])); edit4.Text:=(FloatToStr(valoresaux[4])); edit5.Text:=(FloatToStr(valoresaux[5])); edit6.Text:=(FloatToStr(valoresaux[6])); end; txtraiz.Items.Add(FloatToStr(raiz)) ; end; procedure TForm1.BitBtn2Click(Sender: TObject); begin grado:=StrToInt(txtgrado.text);// lectura del numero ingresado if grado=2 then begin label4.Visible:=true; label5.Visible:=true; edit1.Visible:=true; edit2.Visible:=true; end; if grado=3 then begin label4.Visible:=true; label5.Visible:=true; label6.Visible:=true; edit1.Visible:=true; edit2.Visible:=true; edit3.Visible:=true; end; if grado=4 then begin label4.Visible:=true; label5.Visible:=true; label6.Visible:=true; label7.Visible:=true;

edit1.Visible:=true; edit2.Visible:=true; edit3.Visible:=true; edit4.Visible:=true; end; if grado=5 then begin label4.Visible:=true; label5.Visible:=true; label6.Visible:=true; label7.Visible:=true; label8.Visible:=true; edit1.Visible:=true; edit2.Visible:=true; edit3.Visible:=true; edit4.Visible:=true; edit5.Visible:=true; end;

edit5.Visible:=true; edit6.Visible:=true; end;

fila:=grado; columna:=grado+1; ncoefi:= grado+1;//Nmero de coeficientes a ingresar en cada ecuacion i:=1;// inicializamos la variable i j:=1;//inicializamos la variable j k:=1; v:=1; l:=1; //variable para movilizarnos dentro del vector eps:=0.001; expo:=grado; sg_Sistema.ColCount:=columna+1; sg_sistema.RowCount:=fila+1; //sg_Resultados.ColCount:=columna+1; end; end. //el que cierra al principal

if grado=6 then begin label4.Visible:=true; label5.Visible:=true; label6.Visible:=true; label7.Visible:=true; label8.Visible:=true; label9.Visible:=true; edit1.Visible:=true; edit2.Visible:=true; edit3.Visible:=true; edit4.Visible:=true;

Potrebbero piacerti anche