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

Приложение.

Определение параметра сходимости.

definition(50,50,50,0.001)

Optimal value of the 'mu' is 1.883000

Решение основной задачи на сетке :

У=1

У=0

У=0.1

У=0.7

У=0.6

У=0.5

У=0.4

У=0.3

У=0.2

У=0.9

У=0.8

0 0 0 0 0 0 0 0 0 0 0

0 -0.0013 0.0029 0.0104 0.0207 0.0335 0.0491 0.0680 0.0910 0.1195 0.1564

0 0.0025 0.0125 0.0282 0.0488 0.0743 0.1051 0.1420 0.1866 0.2412 0.3090

0 0.0091 0.0265 0.0511 0.0823 0.1200 0.1650 0.2184 0.2824 0.3598 0.4540

0 0.0173 0.0435 0.0776 0.1192 0.1685 0.2264 0.2945 0.3751 0.4715 0.5878

0 0.0268 0.0626 0.1066 0.1585 0.2186 0.2878 0.3681 0.4621 0.5736 0.7071

0 0.0374 0.0836 0.1379 0.1998 0.2696 0.3484 0.4382 0.5418 0.6637 0.8090

0 0.0492 0.1068 0.1716 0.2432 0.3217 0.4082 0.5045 0.6137 0.7404 0.8910

0 0.0626 0.1327 0.2087 0.2898 0.3761 0.4684 0.5682 0.6783 0.8034 0.9511

0 0.0788 0.1630 0.2507 0.3413 0.4346 0.5312 0.6319 0.7385 0.8544 0.9877

0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000 0.8000 0.9000 1.0000

Модельная задача.

  • Результат применения функции model(50,50,1.883,10^6):

Maximum error is error = 1.251885121567042e-006

  • Результат применения функции model(100,100,1.883,10^6):

Maximum error is error = 3.180901020360949e-007

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

function main(M,N,mu,MAX)

% main(M,N,mu,eps,MAX)

% M - the X-size of the grig

% N - the Y-size of the grig

% MAX - the maximum number of the iterations

% mu - the parameter of the convergence (1<mu<2)

warning off

close all

diary d:\main.txt

diary on

format short

a = 1;

b = 1;

h = a/M;

t = b/N;

q = t/h;

eps=((h+t)/2)^4/1.25;

% initialization

u = ones(M+1, N+1);

x = zeros(M+1,1);

y = zeros(N+1,1);

f = -1.*ones(size(u));

% the approximation of the boundary conditions

for i = 1:(M+1),

u(i,1) = 0;

u(i,N+1) = sin(pi*(i-1)*h/2);

x(i) = (i-1)*h;

end

for j = 1:(N+1),

u(1,j) = 0;

u(M+1,j) = (j-1)*t;

y(j) = (j-1)*t;

end

k = 0;

A = 100;

a1 = 1/(2*(1+q^2));

a2 = q^2;

a3 = t^2*a1;

while (A > eps)

k = k + 1;

A = 0;

for i=2:M,

for j=2:N,

X = a1 * (u(i,j-1) + u(i,j+1) + a2*u(i-1,j) + a2*u(i+1,j)) + a3*f(i,j);

X = mu*X + (1-mu)*u(i,j);

R = abs(X - u(i,j));

if (R > A) A = R; end

u(i,j) = X;

end

end

if k == MAX

sprintf('%d steps were made !!!', MAX)

break;

end

end

sprintf('Quality of approximation is %f', A)

if (k ~= MAX)

sprintf('Riched after %d steps', k)

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

result

U=zeros(M+1,6);

for i=1:M+1,

for j=0:10,

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

end

end

i=1:1:M+1;

colormap(pink)

surf(x,y,u);

grid

pause;

colormap('default')

contour(u,50);

pause;

plot(x(i),U)

grid

diary off

function model(M,N,mu,MAX)

% main(M,N,mu,eps,MAX)

% M - the X-size of the grig

% N - the Y-size of the grig

% MAX - the maximum number of the iterations

% mu - the parameter of the convergence (1<mu<2)

warning off

close all

diary d:\model.txt

diary on

format short

a = 1;

b = 1;

h = a/M;

t = b/N;

q = t/h;

eps=((h+t)/2)^4/1.25;

% initialization

u = ones(M+1, N+1);

x = zeros(M+1,1);

y = zeros(N+1,1);

% the approximation of the boundary conditions

for i = 1:(M+1),

u(i,1) = 1;

x(i) = (i-1)*h;

u(i,N+1) = exp(x(i));

end

for j = 1:(N+1),

u(1,j) = 1;

y(j) = (j-1)*t;

u(M+1,j) = exp(y(j));

end

for i=1:(M+1)

for j=1:(N+1)

f(i,j)=-(x(i)^2+y(j)^2)*exp(x(i)*y(j));

U(i,j)=exp(x(i)*y(j));

end

end

k = 0;

A = 100;

a1 = 1/(2*(1+q^2));

a2 = q^2;

a3 = t^2*a1;

while (A > eps)

k = k + 1;

A = 0;

for i=2:M,

for j=2:N,

X = a1 * (u(i,j-1) + u(i,j+1) + a2*u(i-1,j) + a2*u(i+1,j)) + a3*f(i,j);

X = mu*X + (1-mu)*u(i,j);

R = abs(X - u(i,j));

if (R > A) A = R; end

u(i,j) = X;

end

end

if k == MAX

sprintf('%d steps were made !!!', MAX)

break;

end

end

sprintf('Quality of approximation is %f', A)

if (k ~= MAX)

sprintf('Riched after %d steps', k)

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

result

uu=zeros(M+1,6);

UU=zeros(M+1,6);

for i=1:M+1,

for j=0:10,

uu(i,j+1)=u(i,1+j*N/10);

UU(i,j+1)=U(i,1+j*N/10);

end

end

i=1:1:M+1;

colormap(cool)

surf(x,y,u);

title('obtained')

figure

colormap(pink)

surf(x,y,U);

title('real')

figure

subplot(2,2,1)

plot(x(i),UU,'r')

title('real')

grid

subplot(2,2,2)

plot(x(i),uu,'b')

title('obtained')

grid

subplot(2,2,[3 4])

plot(x(i),UU,'r')

hold

plot(x(i),uu,'b')

grid

title('combined')

R=U-u;

format long

error=max(max(abs(R)));

disp('Maximum error is')

error

diary off

function y = epsilon(M,N,MAX,mu)

% y = epsilon(M,N,MAX,mu)

a = 1;

b = 1;

h = a/M;

t = b/N;

q = t/h;

u = ones(M+1, N+1);

f = -1.*ones(size(u));

x = zeros(M+1,1);

y = zeros(N+1,1);

x = 0:h:1;

y = 0:t:1;

for i = 1:(M+1),

u(i,1) = 0;

u(i,N+1) = sin(pi*(i-1)*h/2);

end

for j = 1:(N+1),

u(1,j) = 0;

u(M+1,j) = (j-1)*t;

end

k = 0;

A = 100;

a1 = 1/(2*(1+q^2));

a2 = q^2;

a3 = t^2*a1;

for k = 1:MAX,

A = 0;

for i=2:M,

for j=2:N,

X = a1*(u(i,j-1)+u(i,j+1)+a2*u(i-1,j)+a2*u(i+1,j))+a3*f(i,j);

X = mu*X + (1-mu)*u(i,j);

R = abs(X - u(i,j));

if (R > A) A = R; end

u(i,j) = X;

end

end

end

y=A;

function definition(M,N,MAX,h)

% y=definition(h,M,N,MAX)

% M - the X-size of the grig

% N - the Y-size of the grig

% MAX - the maximum number of the iterations

% h - the quality of the mu-parameter definition

diary d:\definition.txt

diary on

mu = 1:h:2;

eps = zeros(size(mu));

for i=1:length(mu)

eps(i) = epsilon(M,N,MAX,mu(i));

end

k=0;

EPS=min(eps);

for i=1:length(mu)

if eps(i)==EPS

k=i;

end

end

sprintf('Optimal value of the ''mu'' is %f', mu(k))

diary off

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