home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / l / linsys10.zip / SYSDEMO.PAS < prev   
Pascal/Delphi Source File  |  1992-04-06  |  2KB  |  96 lines

  1.  
  2. { --------------------------------------------------------------------------
  3.                                   SYSDEMO.PAS
  4.  
  5.     ---> A sample that shows how to use the MATRICES unit to solve linear
  6.          systems.
  7.  
  8.          (C) 1990, 1992 by Lenimar N. Andrade (CCENDM03@BRUFPB.BITNET)
  9.  
  10.   -------------------------------------------------------------------------- }
  11.  
  12. program SysDemo;
  13.  
  14. {$E+,N+,F+}
  15.  
  16. {$M 65000, 0, 650000}
  17.  
  18. uses
  19.   Matrices;
  20.  
  21. var
  22.   mat: matrix;
  23.   solution: answer;
  24.   i, j, variables: byte;
  25.  
  26. begin
  27.   Writeln;
  28.   Writeln('RESOLUTION OF LINEAR SYSTEMS');
  29.   Writeln;
  30.   Write('How many equations does the system have? ');
  31.   Readln(mat.m);
  32.   Write('How many variables does the system have? ');
  33.   Readln(variables);
  34.   mat.n := variables + 1;
  35.  
  36.   Writeln;
  37.   Writeln('Enter the elements of complete system''s matrix:');
  38.   Writeln;
  39.   for i := 1 to mat.m do
  40.   begin
  41.     Write('Row ', i, ' : ');
  42.     for j := 1 to mat.n do
  43.       Read(mat.a[i, j])
  44.   end;
  45.  
  46.   SolveSystem(mat, solution);
  47.  
  48.   Writeln;
  49.  
  50.   { Case 1: system without solution }
  51.   if solution.impossible then
  52.   begin
  53.     Writeln('Impossible system.');
  54.     Halt
  55.   end;
  56.  
  57.   { Case 2: system with more equations than variables }
  58.   if solution.ManyEq then
  59.   begin
  60.     Writeln('Warning: some equations were not considered.');
  61.     Writeln;
  62.   end;
  63.  
  64.   { Case 3: determined system }
  65.   if solution.DetSyst then
  66.   begin
  67.     Writeln('Unique solution:');
  68.     Writeln;
  69.     Write('     (');
  70.     for i := 1 to mat.n - 1 do
  71.       Write(solution.ParticularSolution[i]:8:2);
  72.     Writeln(' )');
  73.     Halt;
  74.   end;
  75.  
  76.   { Case 4: undetermined system }
  77.   Writeln('Particular solution:');
  78.   Writeln;
  79.   Write('     (');
  80.   for i := 1 to mat.n -1 do
  81.     Write(solution.ParticularSolution[i]:8:2);
  82.   Writeln(' )');
  83.   Writeln;
  84.   Writeln('Any other solution will be a sum of the particular solution and');
  85.   Writeln('a linear combination of the vectors bellow:');
  86.   Writeln;
  87.   for i := 1 to solution.x.m do
  88.   begin
  89.     Write('     ( ');
  90.     for j := 1 to solution.x.n do
  91.       Write(solution.x.a[i, j]:8:2);
  92.     Writeln(' )');
  93.   end;
  94.  
  95. end.
  96.