Ruben Agapito Ruiz
Math 2?
Summer Session II, 2003

Ordinary Differential Equations

Problem 2

We are gonna learn some Mathematica commands: (Mathematica commands always start with a capital letter. In other words, Mathematica is case sensitive.)

Plot[(x^2), {x, -2, 7}, PlotRange -> {-10, 10}, 
      AxesLabel -> {"x", "y"}]

How to get more information about a Mathematica command:

?Plot

but now how to get even more information about a command:

?? Plot

Plot3D[Sin[x y], {x, -5, 5}, {y, -5, 5}, PlotPoints -> 40]

ODE commands

Example 1

To solve the first-order differential equation (dy/dx) = x + y, we simply type

DSolve[y'[x] == x + y[x], y[x], x]

Let's get more information about DSolve

?? DSolve

Example 2

\(g = \(#1\^2\) #2 + 3  #1&; 
    \ \ \  (*\ this\ is\ a\ pure\ function, \ this\ is\ a\ comment\ \ *) 

    g[3, 4]\)

To obtain the solution of (dy/dx) = x + y as a pure function, we enter

solution = DSolve[y'[x] == x + y[x], y, x]

If we want to evaluate the solution , we can type

y[x] /. solution

Using pure functions you can evaluate derivatives of the solution:

y'[x] /. solution

Example 3. ODE with initial conditions

Solve the ODE (dy/dx) = x + y with the initial condition y(0) = 2. Then plot the solution

equation = DSolve[{y'[x] == x + y[x], y[0] == 2}, y[x], x]

Plot[y[x] /. equation, {x, -5, 2}]

Example 4. How to plot Vector Fields

Plot the vector field F(x, y)=-y i+x j. By default, no axes are drawn so the option Axes->Automatic will be used.

<< Graphics`PlotField`      PlotVectorField[{-y, x}, {x, -5, 5}, {y, -5, 5}, 
      Axes -> Automatic]

some example

a common mistake in Mathematica. Use commands without invoking packages. For example

ImplicitPlot[(x^2) + (y^2) == 1, {x, -1, 1}]

So we invoke the package:

<< Graphics`ImplicitPlot`

So in order to graph the equation we need to remove the variable we created