# use of pdepe for a space-dependent diffusivity

18 visualizzazioni (ultimi 30 giorni)
Giuseppe Pontrelli il 29 Mag 2024 alle 8:58
Commentato: Giuseppe Pontrelli il 29 Mag 2024 alle 10:31
I have a space-dependent heat equation
Dc/dt = d/dx (D(x) dc/dx)
where the function D(x) is not defined as a function, but a position-dependent
vector of (n) points : diff
The vector diff has the same length of x, so I have x(i) and diff(i), i=1,…,n
How can I implement pdepe?
cb = pdepe(m,@heatcyl,@heatic,@heatbc,x,t); % run solver
function [c,f,s] = heatcyl(x,t,u,dudx) % diffusion equation equation
c = 1;
f = dudx*diff; ???? <<<<<<<<< not sure about that, since diff is a vector
s = 0;
end
function u0 = heatic(x) % initial condition
u0=1;
end
function [pl,ql,pr,qr] = heatbc(xl,ul,xr,ur,t) %BCs
global diff n
pl=0;
ql=1;
pr=ur;
qr=0;
end
Thank you!
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Torsten il 29 Mag 2024 alle 9:17
Modificato: Torsten il 29 Mag 2024 alle 9:18
First: Don't name the vector "diff" since "diff" is an internal MATLAB function. Name it D, e.g.
Second: To get the correct value of D, use
f = interp1(X,D,x)*dudx;
where X is the coordinate vector to which the D-values belong.
You can pass both to your function by using
cb = pdepe(m,@(x,t,u,dudx)heatcyl(x,t,u,dudx,X,D),@heatic,@heatbc,x,t); % run solver
...
function [c,f,s] = heatcyl(x,t,u,dudx,X,D) % diffusion equation equation
c = 1;
f = interp1(X,D,x)*dudx;
s = 0;
end
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Giuseppe Pontrelli il 29 Mag 2024 alle 10:31
thank you Torsten. Your suggestions were very useful, and now the code run nicely!

Accedi per commentare.

### Categorie

Scopri di più su Partial Differential Equation Toolbox in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by