Did I find the right examples for you? yes no      Crawl my project      Python Jobs

# sympy.pde_separate

All Samples(10)  |  Call(8)  |  Derive(0)  |  Import(2)
```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.

:param eq: Partial differential equation

:param fun: Original function F(x, y, z)

:param sep: List of separated functions [X(x), u(y, z)](more...)
```

```        def pde_separate(eq, fun, sep, strategy='mul'):
"""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.

:param eq: Partial differential equation

:param fun: Original function F(x, y, z)

:param sep: List of separated functions [X(x), u(y, z)]

:param strategy: Separation strategy. You can choose between additive
separation ('add') and multiplicative separation ('mul') which is
default.
"""

elif strategy == 'mul':
else:
assert ValueError('Unknown strategy: %s' % strategy)

if isinstance(eq, Equality):
if eq.rhs != 0:
return pde_separate(Eq(eq.lhs - eq.rhs), fun, sep, strategy)
assert eq.rhs == 0

# Handle arguments
orig_args = list(fun.args)
subs_args = []
for s in sep:
for j in range(0, len(s.args)):
subs_args.append(s.args[j])

else:
functions = reduce(operator.mul, sep)

# Check whether variables match
if len(subs_args) != len(orig_args):
raise ValueError("Variable counts do not match")
# Check for duplicate arguments like  [X(x), u(x, y)]
if len(subs_args) != len(set(subs_args)):
raise ValueError("Duplicate substitution arguments detected")
# Check whether the variables match
if set(orig_args) != set(subs_args):
raise ValueError("Arguments do not match")

# Substitute original function with separated...
result = eq.lhs.subs(fun, functions)

# Divide by terms when doing multiplicative separation
eq = 0
for i in result.args:
eq += i/functions
result = eq

svar = subs_args
dvar = subs_args[1:]
return _separate(result, svar, dvar)
```

```"""

from sympy import symbols, Eq, Function, pde_separate, pprint, sin, cos, latex
from sympy import Derivative as D

```
```
pprint("We can either separate this equation in regards with variable r:")
res_r = pde_separate(eq, Xi(r, phi, theta), [R(r), u(phi, theta)])
pprint(res_r)

pprint("Or separate it in regards of theta:")
res_theta = pde_separate(eq, Xi(r, phi, theta), [Theta(theta), u(r, phi)])
pprint(res_theta)

res_phi = pde_separate(eq, Xi(r, phi, theta), [Phi(phi), u(r, theta)])
```
```
pprint("\nLets try to separate phi again :)")
res_theta = pde_separate(eq_left, u(r, phi), [Phi(phi), R(r)])
pprint("\nThis time it is successful:")
pprint(res_theta)
```

```"""

from sympy import symbols, Eq, Function, pde_separate, pprint, sin, cos, latex
from sympy import Derivative as D

```
```
pprint ("We can either separate this equation in regards with variable r:")
res_r = pde_separate(eq, Xi(r, phi, theta), [R(r), u(phi, theta)])
pprint (res_r)

pprint ("Or separate it in regards of theta:")
res_theta = pde_separate(eq, Xi(r, phi, theta), [Theta(theta), u(r, phi)])
pprint (res_theta)

res_phi = pde_separate(eq, Xi(r, phi, theta), [Phi(phi), u(r, theta)])
```
```
pprint ("\nLets try to separate phi again :)")
res_theta = pde_separate(eq_left, u(r, phi), [Phi(phi), R(r)])
pprint ("\nThis time it is successful:")
pprint (res_theta)
```