Math 331.1 •  Fall 2005

First-order ODEs with Mathematica

Copyright © 2005 Murray Eisenberg.  All rights reserved.

Finding exact solutions analytically

You already learned how to use DSolve to find exact solutions of a first-order ODE or of an initial value problem for such an ODE.  Here again are examples.

DSolve[y'[t]  ==  y[t] (1  -  y[t]),  y[t],  t]

DSolve[{y'[t]  ==  y[t] (1  -  y[t]),  
        y[0]  ==  -2},  y[t],  t]

The result of a DSolve expression, like that of a Solve expression, is a replacement rule and not the solution function itself.  If you want to use the solution subsequently, it's a good idea to assign the result of the DSolve expression a name.  For example:

soln  =  
      DSolve[{y'[t]  ==  y[t] (1  -  y[t]),  
          y[0]  ==  -2},  y[t],  t]

It's usually also a good idea to strip off the outside list braces:

soln  =  
      First[ DSolve[{y'[t]  ==  y[t] (1  -  y[t]),  
            y[0]  ==  -2},  y[t],  t] ]

Now you can use the result, although sometimes with a bit of extra work:

y[t]  /.  soln

Try this:  Without retyping or copying the entire expression ((2 (E^t))/(-3 + 2 (E^t))) for the solution, plot its graph.

A value of the alleged solution can be obtained like this, using an additional replacement rule:

y[t]  /.  soln  /.  t  ->  3

Try this:  Type and evaluate an expression to check that Mathematica's alleged solution satisfies the initial condition.

If you want to check that Mathematica's answer is correct, you might expect to be able to do something like this:

y'[t]  /.  soln

Unfortunately,as you see, that does not work as expected!  One work-around is to use the D form for taking derivatives instead of the form using a prime (')

D[y[t]  /.  soln,  t]

If you don't want to keep typing the /. soln part, then you could introduce a new name:

yoft  =  y[t]  /.  soln

Try this:  Type and evaluate a single expression to check that Mathematica's alleged solution really does satisfy the ODE.  (Hints:  You will probably want to use Simplify.)

Approximating solutions numerically

See the notebook EulerMethod.nb.

When you open that notebook, you will get a pop-up dialog box asking if you want to evaluate all the "initialization cells" in the notebook.  Click the Yes button.

After going through the examples in the notebook, try another example or two yourself.

Understanding solutions qualitatively

See the notebook SlopeField.nb.

When you open that notebook, you will get a pop-up dialog box asking if you want to evaluate all the "initialization cells" in the notebook.  Click the Yes button.

After going through the examples in the notebook, try another example or two yourself.

What's next?

If you have time, go to the notebook VectorFields.nb.