Problems with PDE (pdepe)
Show older comments
*I'm trying to solve the following pde in MATLAB, with pdepe:
Equation: du/dt = d^2(x)/dx^2
Initial condition: u'(0) = 0
Boundary conditions: u(0) = 20, u(1) = 5
I have everything in place, except the initial condition, which only seems to accept constants or simple expressions. My question is therefore: how can i define the initial condition as u'(0) = 0?
Below, the IC is set to 10 in lack of anything better. The code is as follows:* %------------------------------------------------------------------
function pdex1
m = 0;
x = linspace(0,20,40);
t = linspace(0,20,40);
sol = pdepe(m,@pdex1pde,@pdex1ic,@pdex1bc,x,t);
% Extract the first solution component as u.
u = sol(:,:,1);
% A surface plot is often a good way to study a solution.
surf(x,t,u)
title('Numerical solution computed with 20 mesh points.')
xlabel('Distance x')
ylabel('Time t')
% A solution profile can also be illuminating.
figure
plot(x,u(end,:))
title('Solution at t = 10')
xlabel('Distance x')
ylabel('u(x,t)')
% --------------------------------------------------------------
function [c,f,s] = pdex1pde(x,t,u,DuDx)
c = 1;
f = 0.00001*DuDx;
s = 0.5;
% --------------------------------------------------------------
function u0 = pdex1ic(x) u0 = 10
% --------------------------------------------------------------
function [pl,ql,pr,qr] = pdex1bc(xl,ul,xr,ur,t)
pl = ul-20;
ql = 0;
pr = ur-5;
qr = 0;
Answers (0)
Categories
Find more on PDE Solvers in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!