cBook‎ > ‎Non-linear Control‎ > ‎Phase Portrait‎ > ‎

mupad 3D phase portrate Matlab

plot::Ode3d(f, [t0, t1,...], Y0) renders three-dimensional projections of the solutions of the initial value problem given by ft0 and Y0.

plot::Ode3d(f, [t0, t1,...], Y0, [G]) computes a mesh of numerical sample points Y(t0), Y(t1), … representing the solution Y(t) of the first order differential equation (dynamical system)


The procedure

maps these solution points (tiY(ti)) in ×n to a mesh of 3D plot points [xiyizi]. These points can be connected by straight lines or interpolating splines.

Internally, a sequence of numerical sample points

Y_1 := numeric::odesolve(f, t_0..t_1, Y_0, Options),

Y_2 := numeric::odesolve(f, t_1..t_2, Y_1, Options), and so on

is computed, where Options is some combination of methodRelativeError = rtolAbsoluteError = atol, and Stepsize = h. See numeric::odesolve for details on the vector field procedure f, the initial condition Y0, and the options.

The utility function numeric::ode2vectorfield may be used to produce the input parameters f, t0, Y0 from a set of differential expressions representing the ODE.

Each of the "generators of plot data" G1G2 etc. creates a graphical solution curve from the numerical sample points Y0Y1 etc. Each generator G, say, is internally called in the form G(t0, Y0), G(t1, Y1), … to produce a sequence of plot points in 3D.

The solver numeric::odesolve returns the solution points Y0Y1, and so on, as lists or one-dimensional arrays (the actual type is determined by the initial value Y0). Consequently, each generator G must accept two arguments (t, Y)t is a real parameter, Y is a "vector" (either a list or a 1-dimensional array).

Each generator must return a list with 3 elements representing the (xyz) coordinates of the graphical point associated with a solution point (t, Y) of the ODE. All generators must produce graphical data of the same dimension, that is, forplot::Ode3d, 3D data as lists with 3 elements. For example, G := (t, Y) -> [Y_1, Y_2, Y_3] creates a 3D phase plot of the first three components of the solution curve.

If no generators are given, plot::Ode3d by default plots each group of two components as functions of time with the same style.

Note that arbitrary values associated with the solution curve may be displayed graphically by an appropriate generator G.

Several generators G1, G2, and so on, can be specified to generate several curves associated with the same numerical mesh Y0, Y1, ….

The graphical data produced by each of the generators G1, G2,... consists of a sequence of mesh points in 3D.

  • With Style = Points, the graphical data are displayed as a discrete set of points.

  • With Style = Lines, the graphical data points are displayed as a curve consisting of straight line segments between the sample points. The points themselves are not displayed.

  • With Style = Splines, the graphical data points are displayed as a smooth spline curve connecting the sample points. The points themselves are not displayed.

  • With Style = [Splines, Points] and Style = [Lines, Points], the effects of the styles used are combined, that is, both the evaluation points and the straight lines or splines, respectively, are displayed.

The plot attributes accepted by plot::Ode3d include Submesh = n, where n is some positive integer. This attribute only has an effect on the curves which are returned for the graphical generators with Style = Splines and Style = [Splines, Points], respectively. It serves for smoothening the graphical spline curve using a sufficiently high number of plot points.

n is the number of plot points between two consecutive numerical points corresponding to the time mesh. The default value is n = 4, that is, the splines are plotted as five straight line segments connecting the numerical sample points.


AttributePurposeDefault Value
AbsoluteErrormaximal absolute discretization error 
AffectViewingBoxinfluence of objects on the ViewingBox of a sceneTRUE
Colorslist of colors to use[RGB::BlueRGB::RedRGB::GreenRGB::MuPADGoldRGB::Orange,RGB::CyanRGB::MagentaRGB::LimeGreenRGB::CadmiumYellowLight,RGB::AlizarinCrimsonRGB::AquaRGB::LavenderRGB::SeaGreen,RGB::AureolineYellowRGB::BananaRGB::BeigeRGB::YellowGreen,RGB::WheatRGB::IndianRedRGB::Black]
Framesthe number of frames in an animation50
Functionfunction expression or procedure 
InitialConditionsinitial conditions of the ODE 
Legendmakes a legend entry 
LegendTextshort explanatory text for legend 
LegendEntryadd this object to the legend?FALSE
LineWidthwidth of lines0.35
LineStylesolid, dashed or dotted lines?Solid
LinesVisiblevisibility of linesTRUE
Namethe name of a plot object (for browser and legend) 
ODEMethodthe numerical scheme used for solving the ODEDOPRI78
ParameterEndend value of the animation parameter 
ParameterNamename of the animation parameter 
ParameterBegininitial value of the animation parameter 
ParameterRangerange of the animation parameter 
PointSizethe size of points1.5
PointStylethe presentation style of pointsFilledCircles
PointsVisiblevisibility of mesh pointsTRUE
Projectorsproject an ODE solution to graphical points 
RelativeErrormaximal relative discretization error 
Stepsizeset a constant step size 
Submeshdensity of submesh (additional sample points)4
TimeEndend time of the animation10.0
TimeMeshthe numerical time mesh 
TimeBeginstart time of the animation0.0
TimeRangethe real time span of an animation0.0 .. 10.0
Titleobject title 
TitleFontfont of object titles[" sans-serif "11]
TitlePositionposition of object titles 
TitleAlignmenthorizontal alignment of titles w.r.t. their coordinatesCenter
TitlePositionXposition of object titles, x component 
TitlePositionYposition of object titles, y component 
TitlePositionZposition of object titles, z component 
USubmeshdensity of additional sample points for parameter "u"4
VisibleAfterobject visible after this time value 
VisibleBeforeobject visible until this time value 
VisibleFromToobject visible during this time range 
VisibleAfterEndobject visible after its animation time ended?TRUE
VisibleBeforeBeginobject visible before its animation time starts?TRUE


Example 1

Consider the nonlinear oscillator . As a dynamical system for , solve the following initial value problem Y(0) = Y0:

f := (t, Y) -> [Y[2], sin(t) - Y[1]^3]: 
Y0 := [0, 0.5]:

The following generator produces a phase plot in the (xy) plane, embedded in a 3D plot:

G1 := (t, Y) -> [Y[1], Y[2], 0]:

Further, use the z coordinate of the 3D plot to display the value of the "energy" function  over the phase curve:

G2 := (t, Y) -> [Y[1], Y[2], (Y[1]^2 + Y[2]^2)/2]:

The phase curve in the (xy) plane is combined with the graph of the energy function:

p := plot::Ode3d(f, [i/5 $ i = 0..100], Y0,
                 [G1, Style = Splines, Color = RGB::Red],
                 [G2, Style = Points, Color = RGB::Black],
                 [G2, Style = Lines, Color = RGB::Blue]):

Set an explicit size of the points used in the representation of the energy:

p::PointSize := 2*unit::mm:

The renderer is called:

plot(p, AxesTitles = ["y", "y'", "E"],
     CameraDirection = [10, -15, 5]):

Example 2

The Lorenz ODE is the system

with fixed parameters prb. As a dynamical system for Y = [xyz], solve the ODE  with the following vector field:

f := proc(t, Y)
     local x, y, z;
        [x, y, z] := Y:
        [p*(y - x), -x*z + r*x - y, x*y - b*z]

Consider the following parameters and the following initial condition Y0:

p := 10: r := 28: b := 1: 
Y0 := [1, 1, 1]:

The following generator Gxyz produces a 3D phase plot of the solution. The generator Gyz projects the solution curve to the (yz) plane with x = 20; the generator Gxz projects the solution curve to the (xz) plane with y = - 15; the generatorGxy projects the solution curve to the (xy) plane with z = 0:

Gxyz := (t, Y) -> Y:
Gyz := (t, Y) -> [ 20,  Y[2], Y[3]]:
Gxz := (t, Y) -> [Y[1], -15,  Y[3]]:
Gxy := (t, Y) -> [Y[1], Y[2],   0 ]:

With these generators, create a 3D plot object consisting of the phase curve and its projections.

object := plot::Ode3d(f, [i/10 $ i=1..100], Y0,
           [Gxyz, Style = Splines, Color = RGB::Red],
           [Gyz, Style = Splines, Color = RGB::Grey50],
           [Gxz, Style = Splines, Color = RGB::Grey50],
           [Gxy, Style = Splines, Color = RGB::Grey50],
           Submesh = 7):

Finally, the plot is rendered. This call is somewhat time consuming because it calls the numerical solver numeric::odesolve to produce the graphical data:

plot(object, CameraDirection = [-220, 110, 150])



The vector field of the ODE: a procedure. See numeric::odesolve for details.

f is equivalent to the attribute Function.

t0, t1, …

The time mesh: real numerical values. If data are displayed with Style = Splines, these values must be in ascending order.

t0t1, … is equivalent to the attribute TimeMesh.


The time mesh: real numerical values. tend must be larger than tstart and tstep must be positive and should be smaller than tend - tstart.

tstarttendtstep are equivalent to the attribute TimeMesh.


The initial condition of the ODE: a list or a 1-dimensional array. See numeric::odesolve.

Y0 is equivalent to the attribute InitialConditions.

G1, G2, …

"generators of plot data": procedures mapping a solution point (t, Y(t)) to a list [x, y] or [x, y, z] representing a plot point in 2D or 3D, respectively.

G1G2, … is equivalent to the attribute Projectors.


Use a specific numerical scheme (see numeric::odesolve)


Animation parameter, specified as a = amin..amax, where amin is the initial parameter value, and amax is the final parameter value.



Option, specified as Style = style

Sets the style in which the plot data are displayed. The following styles are available: PointsLinesSplines[Lines, Points], and [Splines, Points]. The default style is [Splines, Points].


Option, specified as Color = c

Sets the RGB color c in which the plot data are displayed. The default color of the ith generator is the ith entry of the attribute Colors.


Option, specified as RelErr = rtol

Sets a numerical discretization tolerance (see numeric::odesolve)


Option, specified as AbsErr = atol

Sets a numerical discretization tolerance (see numeric::odesolve)


Option, specified as Stepsize = h

Sets a constant stepsize (see numeric::odesolve)