
The exact solution to a partial differential equation
11 views (last 30 days)
Show older comments
I know that MATLAB Has a PDE solver, but I wonder if it is possible to obtain the exact solution. For example, consider the heat equation
u_t = k u{xx}_
Is it possible to solve it with a set of initial and boundary conditions to calculate the exact equation of u
u = f(x,t)
and
u(x=0) = f(t)
I don't need numeral solution or the graph but the general equations.
0 Comments
Accepted Answer
Stephan
on 8 Aug 2018
Hi,
% define symbolic variables
syms u(t) k
% define equation
eqn = u == k* diff(u,2);
% Solution without initial conditions
sol = dsolve(eqn);
% Define first derivative from u(t) for initial conditions
Du = diff(u);
% Define initial conditions
conds = [u(0) == 1, Du(0) == 0];
% Get solution with initial conditions
sol_conds = dsolve(eqn, conds);
will give:
>> pretty(sol)
/ t \ / t \
C1 exp| - ------- | + C2 exp| ------- |
\ sqrt(k) / \ sqrt(k) /
>> pretty(sol_conds)
/ t \ / t \
exp| ------- | exp| - ------- |
\ sqrt(k) / \ sqrt(k) /
-------------- + ----------------
2 2
or if you use a live script it looks like this:

Best regards
Stephan
6 Comments
Torsten
on 9 Jul 2025
Edited: Torsten
on 9 Jul 2025
@Stephan 's answer doesn't help to answer the original question. The requested u is a function of x and t following the partial differential equation
du/dt = k * d^2u/dx^2
The code
% define symbolic variables
syms u(t) k
% define equation
eqn = u == k* diff(u,2);
% Solution without initial conditions
sol = dsolve(eqn);
assumes that u is a function of t alone and solves k*u''(t) = u(t) which is an ordinary differential equation.
More Answers (0)
See Also
Categories
Find more on Boundary Conditions 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!