Problems with pdepe with disconnected variables in c, f and s
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Sandy Woo
el 24 de Feb. de 2019
Hello, I would like to ask that could pdepe solve the 1-D convection-diffusion equation like:
![TIM截图20190310174650.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/207747/TIM%E6%88%AA%E5%9B%BE20190310174650.png)
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!
0 comentarios
Respuesta aceptada
Josh Meyer
el 2 de Mzo. de 2019
c, f, and s are expected to be column vectors with length equal to the number of equations being solved. Since you have 1 equation, they are expected to be scalars.
Some ideas:
I think your best bet is to compute Sg on the fly within the PDE function if you can, and extract the entry corresponding to the current time so that the equation coefficients stay scalar. Note that the times that are passed to that function are determined by ode15s during the solution process, so they might be different than the requested output times you pass in as t.
If you don't calculate Sg within the PDE function, perhaps you can use linear interpolation of the appropriate entries in Sg to get a value corresponding to the current time (the t input to pdex1pde is the current time as determined by ode15s).
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Eigenvalue Problems en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!