1D diffusion equation in spherical coordinates with moving boundary condition

Hi,
I was wondering how I could solve the 1D diffusion equation in spherical coordinates with a moving boundary condition using MATLAB. Is it possible to do this with pdepe? The differential equation is
Thank you in advance.

답변 (1개)

Yoki G
Yoki G 2022년 5월 4일
편집: Yoki G 2022년 5월 4일
% define mesh
x = linspace(0,1,25);
t = linspace(0,1,25);
m = 2; % you have m=1 for cylindrical coordinates and m=2 for spherical
cb = pdepe(m,@heatcyl,@heatic,@heatbc,x,t); % run solver
%plot across a secton for different times
for i = 1:length(t)
col=[i/length(t) 0 1-i/length(t)];
plot(x,cb(i,:),'color',col,'linewidth',2); hold on; grid on; box on;
end
xlabel('r')
ylabel('c')
% define functions
function [c,f,s] = heatcyl(x,t,u,dudx) % diffusion equation equation
Dsb = 1; % diffusion coefficient
c = 1;
f = Dsb*dudx;
s = 0;
end
function u0 = heatic(x) % initial condition
cb0 =1; % initial concentration
u0 = cb0+0*x;
end
function [pl,ql,pr,qr] = heatbc(xl,ul,xr,ur,t) %BCs
Dsb = 1; % diffusion coefficient
cl1 = @(t) 1-t; % example of a boundary function
pl = 0;
ql = -Dsb;
pr = -cl1(t);
qr = -Dsb; % for your neumann condition at r=1
end
Here is an example. If you look up pdepe documentation they have an example for cylindrical coordinates with two Dirichlet condition. You need to move the diffusion coefficient inside the derivative (assuming constant) and solve the resulting equation.

카테고리

도움말 센터File Exchange에서 Partial Differential Equation Toolbox에 대해 자세히 알아보기

제품

질문:

2021년 12월 4일

편집:

2022년 5월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by