Solve PDEs Package Pdepe-1-2
Solve PDEs Package Pdepe-1-2
which we specify in the function M-file eqn1.m. (The specification m = 0 will be made later.)
%pde1.m: script M-file that solves and plots sols to the PDE stored in eqn1.m
Clc; close all; clear all
m = 0;
% define the solution mesh
x = linspace(0,1,20);
t = linspace(0,2,10);
% solve the PDE
u = pdepe(m,@eqn1,@initial1,@bc1,x,t);
%Plot solution
figure(1);
surf(x,t,u);
title('Surface plot of solution.');
xlabel('Distance x'); ylabel('Time t');
grid on
Often, we find it useful to plot solution profiles, for which t is fixed, and u is plotted against x.
The solution u(t, x) is stored as a matrix indexed by the vector indices of t and x. For example,
u(1, 5) returns the value of u at the point (t(1), x(5)). We can plot u initially (at t = 0) with the
command plot(x,u(1,:)) (see Figure 1.2).
Finally, a quick way to create a movie of the profile's evolution in time is with the following
MATLAB sequence.
fig = plot(x,u(1,:),'erase','xor')
for k=2:length(t)
set(fig,'xdata',x,'ydata',u(k,:))
pause(.5)
end
If you try this out, observe how quickly solutions to the heat equation approach their equilibrium
configuration. It is noted that the equilibrium configuration is the one that ceases to change in
time.
Section-3: System of Parabolic Partial Differential Equations
We next consider a system of two partial differential equations, though still in time and one
space dimension.
Example 2. Consider the nonlinear system of partial differential equations
This is a non-dimensionalized form of a PDE model for two competing populations. As with
solving ODE in MATLAB, the basic syntax for solving systems is the same as for solving single
equations, where each scalar is simply replaced by an analogous vector. In particular, MATLAB
specifies a system of n PDE as
Observe that the functions ck, bk, and sk can depend on all components of u and ux with boundary
conditions
and initial conditions
We solve equation (1.2) and plot its solutions with pde2.m (see Figure 1.5).
%pde2.m: MATLAB script M-file that solves the PDE
%stored in eqn2.m, bc2.m, and initial2.m
Clc; close all; clear all
m = 0;
x = linspace(0,1,10);
t = linspace(0,1,10);
sol = pdepe(m,@eqn2,@initial2,@bc2,x,t);
u1 = sol(:,:,1);
u2 = sol(:,:,2);
subplot(2,1,1)
surf(x,t,u1);
title('u1(x,t)'); xlabel('Distance x'); ylabel('Time t');
subplot(2,1,2)
surf(x,t,u2);
title('u2(x,t)'); xlabel('Distance x'); ylabel('Time t');
Instead of pdepe, how can we solve these partial differential equations by using FDM, FEM
or some other robust numerical methods?
Best of luck!