The exact solution to a partial differential equation

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.

 Réponse acceptée

Hi,
this works by using the symbolic math toolbox :
% 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 commentaires

Thanks for the detailed answer, Stephan. It answered my question, but still, I am not quite sure how to apply the boundary conditions. I am asking about the line of
conds = [u(0) == 1, Du(0) == 0];
Imagine a simple case of
IC: u(x,0) = A // Initial temperature across the slab
BC: u(0,t) = B // One side is kep at temperature B
BC: u_x(L,t) = 0 // The other side is insulated
How can I apply these three conditions to conds?
Stephan
Stephan le 10 Août 2018
Modifié(e) : Stephan le 10 Août 2018
If you have an analytical description of this case (an ode or a sytem of odes) you could also try solving it with symbolic toolbox. I never tried. So i can not definitly say, if this will work.
Note that we have not modelled a location x in the equation above as a variable.
@Stephan Can you tell me how can I solve 2 dimensional PDE in MATLAB and get analytical solution for that?
diff(F(x, y), x, 4)/E2 + diff(F(x, y), y, 4)/E1 + diff(diff(F(x, y), x, 2), y, 2)/G12 - (v*diff(diff(F(x, y), x, 2), y, 2))/E1 - (v*diff(diff(F(x, y), x, 2), y, 2))/E2 - (ay*h*sym(pi)^2*sin((sym(pi)*x)/a)*sin((sym(pi)*y)/b)*C(t))/a^2 - (ax*h*sym(pi)^2*sin((sym(pi)*x)/a)*sin((sym(pi)*y)/b)*C(t))/b^2 + (h*sym(pi)^4*sin((sym(pi)*x)/a)^2*sin((sym(pi)*y)/b)^2*A(t)^2)/(a^2*b^2) - (4*h*sym(pi)^2*cos((sym(pi)*x)/a)*cos((sym(pi)*y)/b)*sin((sym(pi)*x)/a)*sin((sym(pi)*y)/b)*A(t)^2)/(a*b)
@Stephan u_t = diff(u, t). So considered equation
% define equation
eqn = u == k* diff(u,2); is wrong
The question was about the second derivative (u{xx}_) so I believe @Stephan's answer is correct
Torsten
Torsten le 9 Juil 2025
Modifié(e) : Torsten le 9 Juil 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Version

R2018a

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by