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

3.11 Краевая задача

3.11.1 Листинг

unit UnitKrZ11;

interface

uses

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

Dialogs, StdCtrls, Grids, Math, ExtCtrls, TeeProcs, TeEngine, Chart,

Series, jpeg, Menus;

type

TForm1 = class(TForm)

sg1: TStringGrid;

bt2: TButton;

ed3: TEdit;

Label7: TLabel;

Label1: TLabel;

Label2: TLabel;

ed9: TEdit;

ch1: TChart;

Series1: TLineSeries;

ed2: TEdit;

ed1: TEdit;

ed4: TEdit;

ed5: TEdit;

ed6: TEdit;

ed7: TEdit;

ed8: TEdit;

sg2: TStringGrid;

bt1: TButton;

lbl10: TLabel;

lbl1: TLabel;

lbl2: TLabel;

lbl3: TLabel;

lbl4: TLabel;

lbl5: TLabel;

lbl6: TLabel;

Image1: TImage;

lbl9: TLabel;

lbl7: TLabel;

bvl1: TBevel;

Label3: TStaticText;

Label4: TStaticText;

Label5: TStaticText;

Label6: TStaticText;

Label8: TStaticText;

Label9: TStaticText;

Label10: TStaticText;

Label11: TStaticText;

Image2: TImage;

procedure bt2Click(Sender: TObject);

procedure bt1Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

const max=50;

type vector=array[0..max] of double;

var

alfa1,beta1,alfa2,beta2,c1,c2,h,x,y: double;

a,b,n,i,j: integer;

Am,Bm,Cm,Dm,Pm,Qm,Xm: vector;

Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.bt1Click(Sender: TObject); //Кнопка ОК

begin

bt1.Enabled:=false; bt2.Visible:=true; sg1.Visible:=true;

a:=StrToInt(ed1.Text); b:=StrToInt(ed2.Text);

alfa1:=StrToFloat(ed3.Text); beta1:=StrToFloat(ed4.Text);

c1:=StrToFloat(ed5.Text);

alfa2:=StrToFloat(ed6.Text); beta2:=StrToFloat(ed7.Text);

c2:=StrToFloat(ed8.Text);

h:=StrToFloat(ed9.Text);

if frac((b-a)/h)>0.999999999999 then

n:=round((b-a)/h)

else begin

ShowMessage('Выбранный шаг не позволяет поделить заданный отрезок на четное колличество отрезков!');

h:=(b-a)/trunc((b-a)/h);

n:=round((b-a)/h);

ShowMessage('Шаг изменнен на h = '+FloatToStr(h));

end;

ShowMessage('Колличество отрезков n = '+IntToStr(n));

ed9.Text:=FloatToStr(h);

sg1.RowCount:=n+1; sg1.ColCount:=n+3;

sg2.RowCount:=n+2;

sg1.Cells[0,0]:='X'+IntToStr(0)+'='+IntToStr(a); sg1.Cells[0,n]:='X'+IntToStr(n)+'='+IntToStr(b);

sg1.Cells[1,0]:=FloatToStr(beta1*h-alfa1);

sg1.Cells[2,0]:=FloatToStr(alfa1);

sg1.Cells[n+2,0]:=FloatToStr(c1*h);

sg1.Cells[n,n]:=FloatToStr(-2*alfa2);

sg1.Cells[n+1,n]:=FloatToStr(beta2*(h*h)+alfa2);

sg1.Cells[n+2,n]:=FloatToStr(c2*(h*h));

x:=a+h;

for i:=1 to n-1 do begin

sg1.Cells[0,i]:='X'+IntToStr(i)+'='+FloatToStr(x);

sg1.Cells[n+2,i]:=FloatToStr(0);

sg1.Cells[i,i]:=FloatToStr(2);

sg1.Cells[i+1,i]:=FloatToStr((-4)-(x*h)-(2*h*h));

sg1.Cells[i+2,i]:=FloatToStr(2-(x*h));

x:=x+h;

end;

for i:=0 to sg1.ColCount-1 do

for j:=0 to sg1.RowCount-1 do

if sg1.Cells[i,j]='' then sg1.Cells[i,j]:='0';

end;

procedure TForm1.bt2Click(Sender: TObject); //Кнопка Решить

var okr: double;

begin

sg2.Visible:=true; ch1.Visible:=true;

bt2.Enabled:=false;

for i:=0 to n do begin //заполняем векторы исходными данными

Dm[i]:=StrToFloat(sg1.Cells[n+2,i]);

j:=i+1;

if j=1 then Am[i]:=0

else Am[i]:=StrToFloat(sg1.Cells[j-1,i]);

Bm[i]:=-(StrToFloat(sg1.Cells[j,i]));

if j=n+1 then Cm[i]:=0

else Cm[i]:=StrToFloat(sg1.Cells[j+1,i]);

end;

for i:=0 to sg1.RowCount-1 do

sg1.Rows[i].Clear;

sg1.FixedCols:=0; sg1.FixedRows:=1; sg1.ColCount:=8;

sg1.RowCount:=n+2;

sg1.Cells[0,0]:='i'; sg1.Cells[1,0]:='Ai'; sg1.Cells[2,0]:='Bi'; sg1.Cells[3,0]:='i';

sg1.Cells[4,0]:='Di'; sg1.Cells[5,0]:='Pi'; sg1.Cells[6,0]:='Qi'; sg1.Cells[7,0]:='Yi';

okr:=Cm[0]/Bm[0]; Pm[0]:=RoundTo(okr, -5); //подсчет прогоночных коэффициентов

okr:=-Dm[0]/Bm[0]; Qm[0]:=RoundTo(okr, -5);

for i:=1 to n do

begin

Pm[i]:=Cm[i]/(Bm[i]-Am[i]*Pm[i-1]);

okr:=Pm[i];

Pm[i]:=RoundTo(okr, -5);

Qm[i]:=(Am[i]*Qm[i-1]-Dm[i])/(Bm[i]-Am[i]*Pm[i-1]);

okr:=Qm[i];

Qm[i]:=RoundTo(okr, -5);

end;

Xm[n]:=Qm[n];//вычисление корней

for i:=n-1 downto 0 do

begin

Xm[i]:=Pm[i]*Xm[i+1]+Qm[i];

okr:=Xm[i];

Xm[i]:=RoundTo(okr, -5);

end;

for i:=0 to n+1 do //печать таблицы

begin

sg1.Cells[0,i+1]:=IntToStr(i);

sg1.Cells[1,i+1]:=FloatToStr(Am[i]);

sg1.Cells[2,i+1]:=FloatToStr(Bm[i]);

sg1.Cells[3,i+1]:=FloatToStr(Cm[i]);

sg1.Cells[4,i+1]:=FloatToStr(Dm[i]);

sg1.Cells[5,i+1]:=FloatToStr(Pm[i]);

sg1.Cells[6,i+1]:=FloatToStr(Qm[i]);

sg1.Cells[7,i+1]:=FloatToStr(Xm[i]);

end;

x:=a; Series1.Clear;

sg2.Cells[0,0]:='X'; sg2.Cells[1,0]:='Y';

for i:=0 to n+1 do begin //печать корней

sg2.Cells[0,i+1]:=FloatToStr(x);

sg2.Cells[1,i+1]:=FloatToStr(Xm[i]);

Series1.AddXY(x,Xm[i],'',clRed);

x:=x+h;

end;

end;

end.