Help with Solving PDE System with DAE in MATLAB
Show older comments
I hope you're doing well. My name is William. I’m currently working on a problem and was hoping you might be able to help. I have a system of PDEs, but one of the variables does not include a time derivative (e.g., no ∂u/∂t), even though the variable depends on both time and space. I'm not sure how to approach solving this in MATLAB. I’ve been able to implement it in gPROMS, but translating it into MATLAB has been challenging.
I tried to follow your DAE method, but my variables depend on both time and space—not just time—so I’m unsure how to proceed. If you could offer any guidance or point me in the right direction, I would greatly appreciate it.
Thank you for your time and support.
Best regards,
William
2 Comments
Torsten
on 30 Jul 2025
We need to know your PDE system together with the DAE and the solution method you try to implement. And the MATLAB code so far - if you already started.
Define a mass matrix M for your resulting DAE system.
It then takes the form
M*dy/dt = f(t,y).
Set the rows in M to 0 that correspond to the algebraic variables (velocity) and define the right-hand side as "velocity - value".
For an example, see
Solve Robertson Problem as Semi-Explicit Differential Algebraic Equations (DAEs)
under
I wonder what the algebraic equation for the velocity is and if it's not possible to derive its values directly from the other variables without defining it as an extra solution variable.
Don't you have a pdf file with a mathematical description of your model ? It's laborious to deduce everything just from your coding.
Answers (1)
You have discretized your equations in space. Thus the y variables are only functions of time for fixed z-coordinates.
Here is an example where y1 and y2 have time derivative:
dy1/dt = z + 2 , y1(z,0) = 0
dy2/dt = z - 4 , y2(z,0) = 0
and the third solution variable y3 is given by an algebraic equation
y3 = z + t.
tspan = 0:0.1:1;
z = (0:0.1:1).';
n = numel(z);
fun = @(t,y) [z+2;z-4;z+t-y(2*n+1:3*n)];
y0 = [zeros(n,1);zeros(n,1);zeros(n,1)];
M = [eye(2*n),zeros(2*n,n);zeros(n,2*n),zeros(n)];
options = odeset('Mass',M);
[T,Y] = ode15s(fun,tspan,y0,options);
figure(1)
plot(T,Y(:,1:n)) % should be y1 = t*(z+2)
figure(2)
plot(T,Y(:,n+1:2*n)) % should be y2 = t*(z-4)
figure(3)
plot(T,Y(:,2*n+1:3*n)) % should be y3 = z + t
9 Comments
William
on 30 Jul 2025
If you don't supply correct initial values for the algebraic variables, MATLAB tries to determine them consistently. Sometimes this works, sometimes not. In the above code, I changed the y0 vector from
y0 = [zeros(n,1);zeros(n,1);z];
to
y0 = [zeros(n,1);zeros(n,1);zeros(n,1)];
and it still works.
Did your code work in gProms ? Or why did you switch to MATLAB ?
Why don't you solve the Ergun equation for u in function f (maybe iteratively) ? This way, you don't have u as solution variable, but only as a deduced quantity.
William
on 30 Jul 2025
0== -dP1dz(z)-150 * mu .* u(z) .* ((1-void)^2) / (4 * 2.46e-6 * void^3)- 1.75 * (1-void) .* u(z) .* (abs(u(z))) .* Rho_gas(z) ./ (2 * 1.57e-3 * void^3) ;
In one spatial dimension, it's almost impossible that u changes sign over the length of the reactor. Thus u*abs(u) is either u^2 or -u^2 throughout depending on whether the flow is from the left or from the right. So it's a quadratic equation in u that has to be solved. Nothing complicated in my opinion.
One problem is that you included the boundary conditions after you computed the gradients. This should be done in advance.
And if you use SI units: are you sure that velocities in the order of 1 m/s are normal for your process ?
And you should remove the outer loop when you compute u:
%/*Ergun Equation*/
u(1)=u_feed;
for z = 2:N-1
AA=1.75*Rho_gas(z)*(1-void)./(2*1.57e-3*void^3);
BB=(150*mu*(1-void)^2)/(4*2.46e-6*void^3);
CC= P1x(z)/LLength;
u(z)=(-BB + sqrt(BB^2-4*AA*CC))/(2*AA);
ux(z)=(u(z)-u(z-1))/(dz);
end
u(N)=u(N-1);
instead of
%/*Ergun Equation*/
for z=1:N
u(1)=u_feed;
for z = 2:N-1
AA(z)=1.75*Rho_gas(z)*(1-void)./(2*1.57e-3*void^3);
BB=(150*mu*(1-void)^2)/(4*2.46e-6*void^3);
CC(z)= P1x(z)/LLength;
u(z)=(-BB + sqrt(BB^2-4.*AA(z).*CC(z)))./(2.*AA(z));
ux(z)=(u(z)-u(z-1))/(dz);
end
u(N)=u(N-1);
end
And in the former code, you didn't divide by LLength (which doesn't matter in this case because it's 1, but ...)
William
on 31 Jul 2025
I used
%/*Boundary Condition*/%
dTdt(1)=(T_ads - T_des)/PressTime;
T(N)=T(N-1);
P(N)=Pfeed;
P(1)=P(2);
y1(1)=y_feed1;
y1(N)=y1(N-1);
y2(1)=y_feed2;
y2(N)=y2(N-1);
for z = 2:N %*BFDM1 Method*%
Px(z)=(P(z)-P(z-1))/(dz);
Tx(z)=(T(z)-T(z-1))/(dz);
y1x(z)=(y1(z)-y1(z-1))/(dz);
y2x(z)=(y2(z)-y2(z-1))/(dz);
end
instead of
for z = 2:(N) %*BFDM1 Method*%
Px(z)=(P(z)-P(z-1))/(dz);
Tx(z)=(T(z)-T(z-1))/(dz);
y1x(z)=(y1(z)-y1(z-1))/(dz);
y2x(z)=(y2(z)-y2(z-1))/(dz);
end
%Px(1)=(-P(1)+P(2))/(dz);
%Tx(1)=(-T(1)+T(2))/(dz);
%y1x(1)=(-y1(1)+y1(2))/(dz);
%y2x(1)=(-y2(1)+y2(2))/(dz);
%/*Boundary Condition*/%
dTdt(1)=(T_ads - T_des)/PressTime;
T(N)=T(N-1);
P(N)=Pfeed;
P(1)=P(2);
y1(1)=y_feed1;
y1(N)=y1(N-1);
y2(1)=y_feed2;
y2(N)=y2(N-1);
and got the gProms result (at least for the graph you included).
I'm really surprised about your setting P(1) = P(2) because without a pressure gradient, there is no flow.
You get values from the integrator in the first and last point when you write the values in local variables:
T=y(1:Nz);
P=y(Nz+1:2*Nz);
T_Wall=y(2*Nz+1:3*Nz);
q1=y(3*Nz+1:4*Nz);
q2=y(1+4*Nz:5*Nz);
yy1=y(1+5*Nz:6*Nz);
yy2=y(1+6*Nz:7*Nz);
These values have to be overwritten by the boundary conditions before computing the gradients because they have no physical meaning.
I don't know how gProms handles this conflict between the values stored in the solution vector y for the unknowns and the values you explicitly define in the boundary points. MATLAB at least is a sequential programming language: things that should be used in line x have to be supplied somewhere before line x.
Categories
Find more on Numerical Integration and Differentiation 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!



