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 个评论

Thank you for your quick response, so to be clear, pl is for u_x(0,t) and which is for u_x(1,t) Thank you again.
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.
Thank you for your answer. It clarifies a lot
I have this problem and when comparing it with a colleague we found different solutions I don't know if I'm doing the right thing. Thank you.
u_{t} = u_{xx} -u_{x}+ u, x in [0,1], t>=0,
boundary conditions
u_x(0,t)=2t, u(1,t)=t^2/2
initial condition
u(x,0)=sin(x)+cos(x)
matlab code:
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; % ul;%2*t;%-pi*exp(-pi*pi*t);
ql = 1;%1;
pr = t*t/2;
qr = 1;%ur;
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);%sin(pi*x); %4*x-(4*x*x); %sin(x)+cos(x);
Tank you in advance.
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
Thank you, now I having the same output.

请先登录,再进行评论。

产品

版本

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by