Any suggestions or comments would be sincerely appreciate!

1 view (last 30 days)

Show older comments

Dear all,

I want to solve one kind of systems of PDEs (as mentioned in the title) using pdepe. Here is an example:

(1)

(2)

where u_1, u2 are functions of spatial variable x and time t; x_0 is a constant; f(u_2, dudx_2) is a function of u_2, dudx_2; s(u_1, u_2) is a function of u_1, u_2.

Bascially, u_1 is independent of spatial variable x so I tried to using discontinuity setup to solve a simple example:

(1)

(2)

I choose x_0 = 0. Specific ic and bc are applied so that the analytical solution is: . Below code is trying to solve eq(1) when when x==0 (x==x_0) and when x!=0, we let . Then, u_1 is independent of spatial variable x, and also satisfies eq(1). But this code doesn't work well.

x = -0.2:0.0001:0.2;

t = [0 0.001 0.005 0.01 0.05 0.1 0.5 1];

m = 0;

sol = pdepe(m,@pdex2pde,@pdex2ic,@pdex2bc,x,t);

u1 = sol(:,:,1);

u2 = sol(:,:,2);

surf(x,t,u1)

title('Numerical solution with nonuniform mesh')

xlabel('Distance x')

ylabel('Time t')

zlabel('Solution u')

function [c,f,s] = pdex2pde(x,t,u,dudx) % Equation to solve

if x == 0 %% Outpot : Error: Spatial discretization has failed. Discretization supports only parabolic and elliptic equations, with flux term involving spatial derivative.

%if (x < 0.0005 & x > -0.0005) %% Outpot : Code could be run but the result is wrong

%if (x < 0.2 & x > -0.2) %% Outpot : Error: using surf (line 71) Z must be a matrix, not a scalar or vector.

c = [1; 1];

f = [0; u(2)];

s = [u(2)-u(1); u(2)];

else

c = [0; 1];

f = [u(1); u(2)];

s = [0; u(2)];

end

end

%----------------------------------------------

function u0 = pdex2ic(x) %Initial conditions

u0 = [0; exp(-2*x)];

end

%----------------------------------------------

function [pl,ql,pr,qr] = pdex2bc(xl,ul,xr,ur,t) % Boundary conditions

pl = [ul(1)-ur(1); ul(2)-exp(-t-2*xl)];

ql = [0; 0];

pr = [ul(1)-ur(1); ur(2)-exp(-t-2*xr)];

qr = [0; 0];

end

%------------

Bill Greene
on 2 Oct 2020

pdepe is not really designed to handle systems of coupled PDE and ODE. However, I have written a PDE solver for MATLAB that has similar syntax to pdepe but allows an arbitrary number of coupled ODE. If you want to try it, it can be downloaded here.

This script shows the solution of your example problem using this solver:

function matlabAnswers_10_1_2020

x = linspace(-0.2,0.2,11);

t=linspace(0,1,10);

m = 0;

x0=0;

xOde = x0; % location where ODE and PDE are coupled

[u,uode] = pde1dM(m, @pdeFunc,@icFunc,@bcFunc,x,t,...

@odeFunc, @odeIcFunc, xOde);

u1a=u1Anal(t);

figure; plot(t, uode(:,end), t, u1a, 'o');

legend('numerical', 'analytical');

xlabel('t'); ylabel('u1');

figure; plot(x, u(end,:), x, u2Anal(t(end), x), 'o'); grid on;

xlabel('x'); ylabel('u2');

title('Solution at Final Time');

legend('numerical', 'analytical');

end

function [c,f,s] = pdeFunc(x,t,u,DuDx,v,vdot)

c = 1;

f = u;

s = u;

end

function u0 = icFunc(x, t0)

u0=exp(-2*x);

end

function [pl,ql,pr,qr] = bcFunc(xl,ul,xr,ur,t,v,vdot)

pl = ul-exp(-t-2*xl);

ql = 0;

pr = ur-exp(-t-2*xr);

qr = 0;

end

function f=odeFunc(t,v,vdot,x,u,DuDx,~,~,~)

f=vdot-u+v;

end

function v0=odeIcFunc()

v0=0;

end

function u1=u1Anal(t)

u1=t.*exp(-t);

end

function u2=u2Anal(t,x)

nt=length(t);

nx=length(x);

u2=zeros(nt,nx);

for i=1:nt

u2(i,:) = exp(-t(i)-2*x);

end

end

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

Start Hunting!