ПРОГРАММА
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit; Edit10: TEdit; Edit11: TEdit; Edit12: TEdit;
Edit13: TEdit; Edit14: TEdit; Edit15: TEdit; Edit16: TEdit;
Edit2: TEdit; Edit3: TEdit; Edit4: TEdit; Edit5: TEdit;
Edit6: TEdit; Edit7: TEdit; Edit8: TEdit; Edit9: TEdit;
Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel;
Label5: TLabel; Label6: TLabel; Label7: TLabel; Label8: TLabel;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
const
m=3; n=4;
Type
mas = array [1..m,1..n] of real;
vek = array [1..m] of real;
Procedure zejd(A:mas; var x:vek; Eps:real; m,n:integer);
implementation
{$R *.lfm}
{ TForm1 } {Процедура: метод Зейделя}
Procedure zejd(A:mas; var x:vek; Eps:real; m,n:integer);
var
B:mas; xx:vek; s:real; i,j,k:byte; bol:boolean;
begin
for i:=1 to m do begin
s:=a[i,i];
for j:=1 to n do begin
b[i,j]:=a[i,j]/s;
end;
end;
for i:=1 to m do begin
a[i,1]:=b[i,n];
k:=1;
for j:=1 to n do
if j<>i then begin
k:=k+1;
a[i,k]:=b[i,j]*(-1);
end;
end;
{ Итерационный процесс }
x[1]:=a[1,1];
for i:=2 to m do x[i]:=0;
xx:=x;
k:=0;
repeat
k:=k+1;
for i:=1 to m do begin
s:=0;
for j:=1 to m do
s:=s+a[i,j]*X[j];
X[i]:=s;
end;
bol:=true;
for i:=1 to m do
if abs(x[i]-xx[i])>eps then bol:=false;
xx:=x;
until bol;
end;
{ Кнопка }
procedure TForm1.Button1Click(Sender: TObject);
var
A:mas;
x:vek;
i,j:integer; Eps:real;
begin
eps:=StrToFloat(Form1.Edit16.Text);
{Исходная система линейных уравнениия:}
a[1,1]:=StrToFloat(Form1.Edit1.Text);
a[1,2]:=StrToFloat(Form1.Edit2.Text);
a[1,3]:=StrToFloat(Form1.Edit3.Text);
a[1,4]:=StrToFloat(Form1.Edit10.Text);
a[2,1]:=StrToFloat(Form1.Edit4.Text);
a[2,2]:=StrToFloat(Form1.Edit5.Text);
a[2,3]:=StrToFloat(Form1.Edit6.Text);
a[2,4]:=StrToFloat(Form1.Edit11.Text);
a[3,1]:=StrToFloat(Form1.Edit7.Text);
a[3,2]:=StrToFloat(Form1.Edit8.Text);
a[3,3]:=StrToFloat(Form1.Edit9.Text);
a[3,4]:=StrToFloat(Form1.Edit12.Text);
zejd(A, x, Eps, m, n);
Form1.Edit13.Text:=FloatToStr(x[1]);
Form1.Edit14.Text:=FloatToStr(x[2]);
Form1.Edit15.Text:=FloatToStr(x[3]);
end;
end.