You are on page 1of 4

Separation of variables with Mathematica

Solve the equation


dy

dx

= -xI1 + y2 M
1

with initial conditions y(2)=1. This is separable with gHxL = -x and hHyL = 1+y
2 .
Start by defining Mathematica functions for g and h. Note the underscores; they matter.
g@x_D = -x
-x
h@y_D = 1 H1 + y ^ 2L
1

2
y +1

Define variables for use when we set the initial conditions.


x0 = 2
2
y0 = 1
1

Doing the integrals


G@x_D = Integrate@g@xD, xD
x2
-
2
H@y_D = Integrate@h@yD, yD
tan-1 HyL

Solving the algebraic equation


Solve for y as a function of x. Note the addition of the constant
of integration.
algSoln@x_, C_D = Solve@H@yD G@xD + C, yD
ij 1
yz
::y tanjjj I2 C - x2 Mzzz>>
k2
{

Use the result of the algebraic solution to define a function (a one-parameter family depending on C, actually)
representing the solution of the ODE.

sepVar.nb

odeSoln@x_, C_D = y . algSoln@xD@@1DD


ij 1
yz
tanjjj I2 C - x2 Mzzz
k2
{

Solving for C
Plug the initial conditions into the ODE solution and solve for C.
cSoln = Solve@odeSoln@x0, CD y0, CD

Solve::ifun :
Inverse functions are being used by Solve, so some solutions may not be found;
use Reduce for complete solution information.

::C 2 + >>
4

Lets return to the issue of the scary warning message later. For now, forge boldly ahead, substituting C=2+ 4
into the ODE solution.
ivpSoln@x_D = odeSoln@xD . cSoln@@1DD
y
ij 1 i i
yyz
tanjjj jj2 jj2 + zz - x2 zzzzz
{{
4{
k2 k k

Heres what the solution looks like


Plot@ivpSoln@xD, 8x, 2, 6<D
6
4
2

-2

-4

-6

The solution blows up just below x=3. (You should calculate exactly where!) Ive continued the graph after that
point to highlight the singularity, but the behavior of the solution to the IVP is undefined once it "blows
up."

Checking the solution


You can use Mathematica to simplify checking the solution. Plug in, and let Mathematica do the calculus and
algebra:
LHS = D@ivpSoln@xD, xD
y
ij 1 i i
yyz
-x sec2 jjj jj2 jj2 + zz - x2 zzzzz
{{
4{
k2 k k

sepVar.nb

RHS = -x H1 + ivpSoln@xD ^ 2L
y
ij
ij 1 i i
yz
yyz
-x jjjtan2 jjj jj2 jj2 + zz - x2 zzzzz + 1zzz
{{
4{
k
k2 k k
{
RHS LHS
y
y
ij
ij 1 i i
yz
ij 1 i i
yyz
yyz
-x jjjtan2 jjj jj2 jj2 + zz - x2 zzzzz + 1zzz -x sec2 jjj jj2 jj2 + zz - x2 zzzzz
k
k
{
{
k
k
{
{{
4
4
k
k2
{
{
k2

If you remember your trig identities, youll see that these are equal. When looking at complicated expressions,
the FullSimplify[ ] function is amazingly useful...
FullSimplify@RHS LHSD
True

...so the IVP solution is indeed a solution of the ODE. Now check that the IVP solution satisfies the IC:
ivpSoln@x0D y0
True

...so our solution passes both the ODE check and the IC check. All done! Well, not quite.

About that warning message


OK, why the scary warning message??? Its because the algebraic equation being solved is
odeSoln@x0, CD y0
ij 1
yz
tanjjj H2 C - 4Lzzz 1
k2
{

which we can clean up a little with our friend FullSimplify[ ]


FullSimplify@odeSoln@x0, CD y0D
tanH2 - CL + 1 0

which has multiple solutions because the tangent function is periodic (with period ).The solution C = 4 + 2 is

the principal value, but there are infinitely many other solutions obtained by adding to 4 + 2 any integer multiple of .
Taking into account the multiple solutions to the algebraic equation, the IVP solution is actually
-Tan@x ^ 2 2 - 2 - Pi 4 + n PiD
2

ji x
zy
tanjjjj- - n + + 2zzzz
2
4
k
{

where n is an integer. However, the tangent function is periodic with period , so the addition of an n phase
shift does not matter.
Thus the scary warning about inverse function was a false alarm. This will usually be the case for problems of
this sort, because well be inverting a function to get C, and then putting the value of C right back into the
function. You do things like this all the time in hand calculations, but dont always think about whats happening.

Heres the plot of the solution where weve used C = 143 + 2 + 4 instead of C = 2 + 4 . As expected, it is
identical to the solution with the principal value of C.

where n is an integer. However, the tangent function is periodic with period , so the addition of an n phase
shift does not matter.
4 sepVar.nb
Thus the scary warning about inverse function was a false alarm. This will usually be the case for problems of
this sort, because well be inverting a function to get C, and then putting the value of C right back into the
function. You do things like this all the time in hand calculations, but dont always think about whats happening.

Heres the plot of the solution where weve used C = 143 + 2 + 4 instead of C = 2 + 4 . As expected, it is
identical to the solution with the principal value of C.
Plot@-Tan@x ^ 2 2 - Pi 4 - 2 + 143 PiD, 8x, 2, 6<D
6
4
2

3
-2

-4

-6

OK, now were all done.

You might also like