Reputation: 71
when solving a system of partial differential equation using sympy I'm facing a problem. A reduced problem looks as following:
My simplified problem consists of two PDEs
d
──(u(x)) = 0
dx
2
d d d
──(v(x)) = ──(u(x)) + ───(u(x))
dx dx 2
dx
the solution I expect is d/dx(v(x))=0
. I want to solve this with sympy.
But when doing the following
from sympy import *
u = Function('u',Real=True)(x)
v = Function('v',Real=True)(x)
eq1 = Eq(diff(u,x), 0)
eq2 = Eq(diff(v,x), diff(u,x,x)+diff(u,x))
solve([eq1,eq2],diff(v,x))
the output is
⎧ 2 ⎫
⎪d d d ⎪
⎨──(v(x)): ──(u(x)) + ───(u(x))⎬
⎪dx dx 2 ⎪
⎩ dx ⎭
which is identical with the one obtained by calling
solve([eq2],diff(v,x))
Question: Why is the eq1 not inserted? At least in the first diff term which exactly matches the equation? How can I trigger this or I am doing something wrong here?
Thank you :)
Upvotes: 0
Views: 319
Reputation: 14500
You said you're solving PDEs but these are ODEs. Also you aren't really "solving" in the ordinary sense for differential equations but just trying to eliminate one variable from two equations.
You can just solve one equation and substitute into the other:
In [21]: eq1
Out[21]:
d
──(u(x)) = 0
dx
In [22]: eq2
Out[22]:
2
d d d
──(v(x)) = ──(u(x)) + ───(u(x))
dx dx 2
dx
In [23]: [udsol] = solve(eq1, u.diff(x))
In [24]: udsol
Out[24]: 0
In [26]: eq2.subs(u.diff(x), udsol)
Out[26]:
d d
──(v(x)) = ──(0)
dx dx
In [27]: eq2.subs(u.diff(x), udsol).doit()
Out[27]:
d
──(v(x)) = 0
dx
In general solve
is for algebraic rather than differential equations.
Upvotes: 1