So here is what I have done. Homogeneous has several meanings, but when I use it in this post, I will mean homogeneous functions. We only care about functions of two variables, so I will also only talk about them. A function is called homogeneous of order if for some . Also, if we “pull” an out, we get , which is why the definition is often stated that the function can be written as a function of . Of course, we could do the same with and get a function of . Here is an example of a homogeneous function: . You can see that .

Now, if the coefficients and in the first order differential equation are both homogeneous functions of the same order, then the substitution or will make the equation separable. I will show how to do it for . We have by the product rule. We also have and . Because these functions are homogeneous, we can “pull out” an from each, giving us . Because we made the substitution , we already have had to assume . Thus, we can divide the whole thing by . Doing this, and expanding the remaining terms, we get . Refactoring the and terms, we get . The equation is separable! Separating variables and integrating, we get . If we had used instead, we would have gotten . This is exactly how I was able to solve these equations in SymPy. Each homogeneous equation has two possible integrals, and often the right hand side of one equation is a much harder integral than the right hand side of the other. Therefore, I did them both, and applied a little heuristic on which one to return. It prefers expressions that can be solved for y (f(x) in the case of SymPy), expressions that have evaluated integrals, and if neither of them are solvable, the shortest one, which tends to be the simplest.

Here is an example from my text book. . Astute readers of this blog may have noticed that this equation is exact. It is easier to solve that way, but we will try using the methods outlined above. First, we notice that the coeficients of and are both homogeneous of order 2, so we can make the substitution or and the equation would become seperable. If I were doing this by hand or for a homework assignment, I would make one of those substitutions and work it through, but we have the exact form above, so let’s use it just like SymPy would. and . So we get with and with (here and for the remainder of this derivation, the arbitrary constants in the two equations do not necessarily equal each other until the last step). Both integrals can be solved with a substitution of the denominator, giving, with back substituted, and . If we make , and pull the constants in front of the logs on the right hand sides in as powers, we can combine everything into logarithms. After doing that, we then take the antilog of both sides and get and . We then raise the whole equation to the power and make . We get

and

,

where

Verify as an exercise that you get the same solution by the exact differential equation methods (or don’t… you know, depending on which you’d rather do).

Of course, if that was all there was to it, I would have finished in a day. There was more. First, I had to write a function that determines if an expression is homogeneous and what order if it is. That was about 150 lines of code right there plus tests (150 lines is a lot in Python).

I also wanted it to recognize that is homogeneous because . SymPy was incapable of combining logarithms like this, so I had to write a logcombine function, which was another 100 lines of code plus tests. This came in handy, because I was also able to use it in the part above where I combined the logarithms of my answer to eliminate all of them.

Lastly, you may have noticed that my math looks much nicer in this post. It turns out that WordPress supports math using $ Read the rest of this entry »

### Like this:

Like Loading...