I have decided to start working on my project, even though it is a week early, since I am finished with school and have nothing better to do. I also like the idea of getting ahead. I am pushing everything to my github account. So far, I have implemented exact differential equations, which are cake (i.e., they took me about an hour to code up). These are equations of the type,where. If this condition holds, then there exists a function, often called a ‘potential function’ because of some applications of theses equations to physics, such thatand. This is because mixed partials are equal for continuous functions. The solution will then just be. The tricky part is finding the potential function, but it turns out to be easier than you would think. Because of the fundamental theorem of calculus, the potential function is just. There is a restriction where the rectangle connecting,,, andhas to lie entirely in the domain of and, but if we let, then this is not really a problem for functions that SymPy will encounter. UPDATE: It turns out this is a problem if the equation has singularities in it. Fortunately, I was able to code up a workaround that usually works.
So you can see that this is easy to implement in SymPy if you know the above fact. It turns out that most solution methods for ODEs are like this. They can be solved in the general case, although usually students are only taught tricks because they are much easier to remember than generally solved formulas. For example, to solve an exact differential equation, students are often taught to just integratewith respect toandwith respect to. It is much simpler for a human being to do that than the above integral, because the integral involves evaluating limits and so on, but for a computer algebra system, the above integral is a one-liner.
By the way, if you want to test my code, you should clone my github repository and switch to the odes branch. You can do this by typing ‘git clone git://github.com/asmeurer/sympy.git’ and then ‘git checkout odes’ in a Terminal that is cd’d to the directory you want to clone to (of course, you will need git installed first!). Then type ‘cd sympy’ and ‘./bin/isympy’, which will start SymPy. Then from there, you can do stuff like ‘dsolve(sin(x)*cos(f(x))+cos(x)*sin(f(x))*f(x).diff(x),f(x)’ (this is exact). It’s easy to generate an exact differential equation. Just start with a random function of x and y, then take the derivative of it with respect to x and y each, and do a subs(y,f(x)) on each term (SymPy wants functions for the dependent variable, so we have to use f(x)). Then do dsolve(<the derivative with respect to x>+<the derivative with respect to y>*f(x).diff(x),f(x)). You should get your original function equals an arbitrary constant C1. By the way, diff(<function>,x) will take the derivative of <function> with respect to x.
Up next: Initial conditions, and then first order homogeneous differential equations.