PDE#

用户功能#

这些函数是通过 from sympy import * . 它们是供用户使用的。

sympy.solvers.pde.pde_separate(eq, fun, sep, strategy='mul')[源代码]#

用加法或乘法分离方法分离偏微分方程中的变量。它试图重写一个方程,使其中一个指定的变量出现在等式的另一边。

参数:
  • eq -- 偏微分方程

  • fun -- 原函数F(x,y,z)

  • sep -- 分离功能列表 [X(X),u(y,z)]

  • strategy -- 分离策略。您可以在加法分隔符(“add”)和乘法分隔符(“mul”)之间进行选择,这是默认设置。

实例

>>> from sympy import E, Eq, Function, pde_separate, 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(eq, u(x, t), [X(x), T(t)], strategy='add')
[exp(-X(x))*Derivative(X(x), x), exp(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, 2))/X(x), Derivative(T(t), (t, 2))/T(t)]
sympy.solvers.pde.pde_separate_add(eq, fun, sep)[源代码]#

搜索可加分离解的辅助函数。

考虑一个由两个自变量x,y和一个因变量w组成的方程,我们寻找两个函数的乘积,这两个函数取决于不同的参数:

\(w(x, y, z) = X(x) + y(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)])
[exp(-X(x))*Derivative(X(x), x), exp(T(t))*Derivative(T(t), t)]
sympy.solvers.pde.pde_separate_mul(eq, fun, sep)[源代码]#

搜索乘法可分解的辅助函数。

考虑一个由两个自变量x,y和一个因变量w组成的方程,我们寻找两个函数的乘积,这两个函数取决于不同的参数:

\(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)])
[Derivative(X(x), (x, 2))/X(x), Derivative(Y(y), (y, 2))/Y(y)]
sympy.solvers.pde.pdsolve(eq, func=None, hint='default', dict=False, solvefun=None, **kwargs)[源代码]#

解任何一类(支持的)偏微分方程。

Usage

pdsolve(eq,f(x,y),hint)->使用hint方法求解函数f(x,y)的偏微分方程eq。

Details

eq 可以是任何支持的偏微分方程(请参见

所支持方法的pde docstring)。这可以是一个等式,也可以是一个表达式,假定它等于0。

f(x,y) 是两个变量的函数,其中的导数

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 could not be detected).

hint 是希望pdsolve使用的求解方法。使用

分类u pde(eq,f(x,y))以获得pde的所有可能提示。默认提示“default”将使用classifyu pde()首先返回的任何提示。你可以在下面看到更多的提示。

solvefun 是否返回用于任意函数的约定

通过PDE解算器。如果用户未设置,则默认设置为F。

Hints

除了求解meta()的各种提示外,还有一些方法可以传递给你:

“违约”:

这将使用classifyu pde()首先返回的任何提示。这是pdsolve()的默认参数。

“全部”:

要使pdsolve应用所有相关的分类提示,请使用pdsolve(PDE,func,hint=“all”)。这将返回一个字典提示:解决方案术语。如果提示导致pdsolve引发NotImplementedError,则该提示的键的值将是引发的异常对象。字典还将包括一些特殊的关键字:

  • 顺序:PDE的顺序。另请参见中的ode_order()双耳.py

  • default:默认情况下返回的解决方案。这是由classifyu pde()返回的元组中第一个出现的提示生成的。

“all_Integral”:

这与“all”相同,除非提示也有相应的“_Integral”提示,它只返回“_Integral”提示。如果“all”由于一个困难或不可能的积分而导致pdsolve()挂起,这一点很有用。这个meta提示也比“all”快得多,因为integrate()是一个昂贵的例程。

有关提示的更多信息,请参见classifyu pde()docstring;有关所有支持的提示的列表,请参见pde docstring。

Tips
  • 可以通过以下方式声明未知函数的导数:

    >>> from sympy import Function, Derivative
    >>> from sympy.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)
    
  • 见测试_pde.py对于许多测试,这也是如何使用pdsolve()的一组示例。

  • pdsolve始终返回一个相等类(提示为“all”或“all効Integral”时除外)。注意,不可能像在ODE的情况下那样得到f(x,y)的显式解

  • 帮帮忙(pde.pdeu hintname)获取有关特定提示的详细信息

实例

>>> from sympy.solvers.pde import pdsolve
>>> from sympy import Function, Eq
>>> from sympy.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)), 0)
>>> pdsolve(eq)
Eq(f(x, y), F(3*x - 2*y)*exp(-2*x/13 - 3*y/13))
sympy.solvers.pde.classify_pde(eq, func=None, dict=False, *, prep=True, **kwargs)[源代码]#

返回PDE的可能pdsolve()分类的元组。

对元组进行排序,因此第一项是pdsolve()在默认情况下用于解决PDE的分类。一般来说,靠近列表开头的分类将比接近末尾的分类更快地产生更好的解决方案,尽管总会有例外。要使pdsolve使用不同的分类,请使用pdsolve(PDE,func,hint=<classification>)。另请参见pdsolve()docstring以了解可以使用的不同元提示。

如果 dict 为true,classifyu pde()将返回提示:匹配表达式条款。这是pdsolve()内部使用的。请注意,由于字典是任意排序的,因此这很可能与元组的顺序不同。

你可以通过帮助获得不同提示的帮助(pde.pdeu hintname),其中hintname是不带“_Integral”的提示名称。

看Symphy.pde.All暗示或者Symphy.pdedocstring,用于所有支持的提示列表,这些提示可以从classifypde返回。

实例

>>> from sympy.solvers.pde import classify_pde
>>> from sympy import Function, Eq
>>> from sympy.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)), 0)
>>> classify_pde(eq)
('1st_linear_constant_coeff_homogeneous',)
sympy.solvers.pde.checkpdesol(pde, sol, func=None, solve_for_func=True)[源代码]#

检查给定解是否满足偏微分方程。

偏微分方程是偏微分方程,可以用方程或表达式的形式给出。sol是要检查pde的溶液。这也可以用等式或表达式的形式给出。如果没有提供函数,则使用deutils的helper函数_preprocess来标识函数。

如果传递了一系列解决方案,则将使用相同类型的容器来返回每个解决方案的结果。

目前正在实施以下方法来检查解决方案是否满足PDE:

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

如果解决方案满足PDE,则返回一个元组(True,0)。否则是一个元组(False,expr),其中expr是在PDE中替换解决方案后获得的值。但是,如果已知的解决方案返回False,可能是由于doit()无法将其简化为零。

实例

>>> from sympy import Function, symbols
>>> from sympy.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, (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))*exp(-6*x/25 - 8*y/25))

提示方法#

这些功能仅供内部使用。然而,它们包含了关于各种求解方法的有用信息。

sympy.solvers.pde.pde_1st_linear_constant_coeff_homogeneous(eq, func, order, match, solvefun)[源代码]#

求解一阶常系数线性齐次偏微分方程。

这个偏微分方程的一般形式是

\[a\frac{\partial f(x,y)}{\partial x}\]

在哪里? \(a\)\(b\)\(c\) 是常数。

一般解决方案如下:

\[f(x,y)=f(-a y+b x)e^-\frac{c(a x+b y)}{a^2+b^2}}\]

pdsolve ::

>>> from sympy.solvers import pdsolve
>>> from sympy.abc import x, y, a, b, c
>>> from sympy 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)
  d               d
a*--(f(x, y)) + b*--(f(x, y)) + c*f(x, y)
  dx              dy

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

实例

>>> from sympy import pdsolve
>>> from sympy import Function, pprint
>>> from sympy.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), F(x - y)*exp(-x/2 - y/2))
>>> pprint(pdsolve(f(x,y) + f(x,y).diff(x) + f(x,y).diff(y)))
                      x   y
                    - - - -
                      2   2
f(x, y) = F(x - y)*e

工具书类

  • Viktor Grigoryan,“偏微分方程”数学124A-2010年秋季,第7页

sympy.solvers.pde.pde_1st_linear_constant_coeff(eq, func, order, match, solvefun)[源代码]#

求解一阶常系数线性偏微分方程。

这个偏微分方程的一般形式是

\[a\frac{\partial f(x,y)}{\partial x}\]

在哪里? \(a\)\(b\)\(c\) 是常数和 \(G(x, y)\) 可以是中的任意函数 \(x\)\(y\) .

PDE的一般解决方案是:

\[f(x,y)=\左。\左[F(\eta)+\frac{1}{a^2+b^2}\]

在哪里? \(F(\eta)\) 是任意单值函数。解决办法可以与 pdsolve ::

>>> from sympy.solvers import pdsolve
>>> from sympy.abc import x, y, a, b, c
>>> from sympy import Function, pprint
>>> f = Function('f')
>>> G = Function('G')
>>> u = f(x, y)
>>> ux = u.diff(x)
>>> uy = u.diff(y)
>>> genform = a*ux + b*uy + c*u - G(x,y)
>>> pprint(genform)
  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'))
          //          a*x + b*y                                             \  >
          ||              /                                                 |  >
          ||             |                                                  |  >
          ||             |                                      c*xi        |  >
          ||             |                                     -------      |  >
          ||             |                                      2    2      |  >
          ||             |      /a*xi + b*eta  -a*eta + b*xi\  a  + b       |  >
          ||             |     G|------------, -------------|*e        d(xi)|  >
          ||             |      |   2    2         2    2   |               |  >
          ||             |      \  a  + b         a  + b    /               |  >
          ||             |                                                  |  >
          ||            /                                                   |  >
          ||                                                                |  >
f(x, y) = ||F(eta) + -------------------------------------------------------|* >
          ||                                  2    2                        |  >
          \\                                 a  + b                         /  >

>         \|
>         ||
>         ||
>         ||
>         ||
>         ||
>         ||
>         ||
>         ||
>  -c*xi  ||
>  -------||
>   2    2||
>  a  + b ||
> e       ||
>         ||
>         /|eta=-a*y + b*x, xi=a*x + b*y

实例

>>> from sympy.solvers.pde import pdsolve
>>> from sympy import Function, pprint, exp
>>> from sympy.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), (F(4*x + 2*y)*exp(x/2) + exp(x + 4*y)/15)*exp(-y))

工具书类

  • Viktor Grigoryan,“偏微分方程”数学124A-2010年秋季,第7页

sympy.solvers.pde.pde_1st_linear_variable_coeff(eq, func, order, match, solvefun)[源代码]#

求解一阶变系数线性偏微分方程。这个偏微分方程的一般形式是

\[a(x,y)\frac{\partial f(x,y)}{\partial x}\]

在哪里? \(a(x, y)\)\(b(x, y)\)\(c(x, y)\)\(G(x, y)\) 任意函数在 \(x\)\(y\) . 通过进行以下转换,此PDE转换为ODE:

  1. \(\xi\) as \(x\)

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

进行前面的替换将其简化为线性颂歌

\[A(席席,席席)\压裂{杜}{D\Xi}+C(\Xi,\eta)U - G(\xI,\eta)=0\]

可以用 dsolve .

>>> from sympy.abc import x, y
>>> from sympy 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)
                                     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

实例

>>> from sympy.solvers.pde import pdsolve
>>> from sympy import Function, pprint
>>> from sympy.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), F(x*y)*exp(y**2/2) + 1)

工具书类

  • Viktor Grigoryan,“偏微分方程”数学124A-2010年秋季,第7页

有关pde模块的信息#

此模块包含pdsolve()和它使用的不同助手函数。它深受ode模块的启发,因此基础设施保持不变。

本模块中的功能

以下是本模块中的用户功能:

  • pdsolve()-解决PDE的

  • classifyu pde()-将pde分类为dsolve()的可能提示。

  • pde_separate()—将偏微分方程中的变量分开

    加法或乘法分离法。

以下是本模块中的帮助函数:

  • pde_separate_add()—用于搜索加法可分离解的帮助函数。

  • pde_separate_mul()—用于搜索乘法的助手函数

    可分离的解决方案。

当前实现的解算器方法

以下方法用于求解偏微分方程。有关每个函数的详细信息,请参见各种pde_hint()函数的docstrings(run help(pde)):

  • 一阶常系数线性齐次偏微分方程。

  • 一阶常系数线性一般偏微分方程。

  • 一阶变系数线性偏微分方程。