Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Отчет Расчетка ВЫЧМАТ.docx
Скачиваний:
0
Добавлен:
01.03.2025
Размер:
3.19 Mб
Скачать

3.2 Метод прогонки

В ходе работы программы были подсчитаны корни СЛАУ:

Прогоночные коэффициенты:

3.2.1 Листинг

unit Progonka;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls, Grids, ExtCtrls, jpeg;

type

TForm1 = class(TForm)

StringGrid1: TStringGrid;

Button1: TButton;

Edit1: TEdit;

Button2: TButton;

Korni: TLabel;

mmo1: TMemo;

Label1: TLabel;

Bevel1: TBevel;

Panel: TPanel;

Label4: TLabel;

Label5: TLabel;

Edit2: TEdit;

Button3: TButton;

Button4: TButton;

lbl7: TLabel;

bvl1: TBevel;

Button5: TButton;

lbl8: TLabel;

Edit3: TEdit;

lbl10: TLabel;

lbl1: TLabel;

lbl2: TLabel;

lbl3: TLabel;

lbl4: TLabel;

lbl5: TLabel;

lbl6: TLabel;

Image1: TImage;

lbl9: TLabel;

procedure Button1Click(Sender: TObject);

procedure Button2Click(Sender: TObject);

procedure Button3Click(Sender: TObject);

procedure Button4Click(Sender: TObject);

procedure FormCreate(Sender: TObject);

procedure Button5Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

type

MasEl=array [0..100] of extended;

MasExt=array [0..100] of extended;

var

Q,P,x :MasEl;

a,b,c,d:MasExt;

f: TextFile;

Form1: TForm1;

i,j,n,k,raz,p1,l1,znak : integer;

st: string;

S:real;

tempint: Integer;

tempstr: String;

Tempfloat: Real;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

begin

n:=StrToInt(Edit1.text);

for i:=1 to n do

for j:=1 to n+1 do

StringGrid1.Cells[j-1,i-1]:='';

StringGrid1.ColCount:=n+1;

StringGrid1.RowCount:=n;

StringGrid1.Height:=n*26+1;

StringGrid1.Width:=(n+1)*66+1;

StringGrid1.Visible:=true;

Button2.visible:=true;

mmo1.text:='';

Form2.memo1.text:='';

Button2.Enabled:=True;

end;

procedure TForm1.Button2Click(Sender: TObject);

Var

i,j,n,k,raz : integer;

Q,P,x :MasEl;

a,b,c,d:MasExt;

st:string;

S,R:real;

flag: boolean;

Begin

n:=StrToInt(Edit1.text);

Form2.memo1.lines.Add('P[0]= 1');

Form2.memo1.lines.Add('Q[0]= 1');

for i:=1 to n do

begin

b[i]:=StrToFloat(StringGrid1.Cells[i-1,i-1]); //главная диагональ

if i<n then

begin

c[i]:=StrToFloat(StringGrid1.Cells[i,i-1]); //нижняя диагональ

a[i+1]:=StrToFloat(StringGrid1.Cells[i-1,i]); //верхняя диагональ

end;

d[i]:=StrToFloat(StringGrid1.Cells[n,i-1]) //свободные члены

end;

//P[i], Q[i] - метод прогонки

for i:=1 to n do

begin

P[i]:=(-c[i])/(b[i]+a[i]*P[i-1]);

Q[i]:=(d[i]-a[i]*Q[i-1])/(b[i]+a[i]*P[i-1]);

form2.memo1.lines.Add('P['+IntToStr(i)+']= '+FloatToStr(P[i]));

form2.memo1.lines.Add('Q['+IntToStr(i)+']= '+FloatToStr(Q[i]));

end;

x[n]:=Q[n];

for i:=(n-1) downto 1 do

x[i]:=P[i]*x[i+1]+Q[i];

for i:=1 to n do

mmo1.lines.Add('X['+FloatToStr(i)+']= '+FloatToStr(x[i]));

Button4.Visible:=true;

Exit;

Button2.Enabled:=False;

Button4.Visible:=True;

end;

procedure TForm1.Button3Click(Sender: TObject);

Var

i,j,n,k,raz : integer;

Q,P,x :MasEl;

a,b,c,d:array[1..100] of integer;

begin

//случайное заполнение матрицы

n:=StrToInt(Edit1.text);

Randomize;

for i:=1 to n do

begin

repeat

b[i]:=(Random(2*StrToInt(Edit2.text)+1)-StrToInt(Edit2.text));

until b[i]<>0;

StringGrid1.cells[i-1,i-1]:=FloatToStr(b[i]);

if i<n then

begin

c[i]:=Random(Abs(2*b[i]+1))-Abs(b[i]);

StringGrid1.cells[i,i-1]:=FloatToStr(c[i]);

end

else c[i]:=0;

if i>1 then

begin

a[i]:=Random(2*(Abs(b[i])-Abs(c[i]))+1)-(Abs(b[i])-Abs(c[i]));

StringGrid1.cells[i-2,i-1]:=FloatToStr(a[i]);

end

else a[i]:=0;

d[i]:=a[i]+b[i]+c[i];

StringGrid1.cells[n,i-1]:=FloatToStr(d[i]);

end;

end;

procedure TForm1.Button4Click(Sender: TObject);

begin

Form2.Show;

end;

procedure TForm1.FormCreate(Sender: TObject);

begin

mmo1.Text:='';

end;

procedure TForm1.Button5Click(Sender: TObject);

var lol: integer;

begin

lol:=StrToInt(Edit3.Text);

Randomize;

for p1:= 0 to StringGrid1.RowCount do

for l1:= 0 to StringGrid1.ColCount do

begin

znak:=Random(2);

if znak=1 then znak:=-1 else znak:=1;

tempint:=Random(100);

tempstr:=IntToStr(tempint);

tempfloat:=StrToFloat(tempstr);

StringGrid1.Cells[p1,l1]:=FloatToStr(znak*(Random(lol+1)+tempfloat*0.01));

end;

end;

end.