Recent

Author Topic: Gaussian Elimination  (Read 2179 times)

jcaser1948

  • Jr. Member
  • **
  • Posts: 68
Gaussian Elimination
« on: February 20, 2018, 09:12:45 am »
I try to convert some of my old TP programs to FP and Visual input.
For the Matrix input I had the following Code

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Input(Var N: Integer; Var Coeff_Mat1: Mat_Array;
  2.   Var Col_Mat1: Col_Array);
  3.  
  4. (*** This Procedure lets the user input the number of equations and the  ***)
  5. (*** augmented matrix of their system of equations                       ***)
  6. (*** ON ENTRY : N => number of equations : UNDEFinED
  7.                 Coeff_Mat1 => coefficient matrix : UNDEFinED
  8.                 Col_Mat1 => column matrix :UNDEFinED
  9.      ON Exit  : N => # of equations input by user
  10.                 Coeff_Mat1 => defined coefficient matrix
  11.                 Col_Mat1 => defined column matrix input by user          ***)
  12.  
  13. Var
  14.   I,J : Integer;  (* loop control and Array indices *)
  15.  
  16. begin
  17.  
  18.  
  19.  //  readln(N);
  20.  
  21.   For I := 1 to N do     { row indice }
  22.   begin
  23.     Writeln('ROW #',I);
  24.     For J := 1 to N do   {column indice }
  25.     begin
  26.       Write('a(',I,',',J,'):');
  27.       readln(Coeff_Mat1[I,J]);    {input of coefficient matrix}
  28.     end;
  29.     Write('c(',I,'):');
  30.     readln(Col_Mat1[I]);          {input of Constant matrix}
  31.   end;
  32.   readln;
  33. end;  (* Procedure Input *)
  34. {---------------------------------------------------------------------------}
Has anyone an Idea how this Input can be achieved  with visual Controls in a simple way?Can I Use T stringGird? The size of the matrices is variable , the max numbers of equations 50 .If I use TStringGird Can I change the quantity of rows and columns dynamically im Program ,depending on the number of equations  N given by the User?
Thanks for the help

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Gaussian Elimination
« Reply #1 on: February 20, 2018, 09:31:32 am »
Code: Pascal  [Select][+][-]
  1. procedure PrepareMatrixGrid(AGrid: TStringGrid; N: Integer);
  2. var
  3.   i, j: Integer;
  4. begin
  5.   AGrid.ColCount := N + AGrid.FixedCols;
  6.   AGrid.RowCount := N + AGrid.FixedRows;
  7.   // Add column headers: 1, 2, 3, ...
  8.   for i:=AGrid.FixedCols to AGrid.ColCount-1 do
  9.     AGrid.Cells[i, 0] :=IntToStr(i - AGrid.FixedCols + 1);
  10.   // Add row headers: 1, 2, 3, ...
  11.   for i:=AGrid.FixedRows to AGrid.RowCount-1 do
  12.     AGrid.Cells[0, i] := IntToStr(i - AGrid.FixedRows + 1]);
  13.   // Preset every cell Aij with 0
  14.   for j:=AGrid.FixedRows to AGrid.RowCount-1 do
  15.     for i := AGrid.FixedCols to AGrid.ColCount-1 do
  16.       Cells[i, j] := '0';
  17. end;
« Last Edit: February 20, 2018, 05:07:58 pm by wp »

jcaser1948

  • Jr. Member
  • **
  • Posts: 68
Re: Gaussian Elimination
« Reply #2 on: February 23, 2018, 05:11:34 pm »
Thans,It works fine

 

TinyPortal © 2005-2018