Advertisement
daniv1

Untitled

Nov 15th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.94 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  9.   Grids;
  10.  
  11. type
  12.     Matr = Array[1..3,1..3] of Real;
  13. Vec = Array[1..3] of Real;
  14.   { TForm1 }
  15.  
  16.   TForm1 = class(TForm)
  17.     Button1: TButton;
  18.     Button2: TButton;
  19.     Label1: TLabel;
  20.     Label2: TLabel;
  21.     Label3: TLabel;
  22.     StringGrid1: TStringGrid;
  23.     StringGrid2: TStringGrid;
  24.     StringGrid3: TStringGrid;
  25.     procedure Button1Click(Sender: TObject);
  26.     procedure Button2Click(Sender: TObject);
  27.   private
  28.     { private declarations }
  29.   public
  30.     { public declarations }
  31.   end;
  32.  
  33. var
  34.   Form1: TForm1;
  35.  
  36. implementation
  37.  
  38. {$R *.lfm}
  39.  
  40. { TForm1 }
  41.  
  42. procedure TForm1.Button2Click(Sender: TObject);
  43. begin
  44.   CLOSE
  45. end;
  46.  
  47.  
  48. procedure TForm1.Button1Click(Sender: TObject);
  49. Var A : Matr;
  50. b: Vec;
  51. det,detx,dety,detz,x,y,z,eps:real;
  52. i, j, N: Integer;
  53. begin
  54. N := 3;
  55. eps :=0.0001;
  56. For i:=1 to N do
  57. For j:=1 to N do
  58. Begin
  59. a[i,j] := StrToFloat(StringGrid1.Cells[j - 1,i - 1]);
  60. b[j] := StrToFloat(StringGrid2.Cells[0,j - 1]);
  61. End;
  62. Det:=A[1,1]*A[2,2]*A[3,3]+A[2,1]*A[1,3]*A[3,2]+A[1,2]*A[2,3]*A[3,1]-A[3,1]*A[2,2]*A[1,3]-A[1,1]*A[3,2]*A[2,3]-A[2,1]*A[1,2]*A[3,3];
  63.   if abs(Det)<eps then
  64.     begin
  65.           ShowMessage('rozvjazkiv nemaje');
  66.           close
  67.           end
  68.   else
  69.  if abs(det)>0 then
  70.    begin
  71. Detx:=b[1]*A[2,2]*A[3,3]+b[2]*A[1,3]*A[3,2]+A[1,2]*A[2,3]*b[3]-b[3]*A[2,2]*A[1,3]-b[1]*A[3,2]*A[2,3]-b[2]*A[1,2]*A[3,3];
  72. Dety:=A[1,1]*b[2]*A[3,3]+A[2,1]*A[1,3]*b[3]+b[1]*A[2,3]*A[3,1]-A[3,1]*b[2]*A[1,3]-A[1,1]*b[3]*A[2,3]-A[2,1]*b[1]*A[3,3];
  73. Detz:=A[1,1]*A[2,2]*b[3]+A[2,1]*b[1]*A[3,2]+A[1,2]*b[2]*A[3,1]-A[3,1]*A[2,2]*b[1]-A[1,1]*A[3,2]*b[2]-A[2,1]*A[1,2]*b[3];
  74.  
  75. x:=Detx/Det;
  76. y:=Dety/Det;
  77. z:=Detz/Det;
  78.  
  79. StringGrid3.Cells[0,0]:=floattostr(x);
  80. StringGrid3.Cells[0,1]:=floattostr(y);
  81. StringGrid3.Cells[0,2]:=floattostr(z);
  82. end;
  83. end;
  84.  
  85. end.
  86. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement