Смекни!
smekni.com

Разностные схемы для уравнения переноса на неравномерных сетках (стр. 11 из 12)

read(G);

writeln('----------------------------------------');

readln;

readln;

h[0]:=0;

h[1]:=a2;

for i:=2 to n do

h[i]:=h[i-1]*q;

for i:=0 to n do

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

tau[j]:=t[j]-t[j-1];

t[j]:=0;k:=0;

clrscr;

writeln('------------------------------------------------------');

write(' ',k,'sloy');

writeln(' ');

writeln('-------------------------------------------------------');

writeln('N priblijennoe tochnoe pogreshnost ');

writeln('--------------------------------------------------------');

for i:=0 to n do

begin

x[i]:=i*h[i]; t[j]:=j*tau[j];

u[i]:= A1*exp(x[i]);

d[i]:=abs(ut(x[i],t[j])-u[i]);

write('',i,'',u[i]:6:8,' ');

writeln(ut(x[i],t[j]):6:8,'',d[i]:6:8,'');

end;

writeln('-------------------------------------------------------');

readln;

k:=1;

while t[j]<=tt do begin

clrscr;

t[j]:=t[j]+tau[j];

c[0]:=ro+(p1*tau[j])/h[i];

b[0]:=G*tau[j]*p1/h[i];

a[n]:=0;

c[n]:=1;

for i:=1 to n-1 do begin

a[i]:=-G*p1*tau[j]/(2*h[i]);

c[i]:=ro;

b[i]:=-a[i];

f1[i]:=(1-G)*p1*tau[j]/(2*h[i]);

f2[i]:=ro*u[i];

f3[i]:=G*tau[j]*fi(x[i],t[j]);

f4[i]:=(1-G)*tau[j]*fi(x[i],t[j]-tau[j]);

f[i]:=f1[i]*(u[i+1]-u[i-1])+f2[i]+f3[i]+f4[i];

end;

f5[i]:=(1-G)*p1*(u[1]-u[0])*tau[j]/h[i];

f6[i]:=ro*u[0]+f5[i]+G*tau[j]*fi(x[0],t[j]+tau[j]);

f[0]:=f6[j]+(1-G)*tau[j]*fi(x[0],t[j]);

f[n]:= A1*exp(l+t[j]);

alfa[0]:=b[0]/c[0];

betta[0]:=f[0]/c[0];

for i:=1 to n-1 do begin

z[i]:=c[i]-alfa[i-1]*a[i];

alfa[i]:=b[i]/z[i];

betta[i]:=(f[i]+a[i]*betta[i-1])/z[i]; end;

u1[n]:=(f[n]+a[n]*betta[n-1])/(c[n]-alfa[n-1]*a[n]);

for i:=n-1 downto 0 do

u1[i]:=alfa[i]*u1[i+1]+betta[i];

writeln('----------------------------------------------------------');

write(' ',k,'sloy');

writeln(' ');

writeln('--------------------------------------------------------');

writeln('N priblijennoe tochnoe pogreshnosti ');

writeln('--------------------------------------------------------');

for i:=0 to n do begin

d[i]:=abs(ut(x[i],t[j])-u1[i]);

write('',I,' ',u1[i]:6:8,' ');

writeln(ut(x[i],t[j]):6:8,' ',d[i]:6:8,' '); end;

k:=k+1;

writeln('--------------------------------------------------------------');

readln;

for i:=0 to n do

u[i]:=u1[i];

end;

end.

Уравнение с переменными коэффициентами

Трехточечная схема с весом

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

p0<0, pN<0

uses crt;

const n=15;j0=50;tt=1;l=1;A1=1;q=3;a2=1;

type m=array[0..n] of real;

hi=array[0..n] of real;

var i,j,k,G:integer;

h,d,tau,t,f1,f2,f3,f4,f5,f6:hi;

u,u1,r,x,z,a,b,c,f,alfa,betta:m;

function ut(p,r:real):real;

begin ut:= A1*exp(p+r);end;

function fi(p,r:real):real;

begin fi:=A*exp(p+r)*(p*(p+1)+r*(r+1)+7); end;

function ro(p,r:real):real;

begin ro:=sqr(p)+sqr(r)+5;end;

function p1(p,r:real):real;

begin p1:=-(p+r+2);end;

begin

clrscr;

writeln (' chislennoe reshenie uravneniya perenosa');

writeln ( 'trextochechnaya sxema');

writeln(' kogda p<0');

writeln(' vvedite G=' );

read(G);

writeln('----------------------------------------------------');

readln;

readln;

h[0]:=0;

h[1]:=a2;

for i:=2 to n do

h[i]:=h[i-1]*q;

for i:=0 to n do

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

tau[j]:=t[j]-t[j-1];

t[j]:=0;k:=0;

clrscr;

writeln('------------------------------------------------------');

write(' ',k,'sloy');

writeln(' ');

writeln('-------------------------------------------------------');

writeln('N priblijennoe tochnoe pogreshnost ');

writeln('--------------------------------------------------------');

for i:=0 to n do

begin

x[i]:=i*h[i]; t[j]:=j*tau[j];

u[i]:= A1*exp(x[i]);

d[i]:=abs(ut(x[i],t[j])-u[i]);

write('',i,'',u[i]:6:8,' ');

writeln(ut(x[i],t[j]):6:8,'',d[i]:6:8,'');

end;

writeln('-------------------------------------------------------');

readln;

k:=1;

while t[j]<=tt do begin

clrscr;

t[j]:=t[j]+tau[j];

c[0]:=1;

b[0]:=0;

a[n]:=-g*(tau[j]*p1)/h[i];

c[n]:=ro-g*(p1*tau[j])/h[i];

for i:=1 to n-1 do begin

r[i]:=tau[j]*p1/(2*h[i]);

a[i]:=(-g*p1*tau[j])/(2*h[i]);

c[i]:=ro;

b[i]:=-a[i];

f1[i]:=(1-g)*(p1*tau[j])/(2*h[i]);

f2[i]:=ro*u[i];

f3[i]:=g*tau[j]*fi(x[i],t[j]);

f4[i]:=(1-g)*tau[j]*fi(x[i],t[j]-tau[j]);

f[i]:=f1[i]*(u[i+1]-u[i-1])+f2[i]+f3[i]+f4[i];end;

f[0]:=A1*exp(t[j]);

f5[i]:=(1-g)*p1*(u[1]-u[0])*tau[j]/h[i];

f6[i]:=ro*u[0]+f5[i]+g*tau[j]*fi(x[0],t[j]+tau[j]);

f[n]:=f6[j]+(1-g)*tau[j]*fi(x[0],t[j]);

alfa[0]:=b[0]/c[0];

betta[0]:=f[0]/c[0];

for i:=1 to n-1 do begin

z[i]:=c[i]-alfa[i-1]*a[i];

alfa[i]:=b[i]/z[i];

betta[i]:=(f[i]+a[i]*betta[i-1])/z[i]; end;

u1[n]:=(f[n]+a[n]*betta[n-1])/(c[n]-alfa[n-1]*a[n]);

for i:=n-1 downto 0 do

u1[i]:=alfa[i]*u1[i+1]+betta[i];

writeln('----------------------------------------------------------');

write(' ',k,'sloy');

writeln(' ');

writeln('--------------------------------------------------------');

writeln('N priblijennoe tochnoe pogreshnosti ');

writeln('--------------------------------------------------------');

for i:=0 to n do begin

d[i]:=abs(ut(x[i],t[j])-u1[i]);

write('',I,' ',u1[i]:6:8,' ');

writeln(ut(x[i],t[j]):6:8,' ',d[i]:6:8,' '); end;

k:=k+1;

writeln('--------------------------------------------------------------');

readln;

for i:=0 to n do

u[i]:=u1[i];

end;

end.


Приложение 4

Уравнение с постоянными коэффициентами

“Явная” схема.

Левая разностная схема

p<0

uses crt;

const n=15;j0=50;tt=1;l=1;A=1;B=1;p1=1;q=3;

type m=array[0..n] of real;

hi=array[0..n] of real;

var i,j:integer;

h,d,tau,t:hi;

u11,u12:real;

u,u1,x,g,u2:m;

function ut(p,r:real):real;

begin ut:= A*exp(B*(p+r));end;

function fi(p,r:real):real;

begin fi:=A*B*exp(B*(p+r))*(1-p1+q/B); end;

begin

clrscr;

writeln ( 'sxema begushego scheta');

writeln(' kogda p0>0,pN>0');

writeln(' pravaya raznostnaya sxema');

readln;

h[0]:=0;

h[1]:=a1;

for i:=2 to n do

h[i]:=h[i-1]*q;

for i:=0 to n do

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

tau[j]:=t[j]-t[j-1];

t[j]:=0;j:=1;

for i:=0 to n do

begin

x[i]:=i*h;t[j]:=j*tau[j];

u[i]:= A*(exp(B*(x[i])));

end;

while t[j]<=tt do begin clrscr;

t[j]:=t[j]+tau[j];

u1[n]:=A*exp(B*(l+t[j]));

for i:=n-1 downto 0 do begin

g[i]:=(tau[j+1]*p1)/h[i];

u11:=(g[i]*u1[i+1])+u[i];

u12:=tau*fi(x[i],t[j]);

u1[i]:=(u11+u12)/(1+g[i]+tau[j+1]*q);

end;

for i:=0 to n do u[i]:=u1[i];

writeln('----------------------------------------------------------');

write(' ',j,'sloy');

writeln(' ');

writeln('--------------------------------------------------------');

writeln('N priblijennoe tochnoe pogreshnosti ');

writeln('--------------------------------------------------------');

for i:=0 to n do begin

d[i]:=abs(ut(x[i],t[j])-u1[i]);

write('',I,' ',u1[i]:6:8,' ');

writeln(ut(x[i],t):6:8,' ',d[i]:6:8,' '); end;

j:=j+1;

writeln('--------------------------------------------------------------');

readln;

end;

end.

Уравнение с постоянными коэффициентами

“Явная” схема.

Схема бегущего счета.

Правая разностная схема

p>0

uses crt;

const n=15;j0=50;tt=1;l=1;A=1;B=-1;p1=-3;q=3;

type m=array[0..n] of real;

hi=array[0..n] of real;

var i,j:integer;

x,h,d,tau,t:hi;

u11,u12:real;

u,u1,g:m;

function ut(p,r:real):real;

begin ut:= A*exp(B*(p+r));end;

function fi(p,r:real):real;

begin fi:=A*B*exp(B*(p+r))*(1-p1+q/B); end;

begin

clrscr;

writeln ( 'sxema begushego scheta');

writeln(' kogda p0<0,pN<0');

writeln(' levaya raznostnaya sxema');

readln;

h[0]:=0;

h[1]:=a1;

for i:=2 to n do

h[i]:=h[i-1]*q;

for i:=0 to n do

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

tau[j]:=t[j]-t[j-1];

t[j]:=0;j:=1;

for i:=0 to n do

begin

x[i]:=i*h[i]; t[j]:=j*tau[j];

u[i]:= A*(exp(B*(x[i])));

end;

while t[j]<=tt do begin clrscr;

t[j]:=t[j]+tau[j];

u1[0]:=A*exp(B*(t[j]));

for i:=1 to n do begin

g[i]:=(tau[j]*p1)/h[i];

u11:=(-g[i]*u1[i-1])+u[i];

u12:=tau[j]*fi(x[i],t[j]);

u1[i]:=(u11+u12)/(1-g[i]+tau[j]*q);

end;

for i:=0 to n do u[i]:=u1[i];

writeln('----------------------------------------------------------');

write(' ',j,'sloy');

writeln(' ');

writeln('--------------------------------------------------------');

writeln('N priblijennoe tochnoe pogreshnosti ');

writeln('--------------------------------------------------------');

for i:=0 to n do begin

d[j]:=abs(ut(x[i],t[j])-u1[i]);

write('',I,' ',u1[i]:6:8,' ');

writeln(ut(x[i],t[j]):6:8,' ',d[j]:6:8,' '); end;

j:=j+1;

writeln('--------------------------------------------------------------');

readln;

end;

end.

Приложение 5.

Уравнение с постоянными коэффициентами

Схема с центральной разностью

p>0

uses crt;

const n=15;j0=50;tt=1;l=1;A1=1;B1=1;p1=1;q=3;g1=1;

type m=array[0..n] of real;

hi=array[0..n] of real;

var i,j,k:integer;

h,d,tau,t:hi;

u,u1,r,x,z,a,b,c,f,alfa,betta:m;

function ut(p,r:real):real;

begin ut:= A1*exp(B1*(p+r));end;

function fi(p,r:real):real;

begin fi:=A1*B1*exp(B1*(p+r))*(1-p+q/B);end;

begin

clrscr;

writeln (' chislennoe reshenie uravneniya perenosa');

writeln ( 'sxema s sentralnoy raznostju');

writeln(' kogda p0>0,pn>0');

readln;

h[0]:=0;

h[1]:=a1;

for i:=2 to n do

h[i]:=h[i-1]*q;

for i:=0 to n do

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

tau[j]:=t[j]-t[j-1];

t[j]:=0;k:=0;

clrscr;

writeln('------------------------------------------------------');

write(' ',k,'sloy');

writeln(' ');

writeln('-------------------------------------------------------');

writeln('N priblijennoe tochnoe pogreshnost ');

writeln('--------------------------------------------------------');

for i:=0 to n do

begin

x[i]:=i*h[i]; t[j]:=j*tau[j];

u[i]:= A1*exp(B1*(x[i]));

d[i]:=abs(ut(x[i],t[j])-u[i]);

write('',i,'',u[i]:6:8,' ');

writeln(ut(x[i],t[j]):6:8,'',d[i]:6:8,'');

end;

writeln('-------------------------------------------------------');

readln;

k:=1;

while t[j]<=tt do begin

clrscr;

t[j]:=t[j]+tau[j];

c[0]:=1+(p1*tau[j+1])/h[1]+tau[j+1]*q;

b[0]:=(tau[j+1]*p1)/h[1];

a[n]:=0;

c[n]:=1;

for i:=1 to n-1 do begin

r[i]:=tau[j]*p1/(2*h[i]);

a[i]:=-r[i];

c[i]:=ro;

b[i]:=-a[i];

f[i]:=ro*u[i]+tau[j]*fi(x[i],t[j]);end;

f[0]:=tau[j]*fi(x[0],t[j])+u[0];

f[n]:= A1*exp(B1*(l+t[j]));

alfa[0]:=b[0]/c[0];

betta[0]:=f[0]/c[0];

for i:=1 to n-1 do begin

z[i]:=c[i]-alfa[i-1]*a[i];

alfa[i]:=b[i]/z[i];

betta[i]:=(f[i]+a[i]*betta[i-1])/z[i]; end;

u1[n]:=(f[n]+a[n]*betta[n-1])/(c[n]-alfa[n-1]*a[n]);

for i:=n-1 downto 0 do

u1[i]:=alfa[i]*u1[i+1]+betta[i];

writeln('----------------------------------------------------------');

write(' ',k,'sloy');

writeln(' ');

writeln('--------------------------------------------------------');

writeln('N priblijennoe tochnoe pogreshnosti ');

writeln('--------------------------------------------------------');

for i:=0 to n do begin

d[i]:=abs(ut(x[i],t[j])-u1[i]);

write('',I,' ',u1[i]:6:8,' ');

writeln(ut(x[i],t[j]):6:8,' ',d[i]:6:8,' '); end;

k:=k+1;

writeln('--------------------------------------------------------------');

readln;

for i:=0 to n do

u[i]:=u1[i];

end;

end.


Уравнение с постоянными коэффициентами

Схема с центральной разностью

P<0

uses crt;

const n=15;j0=50;tt=1;l=1;A1=1;B1=-1;p1=-1; q=3;g1=1;

type m=array[0..n] of real;

hi=array[0..n] of real;

var i,j,k:integer;

h,d,tau,t:hi;

u,u1,r,x,z,a,b,c,f,alfa,betta:m;

function ut(p,r:real):real;

begin ut:= A1*exp(B1*(p+r));end;

function fi(p,r:real):real;

begin fi:=A1*B1*exp(B1*(p+r))*(1-p1+q/B);end;

begin

clrscr;

writeln (' chislennoe reshenie uravneniya perenosa');

writeln ( 'sxema s sentralnoy raznostju');

writeln(' kogda p0<0,pn<0');

readln;

h[0]:=0;

h[1]:=g1;

for i:=2 to n do

h[i]:=h[i-1]*q;

for i:=0 to n do

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

tau[j]:=t[j]-t[j-1];

t[j]:=0;k:=0;

clrscr;

writeln('------------------------------------------------------');

write(' ',k,'sloy');

writeln(' ');

writeln('-------------------------------------------------------');

writeln('N priblijennoe tochnoe pogreshnost ');

writeln('--------------------------------------------------------');

for i:=0 to n do

begin

x[i]:=i*h[i]; t[j]:=j*tau[j];

u[i]:= A1*exp(B1*(x[i]));

d[i]:=abs(ut(x[i],t[j])-u[i]);

write('',i,'',u[i]:6:8,' ');

writeln(ut(x[i],t[j]):6:8,'',d[i]:6:8,'');

end;

writeln('-------------------------------------------------------');

readln;

k:=1;

while t[j]<=tt do begin

clrscr;

t[j]:=t[j]+tau[j];

c[0]:=1;

b[0]:=0;

a[n]:=-(tau[j]*p1)/h[i];

c[n]:=1-(p1*tau[j])/h[i]+tau[j]*q;

for i:=1 to n-1 do begin

r[i]:=tau[j]*p1/(2*h[i]);

a[i]:=-r[i];

c[i]:=ro;

b[i]:=-a[i];

f[i]:=ro*u[i]+tau[j]*fi(x[i],t[j]);end;

f[0]:=A1*exp(t[j]);

f[n]:= (tau[j]*fi(x[n],t[j])+u[n]);

alfa[0]:=b[0]/c[0];

betta[0]:=f[0]/c[0];

for i:=1 to n-1 do begin

z[i]:=c[i]-alfa[i-1]*a[i];

alfa[i]:=b[i]/z[i];

betta[i]:=(f[i]+a[i]*betta[i-1])/z[i]; end;

u1[n]:=(f[n]+a[n]*betta[n-1])/(c[n]-alfa[n-1]*a[n]);

for i:=n-1 downto 0 do

u1[i]:=alfa[i]*u1[i+1]+betta[i];

writeln('----------------------------------------------------------');

write(' ',k,'sloy');

writeln(' ');

writeln('--------------------------------------------------------');

writeln('N priblijennoe tochnoe pogreshnosti ');

writeln('--------------------------------------------------------');

for i:=0 to n do begin

d[i]:=abs(ut(x[i],t[j])-u1[i]);

write('',I,' ',u1[i]:6:8,' ');

writeln(ut(x[i],t[j]):6:8,' ',d[i]:6:8,' '); end;

k:=k+1;

writeln('--------------------------------------------------------------');

readln;

for i:=0 to n do

u[i]:=u1[i];

end;

end.


Приложение 6

Уравнение с постоянными коэффициентами

Трехточечная схема с весом

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

p>0

uses crt;

const n=15;j0=50;tt=1;l=1;A1=1;B1=1;p1=1;q=3;