Please help me solve this material balance

16 vues (au cours des 30 derniers jours)
Rachael
Rachael le 11 Sep 2023
  8 commentaires
Rachael
Rachael le 13 Sep 2023
x = [18.4 15.7 22.6 21.8 29.8 21.1 21.9 17.9 21 16.7 16.2 22.1 19.1];
t = [0 24 48 72 96 120 144 168 192 216 240 264 288];
m = 0;
sol = pdepe(m, @pdefun, @pdeic, @pdebc, x, t);
u1 = sol(:,:,1);
u2 = sol(:,:,2);
surf(x,t,u1)
title('u_1(x,t)')
xlabel('Distance x')
ylabel('Time t')
surf(x,t,u2)
title('u_2(x,t)')
xlabel('Distance x')
ylabel('Time t')
%% -------------- Local functions --------------
% Partial Differential Equation to solve
function [c, f, s] = pdefun(x, t, u, dudx)
c = [1; 1];
f = [0.00000256; 0.0000198].*dudx;
y = u(1) - u(2);
F = 0.0017*exp(-0.082*y) - -5.63*exp(-0.082*y);
s = [-F; F];
end
% Initial Conditions
function u0 = pdeic(x)
u0 = [1; 0];
end
% Boundary Conditions
function [pl, ql, pr, qr] = pdebc(xl, ul, xr, ur, t)
pl = [0; ul(2)];
ql = [1; 0];
pr = [ur(1)-1; 0];
qr = [0; 1];
end
Error using pdepe
The entries of XMESH must be strictly increasing.
Rachael
Rachael le 13 Sep 2023
x = [0.05 0.1 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50 0.55 0.61];
t = [0 24 48 72 96 120 144 168 192 216 240 264 288];
m = 0;
sol = pdepe(m, @pdefun, @pdeic, @pdebc, x, t);
u1 = sol(:,:,1);
u2 = sol(:,:,2);
surf(x,t,u1)
title('u_1(x,t)')
xlabel('Distance x')
ylabel('Time t')
surf(x,t,u2)
title('u_2(x,t)')
xlabel('Distance x')
ylabel('Time t')
%% -------------- Local functions --------------
% Partial Differential Equation to solve
function [c, f, s] = pdefun(x, t, u, dudx)
c = [1; 1];
f = [0.00000256; 0.0000198].*dudx;
y = u(1) - u(2);
F = 0.0017*exp(-0.082*y) - -5.63*exp(-0.082*y);
s = [-F; F];
end
% Initial Conditions
function u0 = pdeic(x)
u0 = [1; 0];
end
% Boundary Conditions
function [pl, ql, pr, qr] = pdebc(xl, ul, xr, ur, t)
pl = [0; ul(2)];
ql = [1; 0];
pr = [ur(1)-1; 0];
qr = [0; 1];
end
Unrecognized function or variable 'pdeic'.
Function definitions in a script must appear at the end of the file.
Move all statements after the "pdebc" function definition to before the first local function definition.
Error in pdepe (line 229)
temp = feval(ic,xmesh(1),varargin{:});

Connectez-vous pour commenter.

Réponse acceptée

Torsten
Torsten le 11 Sep 2023
Modifié(e) : Torsten le 12 Sep 2023
This is a typical problem for MATLAB's "pdepe". So I suggest you use this integrator for partial differential equations.
  9 commentaires
Rachael
Rachael le 13 Sep 2023
x = [0.05 0.1 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50 0.55 0.61];
t = [0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.17];
m = 0;
sol = pdepe(m, @pdefun, @icfun, @bcfun, x, t);
Error using pdepe
Unexpected output of PDEFUN. For this problem PDEFUN must return three column vectors of length 2.
u1 = sol(:,:,1);
u2 = sol(:,:,2);
surf(x,t,u1)
title('u_1(x,t)')
xlabel('Distance x')
ylabel('Time t')
surf(x,t,u2)
title('u_2(x,t)')
xlabel('Distance x')
ylabel('Time t')
%% -------------- Local functions --------------
% Partial Differential Equation to solve
function [c, f, s] = pdefun(x, t, u, dudx)
D1= 0.00000190;
D2=0.0000198;
p=1;
v1=0.0011;
v2=0.0026;
r=0.000006;
k=0.082;
C=0.0205;
R=8.205;
T=305.15;
M=16;
e=0.036;
c = [1; 1];
f = [D1-v1; p*(D2-v2)].*dudx;
F = -r+k*(C-c);
J =(-(R*T*e)/M)+k*(C-c);
s = [F; J];
end
% Initial Conditions
function u0 = icfun(x)
u0 = [x; 0];
end
% Boundary Conditions
function [pl, ql, pr, qr] = bcfun(xl, ul, xr, ur, t)
pl = [0; ul(0.61)];
ql = [0; 0];
pr = [0; ur(0.61)];
qr = [0; 0];
end
Torsten
Torsten le 13 Sep 2023
x = [0.05 0.1 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50 0.55 0.61];
t = [0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.17];
m = 0;
sol = pdepe(m, @pdefun, @icfun, @bcfun, x, t);
u1 = sol(:,:,1);
u2 = sol(:,:,2);
surf(x,t,u1)
title('u_1(x,t)')
xlabel('Distance x')
ylabel('Time t')
surf(x,t,u2)
title('u_2(x,t)')
xlabel('Distance x')
ylabel('Time t')
%% -------------- Local functions --------------
% Partial Differential Equation to solve
function [c, f, s] = pdefun(x, t, u, dudx)
D1= 0.00000190;
D2=0.0000198;
p=1;
v1=0.0011;
v2=0.0026;
r=0.000006;
k=0.082;
C=0.0205;
R=8.205;
T=305.15;
M=16;
e=0.036;
c = [1; 1];
f = [D1; p*D2].*dudx;
F = -r+k*(C-u(1));
J =(-(R*T*e)/M)+k*(C-u(1));
s = [F-v1*dudx(1); J-p*v2*dudx(2)];
end
% Initial Conditions
function u0 = icfun(x)
u0 = [x; 0];
end
% Boundary Conditions
function [pl, ql, pr, qr] = bcfun(xl, ul, xr, ur, t)
v1=0.0011;
v2=0.0026;
C=0.0205;
pl = [-v1*(ul(1)-C); -v2*(ul(2)-C)];
ql = [1; 1];
pr = [0; 0];
qr = [1; 1];
end

Connectez-vous pour commenter.

Plus de réponses (1)

Sam Chak
Sam Chak le 13 Sep 2023
@Torsten has shown you how to solve PDEs in MATLAB. From the PDEs,
you need to rearrange and rewrite the equations in the form that the pdepe() solver expects: c, f, s.
Only then, you can code the local function pdefun(x, t, u, dudx).

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by