я не совсем уверен, но вот накидал...
Код | unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids, ExtCtrls, Buttons;
const n1=7; n2=7; type matr=array [1..n1,1..n2] of real; V=array [1..n1] of real; type TFrm = class(TForm) BitBtn1: TBitBtn; RangMatrixEdt: TLabeledEdit; EpsEdt: TLabeledEdit; InputGrd: TStringGrid; OutputGrd: TStringGrid; LblA: TLabel; LblB: TLabel; LabeledEdit1: TLabeledEdit; StringGrid1: TStringGrid; StringGrid2: TStringGrid; StringGrid3: TStringGrid; BitBtn2: TBitBtn; procedure FormCanResize(Sender: TObject; var NewWidth, NewHeight: Integer; var Resize: Boolean); procedure InputGrdSetEditText(Sender: TObject; ACol, ARow: Integer; const Value: String); procedure FormActivate(Sender: TObject); procedure BitBtn1Click(Sender: TObject); procedure Vvod_Matr(var mat:matr; var ur:integer; var S:V); procedure swop(var m1:matr;var m2:matr;u:integer); procedure Matrinvers(p,q:integer; m1:matr; var m2:matr; var ur:integer;var S:V); procedure Out_Matr(m:matr;u:integer); procedure BitBtn2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Frm: TFrm; Matr_Gl,Matr_Inv:matr; p,q,u:integer; S1:V;
implementation uses math, Unit2; {$R *.dfm}
procedure TFrm.Vvod_Matr(var mat:matr; var ur:integer; var S:V); var i,j: integer; begin write('Skolko uravneniy ' ); readln(ur); for i:=1 to StrToInt(RangMatrixEdt.Text) do for j:=1 to StrToInt(RangMatrixEdt.Text) do mat[i, j]:=StrToInt(InputGrd.Cells[j,i]); for i:=1 to StrToInt(RangMatrixEdt.Text) do s[i]:=StrToInt(outputGrd.cells[0, i]); end;
procedure TFrm.Out_Matr(m:matr;u:integer); var i,j:integer; begin for i:=1 to u do for j:=1 to u do StringGrid1.Cells[j,i]:=FloatToStr(m[i,j]); end;
procedure TFrm.swop(var m1:matr;var m2:matr;u:integer); var i,j:integer; buf:real; begin for i:=1 to u do for j:=1 to u do begin buf:=m1[i,j]; m1[i,j]:=m2[i,j]; m2[i,j]:=buf; end; end;
procedure TFrm.Matrinvers(p,q:integer; m1:matr; var m2:matr; var ur:integer;var S:V); var i,j: integer; begin for i:=1 to ur do for j:=1 to ur do begin m2[i,j]:=m1[i,j]-((m1[i,p]*m1[q,j])/m1[q,p]); if j=p then m2[i,j]:=0; if i=q then m2[q,j]:=m1[q,j]; end; for i:=1 to n2 do begin if i=q then S[i]:=S[q] else S[i]:=S[i]-((m1[i,p]*S[q])/m1[q,p]); end; end;
procedure TFrm.BitBtn1Click(Sender: TObject); var i:Integer; begin Vvod_Matr(Matr_Gl,u,S1); q:=StrToInt(EpsEdt.text); p:=StrToInt(LabeledEdit1.text); Matrinvers(p,q,Matr_Gl,Matr_Inv,u,S1); swop(Matr_Gl,Matr_Inv,u); Out_Matr(Matr_Gl,u); for i:=1 to u do StringGrid2.Cells[0, i]:=FloatToStr(S1[i]); for i:=1 to u do StringGrid3.Cells[0, i]:=FloatToStr(S1[i]/Matr_Gl[i,i]); end;
procedure TFrm.FormCanResize(Sender: TObject; var NewWidth, NewHeight: Integer; var Resize: Boolean); begin Resize:=false; end;
procedure TFrm.InputGrdSetEditText(Sender: TObject; ACol, ARow: Integer; const Value: String); var floatC:Double; begin if(TryStrToFloat(InputGrd.Cells[ACol, ARow], floatC)=False)then ShowMessage('Ïðîâåðüòå ïðàâèëüíîñòü ââåäåííûõ äàííûõ!!!'+#10#13+'Äàííûå äîëæíû ââîäèòüñÿ ÷åðåç çàïÿòóþ...'); end;
procedure TFrm.FormActivate(Sender: TObject); begin RangMatrixEdt.SetFocus; end;
procedure TFrm.BitBtn2Click(Sender: TObject); var tList:TStringList; i:Integer; begin tList:=TStringList.Create; try for i:=1 to u do tList.Text:=tList.Text+' '+StringGrid3.Cells[0, i]; tList.SaveToFile('a.txt'); finally tList.Free; end; end;
end.
|
|