1D diffusion equation in spherical coordinates with moving boundary condition
Afficher commentaires plus anciens
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.
Réponses (1)
% 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.
Catégories
En savoir plus sur Symbolic Math Toolbox dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!