Since matlab has no natural capability to plot phase portraits for ODEs, it forces users either to write its own code for their visuallizations or a use a special subroutine. The latter was realized by John C. Polking from Rice University, who developed between 1995 and 2003 very friendly subroutines dfield and pplane. Unfortunately, these apps are not compatible with lastest versions of matlab.
To capture the functionality of the traditional PPlane and DField apps,
Iourii Kouznetsov (2020) published an updated version
dfield9(action,input1,input2,input3) (https://www.mathworks.com/matlabcentral/fileexchange/65886-dfield9-action-input1-input2-input3), matlab Central File Exchange.
Start matlab and set the working directory to be the folder into which you downloaded the program. To start dfield simply type dfield9 in the matlab command window. Linux users should enter:
addpath(tempdir)
dfield9
Similar to dfield9, there is also dirfield subroutine for plotting phase portraits of first order ODEs.
function dirfield(f,tval,yval)
% dirfield(f, t1:dt:t2, y1:dy:y2)
%
% plot direction field for first order ODE y' = f(t,y)
% using t-values from t1 to t2 with spacing of dt
% using y-values from y1 to t2 with spacing of dy
%
% f is an @ function, or an inline function,
% or the name of an m-file with quotes.
%
% Example: y' = -y^2 + t
% Show direction field for t in [-1,3], y in [-2,2], use
% spacing of .2 for both t and y:
%
% f = @(t,y) -y^2+t
% dirfield(f, -1:.2:3, -2:.2:2)
[tm,ym]=meshgrid(tval,yval);
dt = tval(2) - tval(1);
dy = yval(2) - yval(1);
fv = vectorize(f);
if isa(f,'function_handle')
fv = eval(fv);
end
yp=feval(fv,tm,ym);
s = 1./max(1/dt,abs(yp)./dy)*0.35;
h = ishold;
quiver(tval,yval,s,s.*yp,0,'.r'); hold on;
quiver(tval,yval,-s,-s.*yp,0,'.r');
if h
hold on
else
hold off
end
axis([tval(1)-dt/2,tval(end)+dt/2,yval(1)-dy/2,yval(end)+dy/2])
Historical Note about John Polking:
This is what professor John Polking wrote about himself.
I was born and raised on a farm near the town of Breda in western Iowa. He went to Notre Dame, and then spent three years in the US Navy.
During graduate school at the University of Chicago, I spent some time consulting in industry. I received my PhD in 1966 for a thesis on partial differential equations. My current mathematical interests include partial differential equations and several complex variables.
After two years as an instructor at Brandeis, I came to Rice in 1968. With the exception of a year at the Courant Institute, another at the Institute for Advanced Study, and three years at the National Science Foundation, I have been at Rice since.
Although I retired in June 2004, I retain the rank of Professor Emeritus. I teach one course each spring at Rice. I am also an active member of the Steering Committee for the IAS/Park City Mathematics Institute (PCMI) for whom I edit the Graduate Summer School Lecture Series.
I am also rewriting my textbooks in ordinary differential equaitons, and my computer software for use in differential equations courses.
﹡ ⁎ ✱ ✲ ✳ ✺ ✻ ✼
✽ ❋
An updated version of Pplane that works on matlab R2018b was prepared by Hugh Harvey. See https://www.mathworks.com/matlabcentral/fileexchange/61636-pplane.
pplane9 is available in a matlab version.
The latest version of phase portrait plotting with matlab was developed by Brian Hong (2021). Phase Plane and Slope Field apps (https://github.com/MathWorks-Teaching-Resources/Phase-Plane-and-Slope-Field/releases/tag/v1.0.0), GitHub.
Tutorial videos that demonstrate how to use the apps are available at the GitHub repository:
https://github.com/MathWorks-Teaching-Resources/Phase-Plane-and-Slope-Field
We show its application on the following problem:
\[
y' = 3y+2x .
\]
When dfield starts it displays the default Setup window
Example:
**DESCRIPTION OF PROBLEM GOES HERE**
This is a description for some MATLAB code. MATLAB is an extremely useful tool for many different areas in engineering, applied mathematics, computer science, biology, chemistry, and so much more. It is quite amazing at handling matrices, but has lots of competition with other programs such as Mathematica and Maple. Here is a code snippet plotting two lines (
y vs. x and
z vs. x) on the same graph. Click to view the code!
figure(1)
plot(x, y, 'Color', [1 0 0]) %blue line
hold on
plot(x, z, 'Color', [0 1 0]) %green line