# PDE¶

## User Functions¶

These are functions that are imported into the global namespace with from diofant import *. They are intended for user use.

### pde_separate¶

diofant.solvers.pde.pde_separate(eq, fun, sep, strategy='mul')[source]

Separate variables in partial differential equation either by additive or multiplicative separation approach. It tries to rewrite an equation so that one of the specified variables occurs on a different side of the equation than the others.

Parameters: eq – Partial differential equation fun – Original function F(x, y, z) sep – List of separated functions [X(x), u(y, z)] strategy – Separation strategy. You can choose between additive separation (‘add’) and multiplicative separation (‘mul’) which is default.

Examples

>>> from diofant import E, Eq, Function, pde_separate, Derivative as D
>>> from diofant.abc import x, t
>>> u, X, T = map(Function, 'uXT')

>>> eq = Eq(D(u(x, t), x), E**(u(x, t))*D(u(x, t), t))
>>> pde_separate(eq, u(x, t), [X(x), T(t)], strategy='add')
[E**(-X(x))*Derivative(X(x), x), E**T(t)*Derivative(T(t), t)]

>>> eq = Eq(D(u(x, t), x, 2), D(u(x, t), t, 2))
>>> pde_separate(eq, u(x, t), [X(x), T(t)], strategy='mul')
[Derivative(X(x), x, x)/X(x), Derivative(T(t), t, t)/T(t)]


diofant.solvers.pde.pde_separate_add(eq, fun, sep)[source]

Helper function for searching additive separable solutions.

Consider an equation of two independent variables x, y and a dependent variable w, we look for the product of two functions depending on different arguments:

$$w(x, y, z) = X(x) + y(y, z)$$

Examples

>>> from diofant import E, Eq, Function, pde_separate_add, Derivative as D
>>> from diofant.abc import x, t
>>> u, X, T = map(Function, 'uXT')

>>> eq = Eq(D(u(x, t), x), E**(u(x, t))*D(u(x, t), t))
>>> pde_separate_add(eq, u(x, t), [X(x), T(t)])
[E**(-X(x))*Derivative(X(x), x), E**T(t)*Derivative(T(t), t)]


### pde_separate_mul¶

diofant.solvers.pde.pde_separate_mul(eq, fun, sep)[source]

Helper function for searching multiplicative separable solutions.

Consider an equation of two independent variables x, y and a dependent variable w, we look for the product of two functions depending on different arguments:

$$w(x, y, z) = X(x)*u(y, z)$$

Examples

>>> from diofant import Function, Eq, pde_separate_mul, Derivative as D
>>> from diofant.abc import x, y
>>> u, X, Y = map(Function, 'uXY')

>>> eq = Eq(D(u(x, y), x, 2), D(u(x, y), y, 2))
>>> pde_separate_mul(eq, u(x, y), [X(x), Y(y)])
[Derivative(X(x), x, x)/X(x), Derivative(Y(y), y, y)/Y(y)]


### pdsolve¶

diofant.solvers.pde.pdsolve(eq, func=None, hint='default', dict=False, solvefun=None, **kwargs)[source]

Solves any (supported) kind of partial differential equation.

Usage

pdsolve(eq, f(x,y), hint) -> Solve partial differential equation eq for function f(x,y), using method hint.

Details

eq can be any supported partial differential equation (see
the pde docstring for supported methods). This can either be an Equality, or an expression, which is assumed to be equal to 0.
f(x,y) is a function of two variables whose derivatives in that
variable make up the partial differential equation. In many cases it is not necessary to provide this; it will be autodetected (and an error raised if it couldn’t be detected).
hint is the solving method that you want pdsolve to use. Use
classify_pde(eq, f(x,y)) to get all of the possible hints for a PDE. The default hint, ‘default’, will use whatever hint is returned first by classify_pde(). See Hints below for more options that you can use for hint.
solvefun is the convention used for arbitrary functions returned
by the PDE solver. If not set by the user, it is set by default to be F.

Hints

Aside from the various solving methods, there are also some meta-hints that you can pass to pdsolve():

“default”:
This uses whatever hint is returned first by classify_pde(). This is the default argument to pdsolve().
“all”:

To make pdsolve apply all relevant classification hints, use pdsolve(PDE, func, hint=”all”). This will return a dictionary of hint:solution terms. If a hint causes pdsolve to raise the NotImplementedError, value of that hint’s key will be the exception object raised. The dictionary will also include some special keys:

• order: The order of the PDE. See also ode_order() in deutils.py
• default: The solution that would be returned by default. This is the one produced by the hint that appears first in the tuple returned by classify_pde().
“all_Integral”:
This is the same as “all”, except if a hint also has a corresponding “_Integral” hint, it only returns the “_Integral” hint. This is useful if “all” causes pdsolve() to hang because of a difficult or impossible integral. This meta-hint will also be much faster than “all”, because integrate() is an expensive routine.

Tips
• You can declare the derivative of an unknown function this way:

>>> from diofant import Function, Derivative
>>> from diofant.abc import x, y # x and y are the independent variables
>>> f = Function("f")(x, y) # f is a function of x and y
>>> # fx will be the partial derivative of f with respect to x
>>> fx = Derivative(f, x)
>>> # fy will be the partial derivative of f with respect to y
>>> fy = Derivative(f, y)

• See test_pde.py for many tests, which serves also as a set of examples for how to use pdsolve().

• pdsolve always returns an Equality class (except for the case when the hint is “all” or “all_Integral”). Note that it is not possible to get an explicit solution for f(x, y) as in the case of ODE’s

• Do help(pde.pde_hintname) to get help more information on a specific hint

Examples

>>> from diofant.solvers.pde import pdsolve
>>> from diofant import Function, diff, Eq
>>> from diofant.abc import x, y
>>> f = Function('f')
>>> u = f(x, y)
>>> ux = u.diff(x)
>>> uy = u.diff(y)
>>> eq = Eq(1 + (2*(ux/u)) + (3*(uy/u)))
>>> pdsolve(eq)
Eq(f(x, y), E**(-2*x/13 - 3*y/13)*F(3*x - 2*y))


### classify_pde¶

diofant.solvers.pde.classify_pde(eq, func=None, dict=False, **kwargs)[source]

Returns a tuple of possible pdsolve() classifications for a PDE.

The tuple is ordered so that first item is the classification that pdsolve() uses to solve the PDE by default. In general, classifications near the beginning of the list will produce better solutions faster than those near the end, though there are always exceptions. To make pdsolve use a different classification, use pdsolve(PDE, func, hint=<classification>). See also the pdsolve() docstring for different meta-hints you can use.

If dict is true, classify_pde() will return a dictionary of hint:match expression terms. This is intended for internal use by pdsolve(). Note that because dictionaries are ordered arbitrarily, this will most likely not be in the same order as the tuple.

You can get help on different hints by doing help(pde.pde_hintname), where hintname is the name of the hint without “_Integral”.

See diofant.pde.allhints or the diofant.pde docstring for a list of all supported hints that can be returned from classify_pde.

Examples

>>> from diofant.solvers.pde import classify_pde
>>> from diofant import Function, diff, Eq
>>> from diofant.abc import x, y
>>> f = Function('f')
>>> u = f(x, y)
>>> ux = u.diff(x)
>>> uy = u.diff(y)
>>> eq = Eq(1 + (2*(ux/u)) + (3*(uy/u)))
>>> classify_pde(eq)
('1st_linear_constant_coeff_homogeneous',)


### checkpdesol¶

diofant.solvers.pde.checkpdesol(pde, sol, func=None, solve_for_func=True)[source]

Checks if the given solution satisfies the partial differential equation.

pde is the partial differential equation which can be given in the form of an equation or an expression. sol is the solution for which the pde is to be checked. This can also be given in an equation or an expression form. If the function is not provided, the helper function _preprocess from deutils is used to identify the function.

If a sequence of solutions is passed, the same sort of container will be used to return the result for each solution.

The following methods are currently being implemented to check if the solution satisfies the PDE:

1. Directly substitute the solution in the PDE and check. If the solution hasn’t been solved for f, then it will solve for f provided solve_for_func hasn’t been set to False.

If the solution satisfies the PDE, then a tuple (True, 0) is returned. Otherwise a tuple (False, expr) where expr is the value obtained after substituting the solution in the PDE. However if a known solution returns False, it may be due to the inability of doit() to simplify it to zero.

Examples

>>> from diofant import Function, symbols, diff
>>> from diofant.solvers.pde import checkpdesol, pdsolve
>>> x, y = symbols('x y')
>>> f = Function('f')
>>> eq = 2*f(x,y) + 3*f(x,y).diff(x) + 4*f(x,y).diff(y)
>>> sol = pdsolve(eq)
>>> assert checkpdesol(eq, sol)[0]
>>> eq = x*f(x,y) + f(x,y).diff(x)
>>> checkpdesol(eq, sol)
(False, E**(-6*x/25 - 8*y/25)*(x*F(4*x - 3*y) - 6*F(4*x - 3*y)/25 + 4*Subs(Derivative(F(_xi_1), _xi_1), (_xi_1,), (4*x - 3*y,))))


## Hint Methods¶

These functions are meant for internal use. However they contain useful information on the various solving methods.

### pde_1st_linear_constant_coeff_homogeneous¶

diofant.solvers.pde.pde_1st_linear_constant_coeff_homogeneous(eq, func, order, match, solvefun)[source]

Solves a first order linear homogeneous partial differential equation with constant coefficients.

The general form of this partial differential equation is

$a \frac{df(x,y)}{dx} + b \frac{df(x,y)}{dy} + c f(x,y) = 0$

where $$a$$, $$b$$ and $$c$$ are constants.

The general solution is of the form:

>>> from diofant.solvers import pdsolve
>>> from diofant.abc import x, y, a, b, c
>>> from diofant import Function, pprint
>>> f = Function('f')
>>> u = f(x,y)
>>> ux = u.diff(x)
>>> uy = u.diff(y)
>>> genform = a*ux + b*uy + c*u
>>> pprint(genform, use_unicode=False)
d               d
a*--(f(x, y)) + b*--(f(x, y)) + c*f(x, y)
dx              dy

>>> pprint(pdsolve(genform), use_unicode=False)
-c*(a*x + b*y)
---------------
2    2
a  + b
f(x, y) = E               *F(-a*y + b*x)


References

• Viktor Grigoryan, “Partial Differential Equations” Math 124A - Fall 2010, pp.7

Examples

>>> from diofant.solvers.pde import (
... pde_1st_linear_constant_coeff_homogeneous)
>>> from diofant import pdsolve
>>> from diofant import Function, diff, pprint
>>> from diofant.abc import x,y
>>> f = Function('f')
>>> pdsolve(f(x,y) + f(x,y).diff(x) + f(x,y).diff(y))
Eq(f(x, y), E**(-x/2 - y/2)*F(x - y))
>>> pprint(pdsolve(f(x,y) + f(x,y).diff(x) + f(x,y).diff(y)), use_unicode=False)
x   y
- - - -
2   2
f(x, y) = E       *F(x - y)


### pde_1st_linear_constant_coeff¶

diofant.solvers.pde.pde_1st_linear_constant_coeff(eq, func, order, match, solvefun)[source]

Solves a first order linear partial differential equation with constant coefficients.

The general form of this partial differential equation is

$a \frac{df(x,y)}{dx} + b \frac{df(x,y)}{dy} + c f(x,y) = G(x,y)$

where $$a$$, $$b$$ and $$c$$ are constants and $$G(x, y)$$ can be an arbitrary function in $$x$$ and $$y$$.

The general solution of the PDE is:

>>> from diofant.solvers import pdsolve
>>> from diofant.abc import x, y, a, b, c
>>> from diofant import Function, pprint
>>> f = Function('f')
>>> G = Function('G')
>>> u = f(x,y)
>>> ux = u.diff(x)
>>> uy = u.diff(y)
>>> genform = a*u + b*ux + c*uy - G(x,y)
>>> pprint(genform, use_unicode=False)
d               d
a*f(x, y) + b*--(f(x, y)) + c*--(f(x, y)) - G(x, y)
dx              dy
>>> pprint(pdsolve(genform, hint='1st_linear_constant_coeff_Integral'), use_unicode=False)
/         /          b*x + c*y
|         |              /
|         |             |
|         |             |        a*xi
|         |             |      -------
|         |             |       2    2
|         |             |      b  + c   /b*xi + c*eta  -b*eta + c*xi
|         |             |     E       *G|------------, -------------
|         |             |               |   2    2         2    2
|  -a*xi  |             |               \  b  + c         b  + c
| ------- |             |
|  2    2 |            /
| b  + c  |
f(x, y) = |E       *|F(eta) + ------------------------------------------------
|         |                                  2    2
\         \                                 b  + c

\\|
|||
|||
|||
|||
|||
\      |||
| d(xi)|||
|      |||
/      |||
|||
|||
|||
-------|||
|||
//|eta=-b*y + c*x, xi=b*x + c*y


References

• Viktor Grigoryan, “Partial Differential Equations” Math 124A - Fall 2010, pp.7

Examples

>>> from diofant.solvers.pde import pdsolve
>>> from diofant import Function, diff, exp
>>> from diofant.abc import x,y
>>> f = Function('f')
>>> eq = -2*f(x,y).diff(x) + 4*f(x,y).diff(y) + 5*f(x,y) - exp(x + 3*y)
>>> pdsolve(eq)
Eq(f(x, y), E**(x/2 - y)*(E**(x/2 + 4*y)/15 + F(4*x + 2*y)))


### pde_1st_linear_variable_coeff¶

diofant.solvers.pde.pde_1st_linear_variable_coeff(eq, func, order, match, solvefun)[source]

Solves a first order linear partial differential equation with variable coefficients. The general form of this partial differential equation is

$a(x, y) \frac{df(x, y)}{dx} + a(x, y) \frac{df(x, y)}{dy} + c(x, y) f(x, y) - G(x, y)$

where $$a(x, y)$$, $$b(x, y)$$, $$c(x, y)$$ and $$G(x, y)$$ are arbitrary functions in $$x$$ and $$y$$. This PDE is converted into an ODE by making the following transformation.

1] $$\xi$$ as $$x$$

2] $$\eta$$ as the constant in the solution to the differential equation $$\frac{dy}{dx} = -\frac{b}{a}$$

Making the following substitutions reduces it to the linear ODE

$a(\xi, \eta)\frac{du}{d\xi} + c(\xi, \eta)u - d(\xi, \eta) = 0$

which can be solved using dsolve.

The general form of this PDE is:

>>> from diofant.solvers.pde import pdsolve
>>> from diofant.abc import x, y
>>> from diofant import Function, pprint
>>> a, b, c, G, f= [Function(i) for i in ['a', 'b', 'c', 'G', 'f']]
>>> u = f(x,y)
>>> ux = u.diff(x)
>>> uy = u.diff(y)
>>> genform = a(x, y)*u + b(x, y)*ux + c(x, y)*uy - G(x,y)
>>> pprint(genform, use_unicode=False)
d                     d
-G(x, y) + a(x, y)*f(x, y) + b(x, y)*--(f(x, y)) + c(x, y)*--(f(x, y))
dx                    dy


References

• Viktor Grigoryan, “Partial Differential Equations” Math 124A - Fall 2010, pp.7

Examples

>>> from diofant.solvers.pde import pdsolve
>>> from diofant import Function, diff, pprint, exp
>>> from diofant.abc import x,y
>>> f = Function('f')
>>> eq =  x*(u.diff(x)) - y*(u.diff(y)) + y**2*u - y**2
>>> pdsolve(eq)
Eq(f(x, y), E**(y**2/2)*F(x*y) + 1)


## Information on the pde module¶

This module contains pdsolve() and different helper functions that it uses. It is heavily inspired by the ode module and hence the basic infrastructure remains the same.

Functions in this module

These are the user functions in this module:

• pdsolve() - Solves PDE’s

• classify_pde() - Classifies PDEs into possible hints for dsolve().

• pde_separate() - Separate variables in partial differential equation either by

These are the helper functions in this module: