How to solve the following PDE equation
Show older comments
Accepted Answer
More Answers (1)
Bill Greene
on 12 Jul 2024
I don't know how to evaluate that integral using pdepe. However, I have written a pde solver (pde1dm) that has an input syntax very similar to pdepe and includes an option that makes this straightforward.
The "vectorized" option tells pde1dm to call your pdefun with a vector of x values spanning the complete spatial domain of your problem. I have included a slightly-modified version of your code below. If you want to try pde1dm, it can be downloaded using the link above.
function matlabAnswers_7_12_2024
theta=solvePDE;
end
function theta = solvePDE
nx=50;
x = linspace(0, 1, nx);
nx2=ceil(nx/2);
t = linspace(0, 10, 100);
if 0
sol = pdepe(0, @pdefun, @icfun, @bcfun, x, t);
else
opts.vectorized='on';
sol = pde1dm(0, @pdefun, @icfun, @bcfun, x, t,opts);
end
theta = sol(:,:,1);
figure; plot(x, sol(end,:)); title 'solution at final time';
figure; plot(t, sol(:,nx2)); title 'solution at center as a function of time';
end
function [c, f, s] = pdefun(x, t, u, dudx)
nx=length(x);
integral_term = trapz(x, u);
c = ones(1,nx);
f = dudx;
s = ones(1,nx)*integral_term;
end
function u0 = icfun(x)
u0 = 30* ones(size(x));
end
function [pl, ql, pr, qr] = bcfun(xl, ul, xr, ur, t)
pl = ul - 30;
ql = 0;
pr = ur - 30;
qr = 0;
end


Categories
Find more on 1-D Partial Differential Equations 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!