Está en la página 1de 4

clear all

close all
L=300;
nx=100;
c=2;
dx=L/(nx-1);

kh=1;

% controladores de estabilidad
Pe=0.45; % Peclet Pe < 0.5
cr=0.70; % Courant CFL < 1.0

dt1=cr*dx/abs(c); % paso de tiempo de adveccion


dt2=Pe*dx^2/kh; % paso de tiempo de difusion
dt=min(dt1,dt2); % paso de tiempo de calculo
%

tf=50;
nf=round(tf/(dt))+1

a(1:nx,1)=0;
a(nx/2:nx/2+1,1)=1;
b(1:nx,1)=a(1:nx,1);
d(1:nx,1)=a(1:nx,1);
e(1:nx,1)=a(1:nx,1);
t1=5; k1=floor(t1/dt)+1;
t2=10;k2=floor(t2/dt)+1;
t3=15;k3=floor(t3/dt)+1;
t4=20;k4=floor(t4/dt)+1;
for i=1:nx
x(i)=(i-1)*dx;
end

for k=2:nf

for i=2:nx-1
% a(i,k)=a(i,k-1)-(c*dt/dx)*(a(i,k-1)-a(i-1,k-1)); % esquema regresivo
% d(i,k)=d(i,k-1)-0.5*(c*dt/dx)*(d(i+1,k-1)-d(i-1,k-1)); % esquema centrado
adv=0.5*dt*(c+abs(c))*(e(i,k-1)-e(i-1,k-1))/dx+0.5*dt*(c-abs(c))*(e(i+1,k-1)-e(i,k-1))/dx;
dif=(kh*dt/dx^2)*(e(i-1,k-1)-2*e(i,k-1)+e(i+1,k-1));
e(i,k)=e(i,k-1)-adv+dif;
% e(i,k)=e(i,k-1)-0.5*dt*(c+abs(c))*(e(i,k-1)-e(i-1,k-1))/dx-0.5*dt*(c-abs(c))*(e(i+1,k-1)-e(i,k-
1))/dx;
end

%for i=1:nx-1
%b(i,k)=b(i,k-1)-(c*dt/dx)*(b(i+1,k-1)-b(i,k-1)); % esquema adelantado
%end

% plot(x,d(:,k))
hold on
plot(x,e(:,k),'r')
axis([0 300 -2 2])
M(k)=getframe;
pause(0.3);

end
AA=e;
figure
subplot(221)
k=k1
plot(x,AA(:,k),'LineWidth',3)
hold on
plot(x,AA(:,1),'r','LineWidth',3)
axis([0 300 -2 2])

subplot(222)
k=k2
plot(x,AA(:,k),'LineWidth',3)
hold on
plot(x,AA(:,1),'r','LineWidth',3)

axis([0 300 -2 2])

subplot(223)
k=k3
plot(x,AA(:,k),'LineWidth',3)
hold on
plot(x,AA(:,1),'r','LineWidth',3)

axis([0 300 -2 2])


subplot(224)
k=k4
plot(x,AA(:,k),'LineWidth',3)
hold on
plot(x,AA(:,1),'r','LineWidth',3)

axis([0 300 -2 2])

break
subplot(221)
k=1
plot(x,a(:,k))
hold on
plot(x,b(:,k),'r')
hold on
plot(x,d(:,k),'m')
hold on
plot(x,e(:,k),'k')

title((k-1)*dt)
axis([0 300 -15 15])
legend('Adelantado','Atrasado','centrado','upwind')

subplot(222)
k=round(nf/4)
plot(x,a(:,k))
hold on
plot(x,b(:,k),'r')
hold on
plot(x,d(:,k),'m')
hold on
plot(x,e(:,k),'k')

title((k-1)*dt)
axis([0 300 -15 15])

subplot(223)
k=round(2*nf/4)
plot(x,a(:,k))
hold on
plot(x,b(:,k),'r')
hold on
plot(x,d(:,k),'m')
hold on
plot(x,e(:,k),'k')

title((k-1)*dt)
axis([0 300 -15 15])

subplot(224)
k=round(3*nf/4)
plot(x,a(:,k))
hold on
plot(x,b(:,k),'r')
hold on
plot(x,d(:,k),'m')
hold on
plot(x,e(:,k),'k')

title((k-1)*dt)
axis([0 300 -15 15])

También podría gustarte