EDP Parabólica: Problema 1

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

EDP Parabólica

Problema 1
clear all; close all; clc;
L=10; dx=1; Tmax=100; dt=0.005;
k=0.15; D=100; U=1;
nx=L/dx+1;
nt=Tmax/dt+1;
X=0:dx:L;
C(1:nx,1:nt)=0;
C(1,:)=100;
A=D*(dt/(dx^2));
B=U*(dt/(2*dx));
AA=zeros(nx-2,nx-2);
BB=zeros(nx-2,1);
for t=1:nt-1
for i=1:nx-2
AA(i,i)=2*A+1;
if i<nx-2
AA(i,i+1)=-(A-B);
AA(i+1,i)=-(A+B);
end
BB(i,1)=(1-k)*C(i+1,t);
end
BB(1,1)=BB(1,1)+(A+B)*C(1,t);
BB(nx-2,1)=BB(nx-2,1);
m=AA;
n=BB;
[x]=gauss(m,n);
C(2:nx-1,t+1)=x';
if t+1==nt
break
end
end
plot(X,C(:,t-1))
title('problema 01')
xlabel('X')
ylabel('C')
Problema 2:

clear all; close all; clc;


L=1; nx=10; Tmax=0.1; nt=11;
b=[4;2;0;-2;-4];
nb=length(b);
dx=L/(nx-1);
dt=Tmax/(nt-1);
X=0:dx:L;
U(1:nx,1:nt)=0;
U(1,:)=0;
U(nx,:)=1;
U(2:nx-1,1)=0;
for j=1:nb
k=b(j)*(dt/dx); c=dt/(dx^2);
AA = zeros(nx-2,nx-2);
BB = zeros(nx-2,1);
for t=1:nt-1
for i=1:nx-2
AA(i,i)=2*(c+1);
AA(i,i+1)=-c;
AA(i+1,i)=-c;
BB(i,1)=(c-k)*U(i,t)+2*(1-c)*U(i+1,t)+(c+k)*U(i+2,t);
end
BB(1,1)=BB(1,1)+c*U(1,t+1);
BB(nx-2,1)=BB(nx-2,1)+c*U(nx,t+1);
m=AA;
n=BB;
[x]=gauss(m,n);
U(2:nx-1,t+1)=x';
if t+1==nt
break
end

end
plot(X,U(:,t))
hold on
title('PROBLEMA 2')
xlabel('X')
ylabel('U')
end
legend('b=4','b=2','b=0','b=-2','b=-4')
Problema 3:
clear all; close all; clc;
X=40; dx=10; Y=40; dy=10;
Tmax=1*60*60; dt=10; k=0.8357;
nx=X/dx+1; ny=Y/dy+1;
nt=Tmax/dt+1;
h=k*(dt/(dx^2));
T(1:nx,1:ny,1:nt)=0;
T(:,1,:)=5;
T(:,ny,:)=200;
T(1,:,:)=30;
T(nx,:,:)=80;
Q(:,:,:)=T(:,:,:);
AA = zeros(nx-2,nx-2);
BB = zeros(nx-2,1);
for t=1:nt
for i=1:nx-2
for j=1:nx-2
AA(j,j)=2*(1+h);
if j<nx-2
AA(j,j+1)=-h;
AA(j+1,j)=-h;
end
BB(j,1)=h*T(i,j+1,t)+2*(1-h)*T(i+1,j+1,t)+h*T(i+2,j+1,t);
end
BB(1,1)=BB(1,1)+h*T(i+1,1,t);
BB(nx-2,1)=BB(nx-2,1)+h*T(i+1,ny,t);
m=AA;
n=BB;
[x]=gauss(m,n);
Q(i+1,2:ny-1,t+1)=x';
if t+1==nt
break
end
end
for j=1:ny-2
for i=1:nx-2
AA(i,i)=2*(1+h);
if j<nx-2
AA(j,j+1)=-h;
AA(j+1,j)=-h;
end
BB(i,1)=h*Q(i+1,j,t)+2*(1-h)*Q(i+1,j+1,t)+h*Q(i+1,j+2,t);
end
BB(1,1)=BB(1,1)+h*Q(1,j+1,t+1);
BB(nx-2,1)=BB(nx-2,1)+h*Q(nx,j+1,t+1);
m=AA;
n=BB;
[x]=gauss(m,n);
T(2:nx-1,j+1,i+1)=x';
if t+1==nt
break
end
end
end
disp(T(:,:,t-1))
EDP HIPERBOLICA
Problema 4
clear all; close all; clc;
L=1; nx=11; Tmax=1; nt=101;
c=1;
dx=L/(nx-1);
dt=Tmax/(nt-1);
X=0:dx:L;
k=c*((dt^2)/(dx^2));
y(1:nx,1:nt)=0;
for i=2:nx-1
y(i,1)=sin(pi*(i-1)*dx);
y(i,2)=y(i,1)+dt*2*pi*sin(2*pi*(i-1)*dx);
end
y(1,:)=0;
y(nx,:)=0;
for t=2:nt
for i=2:nx-1
y(i,t)=2*y(i,t)-y(i,t-1)+k*(y(i+1,t)+y(i-1,t)-2*y(i+1,t));
end
end

plot(X,y(:,t))
hold on
title('PROBLEMA 4')
xlabel('X')
ylabel('Temperatura')

You might also like