Solving Partial Differential Equations with SymPy

Partial differential equations (PDEs) are used widely for the modeling of various physical phenomena. In simple case one can find symbolic solutions to some PDEs. The solution can then be described by means of either additive or multiplicative separable solutions. For the symbolic calculus needed, SymPy is being used - a python module for symbolic mathematics.

Ιn the first example we are going to consider additive separable solutions of the PDE. Consider an equation of two independent variables x, y, and a dependent variable w.

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

>>> from sympy import E, Eq, Function, pde_separate_add, Derivative as D 
>>> from sympy.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)]) 
[D(X(x), x)*exp(-X(x)), D(T(t), t)*exp(T(t))]

In the second example, we are going to search for multiplicative separable solutions of the PDE. Consider now an equation of two independent variables x, y, such that:

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

>>> from sympy import Function, Eq, pde_separate_mul, Derivative as D 
>>> from sympy.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)]) 
[D(X(x), x, x)/X(x), D(Y(y), y, y)/Y(y)]

Category: