Студопедия

КАТЕГОРИИ:

АстрономияБиологияГеографияДругие языкиДругоеИнформатикаИсторияКультураЛитератураЛогикаМатематикаМедицинаМеханикаОбразованиеОхрана трудаПедагогикаПолитикаПравоПсихологияРиторикаСоциологияСпортСтроительствоТехнологияФизикаФилософияФинансыХимияЧерчениеЭкологияЭкономикаЭлектроника


Описание Основных процедур.




Для построения функции используем: function f(x:real):real

Для построения кубических сплайнов используем процедуры: ButStartClick и ButEstClick.

Прорисовка осей осуществляется с помощью одного из методов Series - функции .AddXY входящей в компонент Chart (Chart).

 

Приложение 1.Скриншоты тестирования программы.

Приложение 2.Листинг программы.

 

Вывод.Кубический сплайн с краевыми условиями непрерывной на отрезке функции равномерно сходится к функции при N → ∞.

Кубический сплайн с начальными условиями непрерывной на отрезке функции расходится при N → ∞.

Приложение 1.Тестирование программы (N=2, кубический сплайн с начальными условиями, S0=1,S1=1).

Приложение 1.Тестирование программы (N=8, кубический сплайн с начальными условиями, S0=1,S1=1).

Приложение 1.Тестирование программы (N=2, кубический сплайн с краевыми условиями, S0=0,S1=0).

Приложение 1.Тестирование программы (N=10, кубический сплайн с краевыми условиями, S0=0,S1=0).

Приложение 2. Листинг программы на Delphi.

unit Unit1;

 

interface

 

uses

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

Dialogs, jpeg, ExtCtrls, StdCtrls, Unit2;

 

type

TVector=array of real;

TForm1 = class(TForm)

ImageF: TImage;

Label1: TLabel;

ButF: TButton;

ButExit: TButton;

ButClearF: TButton;

Panel1: TPanel;

Label2: TLabel;

EditQt: TEdit;

IntCond: TGroupBox;

Label3: TLabel;

EditStart: TEdit;

Label4: TLabel;

EditSecond: TEdit;

ButStart: TButton;

ButClearSpInt: TButton;

Panel2: TPanel;

Label5: TLabel;

EditX: TEdit;

Label6: TLabel;

LabX: TLabel;

Label7: TLabel;

LabS1x: TLabel;

Button1: TButton;

Button2: TButton;

GroupBox1: TGroupBox;

Label8: TLabel;

Label9: TLabel;

Button3: TButton;

Label10: TLabel;

ButEst: TButton;

Button5: TButton;

LabS2x: TLabel;

procedure ButFClick(Sender: TObject);

procedure ButExitClick(Sender: TObject);

procedure ButClearFClick(Sender: TObject);

procedure ButStartClick(Sender: TObject);

procedure ButClearSpIntClick(Sender: TObject);

procedure Button1Click(Sender: TObject);

procedure Button2Click(Sender: TObject);

procedure ButEstClick(Sender: TObject);

procedure Button3Click(Sender: TObject);

procedure Button5Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

 

var

Form1: TForm1;

x_tm:real;

VectX_tm,VectS_tm,VectF_tm:TVector;

 

implementation

 

{$R *.dfm}

 

//Построение функции f(x)

function f(x:real):real;

begin

result:=(1+5*sin(x))/(1+25*x*x);

end;

 

procedure TForm1.ButFClick(Sender: TObject);

var i:integer;

tmp:integer;

step:real;

begin

if not Form2.Showing then

Form2.Show;

tmp:=100;

step:=2/tmp;

for i:=0 to tmp do

Form2.Series1.AddXY(-1+i*step,f(-1+i*step),'');

end;

 

procedure TForm1.ButExitClick(Sender: TObject);

begin

Close;

end;

 

procedure TForm1.ButClearFClick(Sender: TObject);

begin

Form2.Series1.Clear;

Form2.Series3.Clear;

end;

 

 

procedure TForm1.ButStartClick(Sender: TObject);

var

i,j:integer;

VectX,VectF,VectS:TVector;

spline,x,dx,y:real;

tmp:integer;

step:real;

begin

try

Form2.Series2.Clear;

if not Form2.Showing then

Form2.Show;

begin

tmp:=StrToInt(EditQt.Text);

step:=2/tmp;

SetLength(VectX,tmp+1);

SetLength(VectF,tmp+1);

SetLength(VectS,tmp+1);

VectX[0]:=-1;

VectX[tmp]:=1;

VectF[0]:=f(-1);

VectF[tmp]:=f(1);

for i:=1 to tmp-1 do

begin

VectX[i]:=VectX[i-1]+step;

VectF[i]:=f(VectX[i])

end;

VectS[0]:=StrToFloat(EditStart.Text);

VectS[1]:=StrToFloat(EditSecond.Text);

for i:=1 to tmp-1 do

VectS[i+1]:=(VectF[i-1]-2*VectF[i]+VectF[i+1])*6/

(step*step)-VectS[i-1]-4*VectS[i];

 

//Нахождение отрезка разбеения соответствующего точке x*

if EditX.Text<>'' then

begin

x_tm:=StrToFloat(EditX.Text);

SetLength(VectX_tm,2);

SetLength(VectS_tm,2);

SetLength(VectF_tm,2);

for i:=0 to tmp-1 do

begin

if (x_tm>=VectX[i]) and (x_tm<=VectX[i+1]) then

begin

VectX_tm[0]:=VectX[i];

VectX_tm[1]:=VectX[i+1];

VectS_tm[0]:=VectS[i];

VectS_tm[1]:=VectS[i+1];

VectF_tm[0]:=VectF[i];

VectF_tm[1]:=VectF[i+1];

end

end;

end;

x:=-1;

dx:=step/10;

for i:=1 to tmp do

begin

for j:=1 to 10 do

begin

spline:=(VectF[i-1]*(VectX[i]-x)+VectF[i]*(x-VectX[i-1])+

(VectS[i-1]*(VectX[i]-x)*(VectX[i]-x)*(VectX[i]-x)+

VectS[i]*(x-VectX[i-1])*(x-VectX[i-1])*(x-VectX[i-1]))/6)/step-

(VectS[i-1]*(VectX[i]-x)+VectS[i]*(x-VectX[i-1]))*step/6;

Form2.Series2.AddXY(x,spline,'',clGreen);

x:=x+dx

end

end;

y:=f(x);

Form2.Series2.AddXY(x,y,'')

end;

except

end;

end;

 

procedure TForm1.ButClearSpIntClick(Sender: TObject);

begin

Form2.Series2.Clear;

Form2.Series4.Clear;

Form1.EditStart.Text:='';

Form1.EditSecond.Text:=''

end;

 

 

procedure TForm1.Button1Click(Sender: TObject);

begin

try

Form2.Series3.Clear;

x_tm:=StrToFloat(EditX.Text);

if (x_tm>=1) or (x_tm<=-1) then

LabX.Caption:='Вне промежутка'

else

begin

LabX.Caption:=FloatToStrF(f(x_tm),ffGeneral,5,4);

Form2.Series3.AddXY(x_tm,f(x_tm),'');

end;

except

end

end;

 

procedure TForm1.Button2Click(Sender: TObject);

var

spline:real;

tmp:integer;

step:real;

begin

try

with Form1,Form2 do

begin

series4.Clear;

tmp:=StrToInt(EditQt.Text);

x_tm:=StrToFloat(EditX.Text);

if (x_tm>=1) or (x_tm<=-1) then

LabS1x.Caption:='Вне промежутка'

else

begin

step:=2/tmp;

spline:=(VectF_tm[0]*(VectX_tm[1]-x_tm)+VectF_tm[1]*(x_tm-VectX_tm[0])+

(VectS_tm[0]*(VectX_tm[1]-x_tm)*(VectX_tm[1]-x_tm)*(VectX_tm[1]-x_tm)+

VectS_tm[1]*(x_tm-VectX_tm[0])*(x_tm-VectX_tm[0])*(x_tm-VectX_tm[0]))/6)/step-

(VectS_tm[0]*(VectX_tm[1]-x_tm)+VectS_tm[1]*(x_tm-VectX_tm[0]))*step/6;

LabS1x.Caption:=FloatToStrF(spline,ffGeneral,5,4);

Series4.AddXY(x_tm,spline,'')

end

end;

except

end

end;

procedure TForm1.ButEstClick(Sender: TObject);

var

i,j:integer;

VectX,VectF,VectS,VectC,VectD,VectE,VectK, VectL,VectM:TVector;

spline,x,dx,y:real;

tmp:integer;

step:real;

begin

try

Form2.Series5.Clear;

if not Form2.Showing then

Form2.Show;

begin

tmp:=StrToInt(EditQt.Text);

step:=2/tmp;

SetLength(VectX,tmp+1);

SetLength(VectF,tmp+1);

SetLength(VectS,tmp+1);

VectX[0]:=-1;

VectX[tmp]:=1;

VectF[0]:=f(-1);

VectF[tmp]:=f(1);

for i:=1 to tmp-1 do

begin

VectX[i]:=VectX[i-1]+step;

VectF[i]:=f(VectX[i])

end;

SetLength(VectC,tmp+1);

SetLength(VectD,tmp+1);

SetLength(VectE,tmp+1);

SetLength(VectK,tmp+1);

VectC[0]:=0;

VectD[0]:=1;

VectE[0]:=0;

VectK[0]:=0;

for i:=1 to tmp-1 do

begin

VectC[i]:=1;

VectD[i]:=4;

VectE[i]:=1;

VectK[i]:=(VectF[i-1]-2*VectF[i]+VectF[i+1])*6/(step*step)

end;

VectC[tmp]:=0;

VectD[tmp]:=1;

VectK[tmp]:=0;

SetLength(VectL,tmp+1);

SetLength(VectM,tmp+1);

VectL[1]:=-VectE[0]/VectD[0];

VectM[1]:=VectK[0]/VectD[0];

for i:=1 to tmp-1 do

begin

VectL[i+1]:=-VectE[i]/(VectD[i]+VectC[i]*VectL[i]);

VectM[i+1]:=(VectK[i]-VectC[i]*VectM[i])/(VectD[i]+VectC[i]*VectL[i])

end;

VectS[tmp]:=(VectK[tmp]-VectC[tmp]*VectM[tmp])/(VectD[tmp]+

VectC[tmp]*VectL[tmp]);

for i:=tmp-1 downto 0 do

VectS[i]:=VectL[i+1]*VectS[i+1]+VectM[i+1];

 

//Нахождение отрезка разбеения соответствующего точке x*

if EditX.Text<>'' then

begin

x_tm:=StrToFloat(EditX.Text);

SetLength(VectX_tm,2);

SetLength(VectS_tm,2);

SetLength(VectF_tm,2);

for i:=0 to tmp-1 do

begin

if (x_tm>=VectX[i]) and (x_tm<=VectX[i+1]) then

begin

VectX_tm[0]:=VectX[i];

VectX_tm[1]:=VectX[i+1];

VectS_tm[0]:=VectS[i];

VectS_tm[1]:=VectS[i+1];

VectF_tm[0]:=VectF[i];

VectF_tm[1]:=VectF[i+1];

end

end;

end;

x:=-1;

dx:=step/10;

for i:=1 to tmp do

begin

for j:=1 to 10 do

begin

spline:=(VectF[i-1]*(VectX[i]-x)+VectF[i]*(x-VectX[i-1])+

(VectS[i-1]*(VectX[i]-x)*(VectX[i]-x)*(VectX[i]-x)+

VectS[i]*(x-VectX[i-1])*(x-VectX[i-1])*(x-VectX[i-1]))/6)/step-

(VectS[i-1]*(VectX[i]-x)+VectS[i]*(x-VectX[i-1]))*step/6;

Form2.Series5.AddXY(x,spline,'');

x:=x+dx

end

end;

y:=f(x);

Form2.Series5.AddXY(x,y,'')

end;

except

end

end;

 

procedure TForm1.Button3Click(Sender: TObject);

var

spline:real;

tmp:integer;

step:real;

begin

try

with Form1,Form2 do

begin

series6.Clear;

tmp:=StrToInt(EditQt.Text);

x_tm:=StrToFloat(EditX.Text);

if (x_tm>=1) or (x_tm<=-1) then

LabS2x.Caption:='Вне промежутка'

else

begin

step:=2/tmp;

spline:=(VectF_tm[0]*(VectX_tm[1]-x_tm)+VectF_tm[1]*(x_tm-VectX_tm[0])+

(VectS_tm[0]*(VectX_tm[1]-x_tm)*(VectX_tm[1]-x_tm)*(VectX_tm[1]-x_tm)+

VectS_tm[1]*(x_tm-VectX_tm[0])*(x_tm-VectX_tm[0])*(x_tm-VectX_tm[0]))/6)/step-

(VectS_tm[0]*(VectX_tm[1]-x_tm)+VectS_tm[1]*(x_tm-VectX_tm[0]))*step/6;

LabS2x.Caption:=FloatToStrF(spline,ffGeneral,5,4);

Series6.AddXY(x_tm,spline,'')

end

end;

except

end

end;

procedure TForm1.Button5Click(Sender: TObject);

begin

Form2.Series5.Clear;

Form2.Series6.Clear;

Form1.EditStart.Text:='';

Form1.EditSecond.Text:=''

end;

 

end.

 

 

unit Unit2;

 

interface

 

uses

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

Dialogs, ExtCtrls, TeeProcs, TeEngine, Chart, Series, StdCtrls, BubbleCh;

 

type

TForm2 = class(TForm)

ButExit: TButton;

Chart1: TChart;

Series1: TLineSeries;

Series2: TLineSeries;

Series3: TLineSeries;

Series4: TLineSeries;

Series5: TLineSeries;

Series6: TLineSeries;

procedure ButExitClick(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

 

var

Form2: TForm2;

 

implementation

 

{$R *.dfm}

 

procedure TForm2.ButExitClick(Sender: TObject);

begin

Close;

end;

 

end.


Поделиться:

Дата добавления: 2015-09-14; просмотров: 58; Мы поможем в написании вашей работы!; Нарушение авторских прав





lektsii.com - Лекции.Ком - 2014-2024 год. (0.006 сек.) Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав
Главная страница Случайная страница Контакты