Am I doing thid correct. pdepe function
显示 更早的评论
Hello to every one. I am trying to solve this problem using pdepe funcion. u_t = u_xx x in [0,1] t>=0, with boudary conditions
u_x(0,t)= pi*e^⁽-pi^2*t), and u(1,t)=0 initial condition u(x,0)=sin(pi*x)
having this matlab functions:
boundary conditios:
function [pl,ql,pr,qr] = bc1(xl,ul,xr,ur,t)
%BC1: MATLAB function M-file that specifies boundary conditions
%for a PDE in time and one space dimension.
pl = ul;
ql = pi*exp(-pi*pi*t);
pr = ur;
qr = 0;
intital conditions
function [c,b,s]=PDEeqn1(x,t,u,DuDx)
c=1;
b=DuDx;
s=0; %-DuDx+u;
end
with
x=0:0.1:1;
t=0:0.0005k:0.5;
m=0;
u = pdepe(m,@PDEeqn1,@initial1,@bc1,x,t);
My question is, if I am providing the rigth boudary conditios for my problem.
Thank to all of you.
Carlos
回答(1 个)
x = 0:0.1:1;
t = 0:0.05:0.5;
m = 0;
u = pdepe(m,@PDEeqn1,@initial1,@bc1,x,t);
plot(x,[u(1,:);u(2,:);u(3,:);u(4,:);u(end,:)])
function u0 = initial1(x)
u0 = sin(pi*x);
end
function [c,b,s]=PDEeqn1(x,t,u,DuDx)
c = 1;
b = DuDx;
s = 0; %-DuDx+u;
end
function [pl,ql,pr,qr] = bc1(xl,ul,xr,ur,t)
%BC1: MATLAB function M-file that specifies boundary conditions
%for a PDE in time and one space dimension.
pl = -pi*exp(-pi^2*t);
ql = 1.0;
pr = ur;
qr = 0;
end
6 个评论
Carlos Sosa Paz
2023-7-18
The boundary conditions are of the from
p + q*f = 0
where pl,ql stand for p,q at x=0 and pr,qr stand for p,q at x=1.
You set
f = DuDx
Thus the boundary condition form is
p + q*du/dx = 0
Everything else follows:
If you want to specify
u = value at x=0
, you have to set
pl = ul - value
ql = 0
If you want to specify
du/dx = value at x = 0
, you have to set
pl = -value
ql = 1
Same for the right boundary point x = 1.
Carlos Sosa Paz
2023-7-18
Carlos Sosa Paz
2023-7-24
xmesh = linspace(0,1,100);
tspan = 0:0.5:1;
m = 0;
sol = pdepe(m,@PDEeqn1,@initial1,@bc1,xmesh,tspan);
plot(xmesh,[sol(1,:);sol(2,:);sol(3,:)])
function [c,b,s]=PDEeqn1(x,t,u,DuDx)
c = 1;
b = DuDx;
s = -DuDx + u;
end
function [pl,ql,pr,qr] = bc1(xl,ul,xr,ur,t)
%BC1: MATLAB function M-file that specifies boundary conditions
%for a PDE in time and one space dimension.
pl = -2*t;
ql = 1;
pr = ur - t^2/2;
qr = 0;
end
function value = initial1(x)
%INITIAL1: MATLAB function M-file that specifies the initial condition
%for a PDE in time and one space dimension.
value = sin(x) + cos(x);
end
Carlos Sosa Paz
2023-7-24
类别
在 帮助中心 和 File Exchange 中查找有关 PDE Solvers 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

