Problems with pdepe with disconnected variables in c, f and s
Show older comments
Hello, I would like to ask that could pdepe solve the 1-D convection-diffusion equation like:

when Sg, DL and V(x) are known variables along x direction? I hope to calculate the u at each time and position. For x = [0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] and t = [1800 3000 5000], there is a 10*3 size matrix of Sg. So at each time and position, there is a measured Sg which is stored in my xlsx file. Meanwhile, v(x) and DL are functions of Sg. In the equation, Sg could be calculated as the mean value of them between two time points and/or x positions.
Therefore I wrote a code in the editor as:
function solve_convection_diffusion_pdepe
global m Sg vx D
m=0;
Sg = xlsread('C:\Users\k\Desktop\Sg.xlsx');
% Sg are calculated as the mean value of them between two time points at the same x position.
Sg = cat(1,(Sg(:,1)+Sg(:,2))/2,(Sg(:,2)+Sg(:,3))/2);
Sg = Sg';
vx=0.01./Sg;
D=0.5*vx;
x = linspace(0,1,11);
% In the measurement the first position is not 0 but a certain value like 0.1.
x = [0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1];
t = [0 1800 3000 5000];
sol = pdepe(m,@pdex1pde,@pdex1ic,@pdex1bc,x,t);
for I=1:size(t,2)
semilogy(x,sol(I,:), 'color',[rand rand rand]);
axis tight;
xlabel('x');
ylabel('C');
pause(1);
title(sprintf('time = %1.3f',t(1,I)), 'fontsize',16)
hold on;
end
function [c,f,s] = pdex1pde(x,t,u,DuDx)
global Sg deltat vx D
c = Sg;
f = D.*DuDx;
s = -vx.*DuDx;
function u0 = pdex1ic(x)
u0=0;
function [pl,ql,pr,qr] = pdex1bc(xl,ul,xr,ur,t)
pl = ul;
ql = 0;
pr = 0;
qr = 1;
Then matlab inform me as:
Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-10.
Error in pdepe/pdeodes (line 359)
up(:,ii) = ((xim(ii) * fR - xim(ii-1) * fL) + ...
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode15s (line 150)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in pdepe (line 289)
[t,y] = ode15s(@pdeodes,t,y0(:),opts);
Any idea what on earth is going wrong? Thanks in advance!
Accepted Answer
More Answers (0)
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!