Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
ЧМ (МП-3) / Курсовые / mpm_13a / Курсовая 13.doc
Скачиваний:
110
Добавлен:
17.04.2013
Размер:
514.05 Кб
Скачать

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

Тексты функций.

Явная схема.

function [U,u,result,error]=evident(M,N)

% [U,u,result,error]=evident(M,N)

% U - the required surface

% u - y-lines

% result - the matrix of results

% M - the X-size of the grig

% N - the Y-size of the grig

close all

warning off

error=0;

h=1/M;

t=1/N;

if 2*t>h^2

error=1;

end

U=zeros(M+1,N+1);

for i=1:M+1

for j=1:N+1

f(i,j)=20*cos(pi*(i-1)*h*(j-1)*t);

end

end

for j=1:N

U(1,j+1)=2*t/h^2*(U(2,j)-U(1,j))-10*t/h*(j-1)*t+U(1,j)+t*20;

for i=2:M

U(i,j+1)=U(i,j)+t/h^2*(U(i-1,j)-2*U(i,j)+U(i+1,j))+t*f(i,j);

end;

U(M+1,j+1)=2*t/h^2*(U(M,j)-U(M+1,j))+U(M+1,j)+t*f(M+1,j);

end;

m=1;

n=1;

for i=1:M/10:M+1

for j=1:N/10:N+1

result(m,n)=U(i,j);

n=n+1;

end

n=1;

m=m+1;

end

u=zeros(M+1,6);

for i=1:M+1,

for j=0:5,

u(i,j+1)=U(i,1+j*N/5);

end

end

Неявная схема.

function [U,u,result,error]=implicit(M,N)

% [U,u,result,error]=implicit(M,N)

% U - the required surface

% u - y-lines

% Result - the matrix of results

% M - the X-size of the grig

% N - the Y-size of the grig

Close all warning off

error=0;

h=1/M;

t=1/N;

U=zeros(M+1,N+1);

for i=1:M+1

for j=1:N+1

fun(i,j)=20*cos(pi*(i-1)*h*(j-1)*t);

end

end

A=zeros(M,1);

C=zeros(M+1,1);

B=A;

A1=A;

F=zeros(M+1,N+1);

B1=F;

for i=1:M-1,

A(i)=1;

B(i+1)=1;

C(i+1)=2+h^2/t;

if abs(C(i+1))<abs(A(i))+abs(B(i+1))

error=1;

end

end;

A(M)=1;

B(1)=1;

C(1)=1+h^2/(2*t);

C(M+1)=1+h^2/(2*t);

if abs(C(1))<abs(B(1))

error=1;

end

if abs(C(M+1))<abs(A(M))

error=1;

end

A1(1)=B(1)/C(1);

for i=2:M

A1(i)=B(i)/(C(i)-A(i-1)*A1(i-1));

end;

for j=2:N+1,

F(1,j)=h^2/(2*t)*U(1,j-1)+h^2/2*fun(1,j)-5*h*(j-1)*t;

B1(1,j)=F(1,j)/C(1);

for i=1:M-1,

F(i+1,j)=h^2*fun(i+1,j-1)+h^2/t*U(i+1,j-1);

end;

F(M+1,j)=h^2/2*fun(M+1,j)+h^2/(2*t)*U(M+1,j-1);

for i=2:M+1,

B1(i,j)=(F(i,j)+A(i-1)*B1(i-1,j))/(C(i)-A(i-1)*A1(i-1));

end;

U(M+1,j)=B1(M+1,j);

for i=M:-1:1,

U(i,j)=A1(i)*U(i+1,j)+B1(i,j);

end;

end;

m=1;

n=1;

for i=1:M/10:M+1

for j=1:N/10:N+1

result(m,n)=U(i,j);

n=n+1;

end

n=1;

m=m+1;

end

u=zeros(M+1,6);

for i=1:M+1,

for j=0:5,

u(i,j+1)=U(i,1+j*N/5);

end

end

Главная функция.

clear

clc

warning off

close all

format short

diary d:\main.txt

diary on

M=input('Input the X-size of the grig: ')

N=input('Input the Y-size of the grig: ')

[U,u,res,err]=evident(M,N);

[UU,uu,result,error]=implicit(M,N);

if err

disp('Bad fragmentation!!!')

end

if error

disp('Bad fragmentation!!!')

end

if ~err

if ~error

colormap(bone)

mesh(UU)

title('IMPLICIT')

pause

colormap(pink)

mesh(U)

title('EVIDENT')

pause

colormap('default')

contour(UU,50)

title('IMPLICIT')

pause

contour(U,50)

title('EVIDENT')

pause

i=1:M+1;

plot((i-1).*1/M,uu)

title('IMPLICIT')

grid

pause

plot((i-1).*1/M,u)

title('EVIDENT')

grid

pause

plot((i-1).*1/M,uu,'b')

hold

plot((i-1).*1/M,u,'r')

title('COMBINED')

grid

end

end

res

result

err_matr=res-result

format long error

error=max(max(abs(res-result)))

diary off

Используемая литература.

  1. Земсков В.Н. Конспект лекций по курсу “Численные методы”.

  2. Долголаптев В.Г., Земсков В.Н. Численные методы решения разностных уравнений математической физики. – М., МИЭТ, 1987г.

  3. Земсков В.Н., Хахалин С.Я. Метод Сеток. Методические указания к выполнению курсовой работы на персональном компьютере. – М., МИЭТ, 1998.

Соседние файлы в папке mpm_13a