Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
метода_чис_мет_2.doc
Скачиваний:
2
Добавлен:
08.08.2019
Размер:
624 Кб
Скачать
☆

Хід роботи.

  1. Завантажити середовище Турбо Паскаль.

  2. Набрати текст програми DemSpl.

program DemSpl;

uses Crt,Graph,Serv,Groms;

const

c1:real=2;

w1:real=1.5;

c2:real=0.5;

w2:real=5;

x1:real=-2;

x2:real=3;

m:integer=10;

Ngl:integer=1;

Ngr:integer=2;

D0:real=0;

Dm:real=0;

var

Mx,My,A0,A1,A2,A3:Coefr;

Mo:coefl;

Dx1:real;

i:integer;

function SplintN(A0,A1,A2,A3:coefr;x:real):real;

var

m,s:integer;

begin

s:=1;

while Mx[s-1]<x do inc(s);

if s>1 then dec(s);

x:=x-Mx[s-1];

SplintN:=((A3[s]*x+A2[s])*x+a1[s])*x+a0[s];

end;

procedure SplineN (X,Y:coefr;Ngl,Ngr:integer; D0,Dm:real);

var

m,s:integer;

h,h1,e,v,z,r:real;

a,b:coefr;

begin

m:=round(x[-1]);

case Ngl of

1: begin

h:=x[1]-x[0]; A[0]:=-0.5;

B[0]:=1.5*((y[1]-y[0])/h-d0)/h;

end;

2: begin

A[0]:=0; b[0]:=d0/2;

end;

end;

for s:=1 to m-1 do

begin

h:=x[s]-x[s-1]; h1:=x[s+1]-x[s];

e:=2*(h+h1);

r:=3*((y[s+1]-y[s])/h1-(y[s]-y[s-1])/h);

z:=e+a[s-1]*h; a[s]:=-h1/z;

b[s]:=(r-b[s-1]*h)/z;

end;

case Ngr of

1: begin

h:=x[m]-x[m-1];

a2[m+1]:=(3*(dm-(y[m]-y[m-1])/h)-b[m-1]*h)/((a[m-1]+2)*h);

end;

2: a2[m+1]:=dm/2;

end;

for s:= m-1 downto 0 do

a2[s+1]:=a[s]*a2[s+2]+b[s];

for s:=1 to m do

begin

h:=x[s]-x[s-1];

a1[s]:=(y[s]-y[s-1])/h-2/3*a2[s]*h-1/3*a2[s+1]*h;

a3[s]:=(a2[s+1]-a2[s])/(3*h);

a0[s]:=y[s-1];

end;

a0[-1]:=m;

end;

procedure InpD;

begin

repeat

putA;

Ou('0-exit,1-C1,2-w1,3-C2,4-w2,5-x1,6-x2,7-m,8-SystCoor,9-points');

str(c1:1:3,T10); Ts:='C1='+T10;

str(w1:1:3,T10); Ts:=Ts+', w1='+T10;

str(c2:1:3,T10); Ts:=Ts+', C2='+T10;

str(w2:1:3,T10); Ts:=Ts+', w2='+T10;

str(x1:1:3,T10); Ts:=Ts+', x1='+T10;

str(x2:1:3,T10); Ts:=Ts+', x2='+T10;

str(m:1,T10); Ts:=Ts+', m='+T10;

Info; j1:=readKey;

case j1 of

'1': Our('C1',C1);

'2': Our('w1',w1);

'3': Our('C2',C2);

'4': Our('w2',w2);

'5': Our('x1',x1);

'6': Our('x2',x2);

'7': Oui('m',m);

'8': begin

xMax:=x2; xMin:=x1;

yMax:=0; yMin:=0;

Mx[-1]:=m; My[-1]:=m;

Dx:=(x2-x1)/m;

for s:=0 to m do

begin

x:=x1+s*Dx; Mx[s]:=x;

y:=C1*cos(w1*x)+C2*sin(w2*x);

My[s]:=y;

if y<yMin then yMin:=y;

if y>yMax then yMax:=y;

end;

X0Y0(false); cleardevice;

SystCoor;

end;

'9': for s:=0 to m do

circle(X0+round(Mx[s]/Dx),Y0-round(My[s]/Dy),3);

end;

until j1='0';

end;

begin

L:=300;H:=240;

c:=15;

repeat

PutA;

Ou('Esc-exit,1-InpD,2-c,3-Grf,4-Ngl,5-Ngr,6-D0,7-Dm,8-GrSpl,9-Serv');

str(c,T10); Ts:='c='+T10;

str(Ngl,T10); Ts:=Ts+', Ngl='+T10;

str(Ngr,T10); Ts:=Ts+', Ngr='+T10;

str(D0:1:3,T10); Ts:=Ts+', D0='+T10;

str(Dm:1:3,T10); Ts:=Ts+', Dm='+T10;

Info; j:=ReadKey;

case j of

'1': InpD;

'2': Oui('c',c);

'3': begin

SetColor(c); Mo[-1]:=L;

for s:=0 to L do

begin

x:=x1+s*Dx;

Mo[s]:=c1*cos(w1*x)+c2*sin(w2*x);

end; {X0Y0(false); SystCoor;}

Graphic(Mo,c);

end;

'4': Oui('Ngl',Ngl);

'5': Oui('Ngr',Ngr);

'6': Our('D0',D0);

'7': Our('Dm',Dm);

'8': begin

Dx1:=(x2-x1)/m; Mx[-1]:=m;

for s:=0 to m do

begin

Mx[s]:=x1+s*Dx1;

My[s]:=c1*cos(w1*Mx[s])+c2*sin(w2*Mx[s]);

end;

SplineN(Mx,My,Ngl,Ngr,D0,Dm);

Mo[-1]:=L; Dx:=(x2-x1)/L;

for i:=0 to L do

begin

x:=x1+i*Dx;

Mo[i]:=splintn(A0,A1,A2,A3,x);

end;

Graphic(mo,c);

end;

'9':Service

end;

until j=#27;

end.

3. Результати роботи

а) точковий графік, що підлягає апроксимації за заданими значеннями

xn = _______ ; xk = _______ ; m = _______ ;

B1= _______ ; B2= _______ ; w1= _______ ; w2 = _______ .

б) При різних комбінаціях значень граничних умов Ngl, Ngr та D0, Dm, сформулювати графіки інтерполяційного пучкового сплайна та апроксимацію за допомогою В-сплайна.

Звіт повинен містити назву роботи, мету, короткі теоретичні відомості, заповнений п.3