# Phase Plane and Slope Field [![View on File Exchange](https://www.mathworks.com/matlabcentral/images/matlab-file-exchange.svg)](https://www.mathworks.com/matlabcentral/fileexchange/91705-phase-plane-and-slope-field-apps) or [![Open in MATLAB Online](https://www.mathworks.com/images/responsive/global/open-in-matlab-online.svg)](https://matlab.mathworks.com/open/github/v1?repo=MathWorks-Teaching-Resources/Phase-Plane-and-Slope-Field) You can use the Phase Plane and Slope Field apps to qualitatively analyze ordinary differential equations (ODEs).
Phase Plane app: Analyze two-dimensional autonomous ODE systems.Slope Field app: Analyze single variable ODEs.
These apps capture the functionality of the traditional PPlane and DField apps created by John C. Polking in MATLAB between 1995 and 2003 [[1]](#ref1). While similar in function to the original apps, the Slope Field and Phase Plane apps have been written entirely from scratch in MATLAB App Designer using modern MATLAB coding practices. This makes the new apps easier to maintain, edit, and use. ### Latest update: 1.1.0 * Updated field arrows with solid arrowheads. These fix the distortion that was visible when the axes were scaled differently. * Default field color is darker. Also, an option has been added to set a custom field color (in the Appearance menu). * The solver now allows complex solutions but only plots the real part. * Added options for the numerical estimation of separatrices. * Added options to export the field to a figure. ### Related content * Qualitative Analysis of ODEs: an accompanying set of live scripts that teach the basics of qualitative ODE analysis using these apps. ### Acknowledgements * Thank you to Roy Goodman at NJIT for his support of this project and many insightful suggestions. ## Setup ### MATLAB® 1. Ensure that you have MATLAB R2021a or newer installed. 2. Download and unzip the entire repository. 3. Double-click each app installer (SlopeField.mlappinstall and PhasePlane.mlappinstall) and follow the installation instructions. 4. Access the apps from the **APPS** tab in the MATLAB toolstrip. Use the dropdown to expand the menu. ### MATLAB Online™ 1. Download and unzip the entire repository. 2. Drag and drop the two app installers (SlopeField.mlappinstall and PhasePlane.mlappinstall) into the Current Folder in MATLAB Online. 3. Double-click each app installer (SlopeField.mlappinstall and PhasePlane.mlappinstall) and follow the installation instructions. 4. Access the apps from the **APPS** tab in the MATLAB toolstrip. Use the dropdown to expand the menu. ## Getting Started ### Tutorial Videos Learn the basics of the Phase Plane and Slope Field apps in these 3-minute tutorial videos. https://user-images.githubusercontent.com/81383420/134724074-25ac1212-2aa7-429b-b93d-550667641cf7.mp4 https://user-images.githubusercontent.com/81383420/134727298-5e0c2e62-4e4b-452d-9371-c61237e395e0.mp4 ### Quick Start Guides As an alternative to the videos, you can use these PDF quick start guides to get up and running quickly. [](https://github.com/MathWorks-Teaching-Resources/Phase-Plane-and-Slope-Field/files/6429294/PhasePlaneQuickStart.pdf)     [](https://github.com/MathWorks-Teaching-Resources/Phase-Plane-and-Slope-Field/files/6429351/SlopeFieldQuickStart.pdf) ## MathWorks Products Requires MATLAB release R2021a or newer ## License The license for the Phase Plane and Slope Field apps is available in the [LICENSE.md](LICENSE.md) file in this GitHub repository. ## Educator Resources ## * [Featured Courseware](https://www.mathworks.com/academia/courseware/course-materials.html) * [Teach with MATLAB and Simulink](https://www.mathworks.com/academia/educators.html) * [MATLAB Grader](https://www.mathworks.com/products/matlab-grader.html) Find an issue or need help? Email the MathWorks Online teaching team: onlineteaching@mathworks.com
## Full Capabilities: Phase Plane App The details of the Phase Plane app are documented here for reference. The Phase Plane app has four main areas you can interact with: Each of these areas is described below. ### Differential Equation System Panel ![differentialequationsystempanel](https://user-images.githubusercontent.com/81383420/117188975-a38ef500-adab-11eb-9e55-117c351d601e.png)
FunctionalityAction
Define an ODE system Type the two dependent variable names in the first two fields and the ODE expressions in terms of the dependent variables and any parameters you defined.
Define a parameter Type the name of the parameter in the first field. Type the value in the second field. You can use a valid MATLAB expression, such as log(2), but you cannot use other parameters or variables.
Update the phase plane field with the edited ODE system Click Update
Clear the differential equation system and parameter fields Click Clear
Use the default ODE system Click Default
### Phase Plane Panel ![phaseplanepanel](https://user-images.githubusercontent.com/81383420/117188869-8823ea00-adab-11eb-8d1e-42fef2ca1f73.png)
FunctionalityAction
Generate a solution Click the phase plane
Delete a solution Right-click a solution curve
Highlight a solution Left-click a solution curve
Remove highlighting Left- or right-click a highlighted curve
Solve from a numerically defined initial condition Set the initial values in the x0 and y0 edit fields. Then press Solve from (x0,y0).
Clear solution curves Click Clear solutions
Show the analysis for an equilibrium point Click an equilibrium point (equilibria are generated from the Analysis menu)
### Appearance Tab ![appearancetabpp](https://user-images.githubusercontent.com/81383420/117189258-fb2d6080-adab-11eb-92b0-58e8ad5b72c5.png)
FunctionalityAction
Change the phase plane horizontal axis limits Type values of xmin and xmax
Change the phase plane vertical axis limits Type values of ymin and ymax
Change the time series horizontal axis limits Type values of tmin and tmax
Speed up or slow down the animation Move the Animation speed slider
Toggle the time series plots Click the Time series checkbox
Increase or decrease the widths of solution curves Use the spinner or type a new value for Line width
Increase or decrease the number of field arrows Use the spinner or type a new value for Field density
Increase or decrease the size of the field arrows Use the spinner or type a new value for Field scale
### Solution Tab ![solutiontabpp](https://user-images.githubusercontent.com/81383420/117189293-07192280-adac-11eb-8232-1d95d3b91e87.png)
FunctionalityAction
Change the solver time span. The ODE solver will start at t=0 and solve both forward and backward in time based on the defined values. Edit the Forward solution tmax and Backward solution tmin fields.
Allow the solver to continue beyond the axis limits Uncheck Terminate solutions at axis limits
Change how many solutions are generated when the Solve from region functionality is used Adjust the Solve from region density slider
### Solver Tab ![solvertabpp](https://user-images.githubusercontent.com/81383420/117189312-0ed8c700-adac-11eb-8221-b7aaf5d3e0cb.png)
FunctionalityAction
Change the variable step ODE solver Select a solver from the Solver dropdown
Change the ODE solver relative tolerance Enter a new value in the Relative tolerance field
Change the ODE solver absolute tolerance Enter a new value in the Absolute tolerance field
The ODE solver automatically terminates if it runs for too long (in real time). You can adjust how long the solver will run. Type a new value for Max solver wall clock (s)
Use a fixed step solver Press the Fixed step button
Use a different fixed step solver. Note that implicit methods use a Newton iteration at each step and, as a result, solve slowly. Select a solver from Solver dropdown
Use a different step in the numerical integration Type a new value for Step size
### Analysis Menu ![analysismenupp](https://user-images.githubusercontent.com/81383420/117189337-17c99880-adac-11eb-8545-3f6f01a5ea2d.png)
FunctionalityAction
Numerically solve for an equilibrium of the system. Equilibria occur where x'(t)=0 and y'(t)=0. This function uses the Newton-Raphson method with a finite-difference Jacobian to solve for zeros of the differential equation system. Select Find nearby equilibrium. Then, click the phase plane near the suspected equilibrium point.
Find equilibria in the phase plane. This method scans the plane using a grid of initial guesses and records all equilibria found. The Newton-Raphson method is used to solve for zeros of the differential equation system. Select Scan for equilibria
Clear the equilibria Select Clear equilibria
Solve for saddle separatrices. Saddle separatrices are numerically estimated by generating a solution an increment away from each saddle equilibrium in the directions of the eigenvectors. Before solving for saddle separatrices, you should scan for equilibria. Select Solve for saddle separatrices
Clear the separatrices Select Clear separatrices
Show nullclines or hide nullclines. Nullclines are curves along which x'(t) = 0 or y'(t) = 0. Nullclines with x'(t) = 0 are blue and those with y'(t) = 0 red. Intersections of the nullclines are equilibria since x'(t) and y'(t) are both zero. Select Show nullclines
Automatically generate isoclines. Isoclines are curves along which the phase plane field directions are constant: y'(t)/x'(t) = m. Select Auto-generate isoclines. Then, enter an integer for how many isoclines you want to generate.
Draw an isocline curve through a point. Select Draw isocline through a point. Then, click the phase plane.
Draw isoclines with specified values. Select Draw several isoclines. Then, type a list of slope values. For example: -1 3 5
Clear the isoclines Select Clear isoclines
### Solve and Draw Menus ![solvemenupp](https://user-images.githubusercontent.com/81383420/117189390-2748e180-adac-11eb-91bf-d51f65471378.png)
FunctionalityAction
Generate several solutions starting within a region Select Solve > Solve from region. Then, click once on the phase plane to start drawing, draw your region, and click again to stop drawing.
Draw a solution on the phase plane Select Draw > Draw solution. Then, click once on the phase plane to start drawing, draw your solution, and click again to stop drawing.
Draw a solution on the phase plane and compare it to the numerical solution Select Draw > Draw and compare solution. Then, click once on the phase plane to start drawing, draw your solution, and click again to stop drawing.
### Appearance Menu ![appearancemenupp](https://user-images.githubusercontent.com/81383420/117189426-2fa11c80-adac-11eb-91bb-1d07a9f0a1ab.png)
FunctionalityAction
Toggle solution animations Select Animate solution
Toggle initial value labels Select Point labels
Toggle the location of the axes Select Axis through origin
Toggle dark mode Select Dark mode
Toggle between showing the field arrows with magnitude and orientation and orientation only Select Field orientation only
### Library and Custom Library Menus ![librarymenupp](https://user-images.githubusercontent.com/81383420/117189453-3760c100-adac-11eb-8f52-4fbbd0ee3564.png)
FunctionalityAction
Set the differential equation to a standard systemSelect one of the systems from the Library menu
Add the current system to the Custom library tabSelect Custom library > Add current system
Save the current custom library to a MAT fileSelect Custom library > Save
Load a custom library MAT file (note: the custom library should be one created by the Phase Plane app)Select Custom library > Load
Clear the current custom librarySelect Custom library > Clear
### Export Graphics Menu ![exportgraphicsmenupp](https://user-images.githubusercontent.com/81383420/117189476-4182bf80-adac-11eb-94eb-cc998e46d022.png)
FunctionalityAction
Export the phase plane portrait and time series to an image file. This method includes the equations in the exported image. Select Export to PNG
Export the phase plane portrait and time series to a scalable vector graphics file (this format is useful for editing or high resolution website display). This method includes the equations in the exported image. Select Export to SVG
Export the phase plane portrait and time series to a PDF. This method includes the equations in the exported image. Select Export to PDF
Export the phase plane portrait to an image file Select Export portrait only to PNG
Export the phase plane portrait to a scalable vector graphics file Select Export portrait only to SVG
Export the phase plane portrait to a PDF Select Export portrait only to PDF
## Full Capabilities: Slope Field App The details of the Slope Field app are documented here for reference. The Slope Field app has four main areas you can interact with: Each of these areas is described below. ### Differential Equation Panel ![differentialequationpanel](https://user-images.githubusercontent.com/81383420/117189545-552e2600-adac-11eb-9ed0-24d5d20731d2.png)
FunctionalityAction
Define an ODE Type the dependent variable name and the ODE expression in terms of the dependent variable and the independent variable t.
Define a parameter Type the name of the parameter in the first field. Type the value in the second field. You can use a valid MATLAB expression, such as log(2), but you cannot use other parameters or variables.
Update the slope field with a new equation Click Update
Clear the differential equation and parameters Click Clear
Use the default ODE Click Default
### Slope Field Panel ![slopefieldpanel](https://user-images.githubusercontent.com/81383420/117189594-61b27e80-adac-11eb-9364-3c7f50701006.png)
FunctionalityAction
Generate a solution Click the slope field
Delete a solution Right-click a solution curve
Highlight a solution Left-click a solution curve
Remove highlighting Left- or right-click a highlighted curve
Solve from a numerically defined initial condition Set the initial values in the t0 and x0 edit fields. Then press Solve from (t0,x0).
Clear solution curves Click Clear solutions
### Appearance Tab ![appearancemenu](https://user-images.githubusercontent.com/81383420/117189628-69722300-adac-11eb-9e00-4304143de79e.png)
FunctionalityAction
Change the horizontal axis limits Type values of tmin and tmax
Change the vertical axis limits Type values of xmin and xmax
Speed up or slow down the animation Move the Animation speed slider
Increase or decrease the widths of solution curves Use the spinner or type a new value for Line width
Increase or decrease the number of slope field arrows Use the spinner or type a new value for Field density
Increase or decrease the size of the slope field arrows Use the spinner or type a new value for Field scale
### Solution Tab ![solutiontab](https://user-images.githubusercontent.com/81383420/117189697-7c84f300-adac-11eb-9e96-890b12634c37.png)
FunctionalityAction
Allow solver to continue beyond axis limits Uncheck Terminate solutions at axis limits
Change how many solutions are generated when the Solve from region functionality is used Adjust the Solve from region density slider
### Solver Tab ![solvertab](https://user-images.githubusercontent.com/81383420/117189722-81e23d80-adac-11eb-958e-01640aebd1fd.png)
FunctionalityAction
Change the variable step ode solver Select a solver from the Solver dropdown
Change the ODE solver relative tolerance Enter a new value in the Relative tolerance field
Change the ODE solver absolute tolerance Enter a new value in the Absolute tolerance field
The ODE solver automatically terminates if it runs for too long (in real time). You can adjust how long the solver will run. Type a new value for Max solver wall clock (s)
Use a fixed step solver Press the Fixed step button
Use a different fixed step solver. Note that implicit methods use a Newton iteration at each step and, as a result, solve slowly. Select a solver from the Solver dropdown
Use a different step in the numerical integration Type a new value for Step size
### Analysis Menu ![analysisdropdown](https://user-images.githubusercontent.com/81383420/117189767-8eff2c80-adac-11eb-8067-716e1adeb893.png)
FunctionalityAction
Show nullclines or hide nullclines. Nullclines are curves along which x'(t) = 0. Select Show nullclines
Automatically generate isoclines. Isoclines are curves along which the derivative is constant: x'(t) = m. Select Auto-generate isoclines. Then, enter an integer for how many isoclines you wish to generate.
Draw an isocline curve through a point. Select Draw isocline through a point. Then, click the slope field.
Draw isoclines with specified slope values. Select Draw several isoclines. Then, type a list of slope values. For example: -1 3 5
Clear the isoclines Select Clear isoclines
### Solve and Draw Menus ![solvemenu](https://user-images.githubusercontent.com/81383420/117189824-a0483900-adac-11eb-9267-2500f933bfb1.png)
FunctionalityAction
Generate several solutions starting within a region Select Solve > Solve from region. Then, click once on the slope field to start drawing, draw your region, and click again to stop drawing.
Draw a solution on the slope field Select Draw > Draw solution. Then, click once on the slope field to start drawing, draw your solution, and click again to stop drawing.
Draw a solution on the slope field and compare it to the numerical solution Select Draw > Draw and compare solution. Then, click once on the slope field to start drawing, draw your solution, and click again to stop drawing.
### Appearance Menu ![appearancemenu](https://user-images.githubusercontent.com/81383420/117189868-accc9180-adac-11eb-89d9-2c46895a8461.png)
FunctionalityAction
Toggle solution animations Select Animate solution
Toggle initial value labels Select Point labels
Toggle the location of the axes Select Axis through origin
Toggle dark mode Select Dark mode
Toggle between showing the field arrows with magnitude and orientation and orientation only Select Field orientation only
### Library and Custom Library Menus ![librarymenu](https://user-images.githubusercontent.com/81383420/117189899-b524cc80-adac-11eb-9c57-111b6ec4b6b0.png)
FunctionalityAction
Set the differential equation to a standard systemSelect one of the systems from the Library menu
Add the current system to the Custom library tabSelect Custom library > Add current system
Save the current custom library to a MAT fileSelect Custom library > Save
Load a custom library MAT file (note: the custom library should be one created by the Slope Field app)Select Custom library > Load
Clear the current custom librarySelect Custom library > Clear
### Export Graphics Menu ![exportgraphicsmenu](https://user-images.githubusercontent.com/81383420/117189911-bc4bda80-adac-11eb-92f7-9a689de6d810.png)
FunctionalityAction
Export the Slope Field to an image fileSelect Export to PNG
Export the Slope Field to a scalable vector graphics file (this format is useful for editing or high resolution website display)Select Export to SVG
Export the Slope Field to a PDFSelect Export to PDF
## References [1] John C. Polking. DField and PPlane [Computer software]. (1995-2003). Available online: https://math.rice.edu/~polking/odesoft/dfpp.html
Copyright 2021 The MathWorks, Inc.