How to solve the following PDE equation
2 views (last 30 days)
Show older comments
0 Comments
Accepted Answer
Torsten
on 12 Jul 2024
Moved: Torsten
on 12 Jul 2024
I think you mean x(s,0) = 10 instead of x(s,t) = 10, don't you ?
The easiest way to solve the equation is to discretize the expressions on the right-hand side and solve the resulting system of ordinary differential equations using ode15. Here, the integral term can be approximated by MATLAB's "trapz".
Look up "method-of-lines" for more details.
2 Comments
Torsten
on 12 Jul 2024
integral_term = trapz(x, u);
"pdepe" supplies x and u pointwise, not for the complete interval [0,1]. Thus using "pdepe" this way is not possible.
It might be possible using this code for your purpose:
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
0 Comments
See Also
Categories
Find more on Eigenvalue Problems 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!