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)];endend%----------------------------------------------
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%------------
Best Answer