home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / MISC / MATH / CLA20.ZIP / JORDEMO.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1991-02-08  |  2.6 KB  |  106 lines

  1. program JorDemo;
  2.  
  3. { --------------------------------------------------------------------------
  4.                                   JORDEMO.PAS
  5.  
  6.      ---> A  sample that shows how to use the JORDAN unit to calculate
  7.           the Jordan canonical form of a matrix and its basis.
  8.  
  9.           (C) 1990, 1992 by Lenimar N. Andrade (CCENDM03@BRUFPB.BITNET)
  10.  
  11.   -------------------------------------------------------------------------- }
  12.  
  13. {$E+,N+}
  14.  
  15. {$M 65520, 0, 655200}
  16.  
  17. uses
  18.   Equation, Matrices, BasFPTC, LinAlg, Jordan, Crt;
  19.  
  20. var
  21.   mat, basis, JordanForm: matrix;
  22.   p: polynomial;
  23.   w: eigenvalues;
  24.   HappenedError, FoundBasis: boolean;
  25.   min: minimal;
  26.   diagonal: DiagBlocks;
  27.   i, j, xpos, ypos: byte;
  28.  
  29. begin
  30.   Writeln;
  31.   Writeln('CALCUTATING JORDAN CANONICAL FORM OF A MATRIX');
  32.   Writeln;
  33.   Write('Which is matrix''s order? ');
  34.   Readln(mat.m);
  35.   mat.n := mat.m;
  36.  
  37.   Writeln;
  38.   Writeln('Enter the elements of matrix M:');
  39.   Writeln;
  40.   for i := 1 to mat.m do
  41.   begin
  42.     Write('Row ', i, ' : ');
  43.     for j := 1 to mat.n do
  44.       Read(mat.a[i, j])
  45.   end;
  46.  
  47.   Writeln;
  48.   xpos := WhereX; ypos := WhereY;
  49.   Write('Calculating the characteristic polynomial...');
  50.   CharPoly(mat, p);
  51.   GoToXY(xpos, ypos); ClrEol;
  52.   Write('Calculating the eigenvalues...');
  53.   CalcEigenvalues(p, w);
  54.   GoToXY(xpos, ypos); ClrEol;
  55.   Write('Calculating the minimal polynomial...');
  56.   MinPoly(mat, w, min);
  57.   GoToXY(xpos, ypos); ClrEol;
  58.   Write('Calculating Jordan form...');
  59.   CalculatesJordanForm(mat, w, min, HappenedError, diagonal);
  60.   GoToXY(xpos, ypos); ClrEol;
  61.   Write('Formating Jordan matrix...');
  62.   FormatsJordanMatrix(diagonal, JordanForm, mat.m, w, min);
  63.   GoToXY(xpos, ypos); ClrEol;
  64.   Write('Calculating the Jordan basis...');
  65.   FoundBasis := false;
  66.   if (w.QuantComplex = 0) then
  67.     CalculatesJordanBasis(mat, diagonal, min, basis, FoundBasis);
  68.  
  69.   if HappenedError then
  70.   begin
  71.     GoToXY(xpos, ypos); ClrEol;
  72.     Writeln('*** ERROR: It wasn''t possible find M''s Jordan form ***');
  73.     Halt;
  74.   end;
  75.   GoToXY(xpos, ypos); ClrEol;
  76.   Writeln('Jordan canonical form of M:');
  77.   Writeln;
  78.   for i := 1 to mat.m do
  79.   begin
  80.     for j := 1 to mat.n do
  81.       Write(JordanForm.a[i, j] :8:2);
  82.     Writeln;
  83.   end;
  84.  
  85.   if not FoundBasis then
  86.   begin
  87.     Writeln;
  88.     Writeln('*** I can''t find the Jordan basis in this case ***');
  89.     Halt;
  90.   end;
  91.   Writeln;
  92.   Writeln('Basis related to Jordan form of M:');
  93.   Writeln;
  94.   for i := 1 to mat.m do
  95.   begin
  96.     Write('(');
  97.     for j := 1 to mat.n do
  98.     begin
  99.       Write(basis.a[i, j] :8:2);
  100.       if (j < mat.n) then Write(', ');
  101.     end;
  102.     Writeln(' )');
  103.   end;
  104.  
  105. end.
  106.