47 views (last 30 days)

Hello everyone!

I would like to solve a first order partial differential equations (2 coupled equations) system numerically. I just want to make sure that my thoughts are correct.

So firstly, I will start by doing a discretization to each of the two equations and then I will use ode15s to solve the ordinary differential equations that I got from the first step. Am I right? Which method of discretization do you recommend me to use?

Note: My equations are similar to the linear advection equation but with a source term.

Thank you very much.

Malak

Torsten
on 18 Jan 2019

Edited: Torsten
on 18 Jan 2019

%program solves

% dy1/dt + v1*dy1/dx = s1*y1*y2

% dy2/dt + v2*dy2/dx = s2*y1*y2

% y1(0,x) = y2(0,x) = 0

% y1(t,1) = y2(t,0) = 1

% for 0 <= t <= 400

function main

nx = 500;

y1 = zeros(nx,1);

y1(end) = 1.0;

y2 = zeros(nx,1);

y2(1) = 1.0;

ystart = [y1;y2];

tstart = 0.0;

tend = 400;

nt = 41;

tspan = linspace(tstart,tend,nt);

xstart = 0.0;

xend = 1.0;

x = linspace(xstart,xend,nx);

x = x.';

v1 = -0.005;

v2 = 0.0025;

v = [v1 v2];

s1 = 3.0e-3;

s2 = -4.0e-3;

s = [s1 s2];

[T,Y] = ode15s(@(t,y)fun(t,y,nx,x,v,s),tspan,ystart);

plot(x,Y(20,1:nx), x,Y(20,nx+1:2*nx))

end

function dy = fun(t,y,nx,x,v,s)

y1 = y(1:nx);

y2 = y(nx+1:2*nx);

dy1 = zeros(nx,1);

dy2 = zeros(nx,1);

dy1(1:nx-1) = -v(1)*(y1(2:nx)-y1(1:nx-1))./(x(2:nx)-x(1:nx-1)) + s(1)*y1(1:nx-1).*y2(1:nx-1);

dy1(nx) = 0.0;

dy2(1) = 0.0;

dy2(2:nx) = -v(2)*(y2(2:nx)-y2(1:nx-1))./(x(2:nx)-x(1:nx-1)) + s(2)*y1(2:nx).*y2(2:nx) ;

dy = [dy1;dy2];

end

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/440015-first-order-partial-differential-equations-system-numerical-solution#comment_661000

⋮## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/440015-first-order-partial-differential-equations-system-numerical-solution#comment_661000

## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/440015-first-order-partial-differential-equations-system-numerical-solution#comment_661779

⋮## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/440015-first-order-partial-differential-equations-system-numerical-solution#comment_661779

Sign in to comment.