Скачиваний:
10
Добавлен:
25.03.2015
Размер:
3.68 Кб
Скачать
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, OleCtnrs, StdCtrls, Buttons;

type
TForm1 = class(TForm)
mm1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
btn1: TBitBtn;
olcntnr1: TOleContainer;
lbl1: TLabel;
lbl2: TLabel;
lbl3: TLabel;
lbl4: TLabel;
lbl5: TLabel;
lbl6: TLabel;
lbl7: TLabel;
lbl8: TLabel;
N4: TMenuItem;
lbl9: TLabel;
lbl10: TLabel;
lbl11: TLabel;
lbl12: TLabel;
lbl13: TLabel;
lbl14: TLabel;
lbl15: TLabel;
lbl16: TLabel;
lbl17: TLabel;
lbl18: TLabel;
procedure N1Click(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure N3Click(Sender: TObject);
procedure N4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
const n=3; eps=0.0001;
type matr=array[1..n,1..n+1] of real;
var
a:matr;
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.N1Click(Sender: TObject);
var f:textfile; i,j:Byte;
begin
assignfile(f,'matr.txt');
Reset(f);
for i:=1 to n do
for j:=1 to n+1 do read(f,a[i,j]);
CloseFile(f);
end;

procedure TForm1.N2Click(Sender: TObject);
var i,j:Byte; alfa:matr;
f:textfile;
begin
for i:=1 to n do
for j:=1 to n do if i=j then alfa[i,j]:=0
else alfa[i,j]:=-a[i,j]/a[i,i];
for i:=1 to n do alfa[i,4]:=a[i,4]/a[i,i];


AssignFile(f,'alfa.txt');
Rewrite(f);
Writeln(f);
for i:=1 to n do begin
for j:=1 to n+1 do write(f,' ',alfa[i,j]:6:2);
Writeln(f);
end;
Closefile(f);
end;

procedure TForm1.N3Click(Sender: TObject);
var i,j,k:Byte;
x1,x2,x3,y1,y2,y3:Real;
n1,n2,n3:Real;
alfa:matr;
f:TextFile;
begin
AssignFile(f,'alfa.txt');
Reset(f);
Readln(f);
for i:=1 to n do
for j:=1 to n+1 do Read(f,alfa[i,j]);
k:=0;
y1:=0; y2:=0; y3:=0;
repeat
x1:=y1; x2:=y2; x3:=y3;
y1:=alfa[1,2]*x2+alfa[1,3]*x3+alfa[1,4];
y2:=alfa[2,1]*x1+alfa[2,3]*x3+alfa[2,4];
y3:=alfa[3,1]*x1+alfa[3,2]*x2+alfa[3,4];
k:=k+1;
until (Abs(x1-y1)<eps)and(Abs(x2-y2)<eps)and(Abs(x3-y3)<eps)or(k>30);
lbl1.Caption:=lbl1.Caption+' '+floattostr(k);
lbl2.Caption:=lbl2.Caption+' '+format('%5.4f',[x1]);
lbl3.Caption:=lbl3.Caption+' '+format('%5.4f',[x2]);
lbl4.Caption:=lbl4.Caption+' '+format('%5.4f',[x3]);

n1:=8*x1-3*x2+2*x3-7;
n2:=4*x1-8*x2+2*x3+2;
n3:=5*x1-6*x2-14*x3-13;
lbl9.Caption:=lbl9.Caption+' '+format('%5.4f',[n1]);
lbl10.Caption:=lbl10.Caption+' '+format('%5.4f',[n2]);
lbl11.Caption:=lbl11.Caption+' '+format('%5.4f',[n3]);
end;

procedure TForm1.N4Click(Sender: TObject);
var i,j,k:Byte;
x1,x2,x3,y1,y2,y3:Real;
n1,n2,n3:Real;
alfa:matr;
f:TextFile;
begin
AssignFile(f,'alfa.txt');
Reset(f);
Readln(f);
for i:=1 to n do
for j:=1 to n+1 do Read(f,alfa[i,j]);
k:=0;
y1:=0; y2:=0; y3:=0;
repeat
x1:=y1; x2:=y2; x3:=y3;
y1:=alfa[1,2]*x2+alfa[1,3]*x3+alfa[1,4];
y2:=alfa[2,1]*y1+alfa[2,3]*x3+alfa[2,4];
y3:=alfa[3,1]*y1+alfa[3,2]*y2+alfa[3,4];
k:=k+1;
until (Abs(x1-y1)<eps)and(Abs(x2-y2)<eps)and(Abs(x3-y3)<eps)or(k>30);
lbl5.Caption:=lbl5.Caption+' '+floattostr(k);
lbl6.Caption:=lbl6.Caption+' '+format('%5.4f',[x1]);
lbl7.Caption:=lbl7.Caption+' '+format('%5.4f',[x2]);
lbl8.Caption:=lbl8.Caption+' '+format('%5.4f',[x3]);

n1:=8*x1-3*x2+2*x3-7;
n2:=4*x1-8*x2+2*x3+2;
n3:=5*x1-6*x2-14*x3-13;
lbl12.Caption:=lbl12.Caption+' '+format('%5.4f',[n1]);
lbl13.Caption:=lbl13.Caption+' '+format('%5.4f',[n2]);
lbl14.Caption:=lbl14.Caption+' '+format('%5.4f',[n3]);
end;

end.
Соседние файлы в папке Delphi
  • #
    25.03.2015188 б11Project1.dpr
  • #
    25.03.2015876 б10Project1.res
  • #
    25.03.201510.47 Кб10Unit1.dcu
  • #
    25.03.201551 б10Unit1.ddp
  • #
    25.03.2015402.9 Кб10Unit1.dfm
  • #
    25.03.20153.68 Кб10Unit1.pas