# Solving general PDE’s in SymPy

Hello, I have decided to start my official work for my GSoC project. This post would be slightly TL;DR , so please bear with me.

1. The first step was to wrap up the work on my previous PR, I had added a hint such that SymPy can now solve general partial differential equations with constant coefficients.  The mentioned Partial Differential Equation is of the form $\frac{\partial f}{\partial x} + b*\frac{\partial f}{\partial y} + c*f =G(x,y)$ where $f$ is a function of $x$ and $y$ and $G$ can be any arbitrary function in $x$ and $y$.

The implementation is discussed as follows, it can be separated into a general part and homogeneous part. The homogeneous part of course is  $a*\frac{\partial f}{\partial x} + b*\frac{\partial f}{\partial y} + c*f$and the general part is when you add the function $G(x,y)$ and the solution would be when you add the general part and homogeneous part.

So how does one solve the homogeneous part. It beats me too. I had referred this book “Partial Differential Equations by Viktor Grigoryan” and this is what he says in the book.  Before I go into the details of the implementation, it is important to review a few concepts that I had studied in my Math-1 Course in college.

a] Directional Derivatives –  All of us know that a derivative is the rate of change of  a function. $\frac{\partial f}{\partial x}$ is the rate of change in the x direction, similarly $\frac{\partial f}{\partial y}$  is the rate of change in the y direction. Suppose one wants to find the rate of change in an arbitrary direction say , this is the way to proceed. We find the dot product between the unit vector which gives the direction , and the gradient of the function, which would give the rate of change of function in the direction $\frac{v}{|v|}.(\frac{\partial f}{\partial x}\hat{i} + \frac{\partial f}{\partial y}\hat{j})$ . The reasoning behind it? Well I’ll leave it to someday else.

Solving the homogeneous part : Now take the Partial Differential Equation $a*\frac{\partial f}{\partial x} + b*\frac{\partial f}{\partial y} + c*f$ . Our goal is to convert it this PDE in two variables into an ordinary differential equation, the first additive part can be written as directional derivative of $f$ in the direction of $a\hat{i} + b\hat{j}$ . It can be also seen the third part $c*f(x,y)$ is independent of the derivative term. Just ignoring the third term for a moment, the first part becomes zero, which tells us that it would be convenient to change the co-ordinates from the $x$ and $y$ to a system parallel to $a\hat{i} + b\hat{j}$ and perpendicular to it. So we make the following substitutions

$\xi=a*x+by$ and $\eta=b*x-a*y$ and yay the homogeneous PDE reduces to, $(a^{2} + b^{2})*\frac{\partial u}{\partial \xi} + u=0$ . Do the substitutions yourself. It isn’t that difficult, and the ODE is variable separable and the solution is given by $e^{-c/(a^{2} + b^{2})*(a*x + b*y)}*f(b*x - a*y)$ . This solves the homogeneous part of the Partial Differential Equation

Solving the general part : The general Partial Differential Equation reduces to the form $\frac{\partial u}{\partial \xi} +\frac{c*u}{a^{2} + b^{2}}= \frac{G(\xi , \eta)}{a^{2} + b^{2}}$ , which is a linear differential equation. The solution is given by,  $e^{-c/(a^{2} + b^{2})*(a*x + b*y)}*\int\frac{e^\frac{c*\xi}{a^{2} + b^{2}}*G(\xi , \eta)}{a^{2} + b^{2}}\,d\xi$.

The corresponding source code can be found here, for those who are interested https://github.com/sympy/sympy/pull/2109

I’ve also finished work on implementing the first heuristic, however I did not want to squeeze it here, as the post is already going too big, I have to admit that the code was completely straightforward and formatting this post was a tougher task. So till next time.

P.S : Going through emotional lows now which I wouldn’t want to mention here , just hoping tomorrow is better than today.