Go to CCP 
Homepage Go to Materials Page Go to Engineering Mathematics Materials Go to Table of Contents
Go Back One Page Go Forward One Page

MATLAB Tutor

Part 13: Direction fields

  1. MATLAB does not have a built-in command to plot direction fields. An m-file that provides a function for this purpose called "slpfield" is provided for every module that needs direction fields.

    If you downloaded the package of m-files in Part 11 of this tutorial, this function is available to you, provided the file slpfield.m is in your working directory or on MATLAB's path. If you have not yet downloaded the package, go back to Part 11 and do it now.


  2. In order to make the plot of the direction field, the "slpfield" function must be provided a function called "dfun" which gives the right hand side of the differential equation.

    Use a text editor to edit the file dfun.m (provided in the same package as slpfield.m) so that the right-hand-side function is y.*(1-y). (The period after the y is important.)


  3. Assuming you have the correct dfun.m file, we can now plot the vector field on the interval -2 < t < 2 and -0.5 < y < 2. Enter:

    slpfield(-2, 2, -0.5, 2)
    hold on     %holds the plot



  4. Now plot the function h from Part 12 on top of the slope field plot. We use the same limits on t. Enter:

    ezplot( h, [-2,2] )
    axis( [-2, 2, -0.5, 2] )


    Does this solution look like it fits the direction field?


  5. Adjust the horizontal ranges and redraw the direction field and the solution plot so that you can see the solution function h approach equilibrium. If necessary, enlarge the picture so you can see more detail. Are you convinced that the symbolic solution h fits the direction field?


  6. Edit the dfun.m file in order to generate direction fields over appropriate ranges of the variables for the following differential equations:

    • dy/dt = y2

    • dy/dt = ty + t


Go to CCP Homepage Go to Materials Page Go to Engineering Mathematics Materials Go to Table of Contents
Go Back One Page Go Forward One Page


modules at math.duke.edu Copyright CCP and the author(s), 1998, 1999, 2000