MATLAB: Multi variable simultaneous differential equations with nested function

higher order differential equationmultivariablenested functionsimultaneous odes

I would like to solve a set of mass transfer differential equations which are not only over time but over time and reactor length. I know I have to do a nested function but not quite sure how.
ds/dt=(d^2 s)/dx^2 – ds/dx- s
dq/dt=-∝.s
the 4 dimensionless variables are s (solvent concentration), x (reactor length) and t (time) and q (solute concentration). alpha is a constant.
The complexity is that while dq and ds are over time, there is a 2nd order d2s/dx2 term as well as ds/dx term in equation one, i.e. s is a factor of time AND distance inside reactor.
ANY help would be much much appreciated.

Best Answer

Hi Isaac
Modifying the initial example of the function pdepe please not your s is here u:
function pdepe_exercise_01
m = 0;
x = linspace(-10,10,200);
t = linspace(0,2,50);
sol = pdepe(m,@pdex1pde,@pdex1ic,@pdex1bc,x,t); % Extract first solution component as u
u = sol(:,:,1);
figure(1);surf(x,t,u) % surface plot
title('Numerical solution computed with 20 mesh points.')
xlabel('Distance x')
ylabel('Time t')
6
figure(2) % A solution profile
plot(x,u(end,:))
title('Solution at t = 2')
xlabel('Distance x')
ylabel('u(x,2)')
% --------------------------------------------------------------


function [c,f,s] = pdex1pde(x,t,u,DuDx)
c = 1;
f = DuDx;
s = -DuDx-u;
% --------------------------------------------------------------
function u0 = pdex1ic(x)
u0 = sin(pi*x);
% --------------------------------------------------------------
function [pl,ql,pr,qr] = pdex1bc(xl,ul,xr,ur,t)
pl = ul;
ql = 0;
pr = pi * exp(-t);
qr = 1;
setting c=pi^2
Since you neither defined initial or boundary conditions i left the same as in the example.
If you find this answer of any help solving your question,
please click on the thumbs-up vote link,
thanks in advance
John
Related Question