Partial Differential Equations

PDEs can be also solved with the sympy module and the pdsolve function.

Here is how this can be done, step by step to solve the PDE 1 + (2(ux/u)) + (3(uy/u)):

  1. Import sympy

     from sympy.solvers.pde import pdsolve
     from sympy import Function, Eq
    
  2. Create symbols

    We need to tell sympy that the letters x and y represents a symbol whilst f is a function..

     from sympy.abc import x, y
     f = Function('f')
    
  3. Calculate derivatives and define equation

     u = f(x, y)
     ux = u.diff(x)
     uy = u.diff(y)
    
     eq = Eq(1 + (2*(ux/u)) + (3*(uy/u)), 0)
    
  4. Solve the PDE.

     pdsolve(eq)