| Contents | Index |
and
render two- and threedimensional projections of the solutions of the initial value problem given by f, t0 and Y0, respectively.
Calls:
plot::Ode2d(f, [t0, t1, ...], Y0, <[G1, <Style = style1>, <Color = c1>], [G2, <Style = style2>, <Color = c2>], ...>, <method>, <RelativeError = rtol>, <AbsoluteError = atol>, <Stepsize = h>, <a = amin .. amax>, Options)
plot::Ode2d(f, [Automatic,
,
,
], Y0, <[G1, <Style = style1>, <Color = c1>], [G2, <Style = style2>, <Color = c2>], ...>, <method>, <RelativeError = rtol>, <AbsoluteError = atol>, <Stepsize = h>, <a = amin .. amax>, Options)
plot::Ode2d([t0, t1, ...], f, Y0, <[G1, <Style = style1>, <Color = c1>], [G2, <Style = style2>, <Color = c2>], ...>, <method>, <RelativeError = rtol>, <AbsoluteError = atol>, <Stepsize = h>, <a = amin .. amax>, Options)
plot::Ode2d([Automatic,
,
,
], f, Y0, <[G1, <Style = style1>, <Color = c1>], [G2, <Style = style2>, <Color = c2>], ...>, <method>, <RelativeError = rtol>, <AbsoluteError = atol>, <Stepsize = h>, <a = amin .. amax>, Options)
plot::Ode3d(f, [t0, t1, ...], Y0, <[G1, <Style = style1>, <Color = c1>], [G2, <Style = style2>, <Color = c2>], ...>, <method>, <RelativeError = rtol>, <AbsoluteError = atol>, <Stepsize = h>, <a = amin .. amax>, Options)
plot::Ode3d(f, [Automatic,
,
,
], Y0, <[G1, <Style = style1>, <Color = c1>], [G2, <Style = style2>, <Color = c2>], ...>, <method>, <RelativeError = rtol>, <AbsoluteError = atol>, <Stepsize = h>, <a = amin .. amax>, Options)
plot::Ode3d([t0, t1, ...], f, Y0, <[G1, <Style = style1>, <Color = c1>], [G2, <Style = style2>, <Color = c2>], ...>, <method>, <RelativeError = rtol>, <AbsoluteError = atol>, <Stepsize = h>, <a = amin .. amax>, Options)
plot::Ode3d([Automatic,
,
,
], f, Y0, <[G1, <Style = style1>, <Color = c1>], [G2, <Style = style2>, <Color = c2>], ...>, <method>, <RelativeError = rtol>, <AbsoluteError = atol>, <Stepsize = h>, <a = amin .. amax>, Options)
Parameters:
|
f: |
the vector field of the ODE: a procedure. See numeric::odesolve for details. |
|
t0, t1, ...: |
the time mesh: real numerical values. If data are displayed with Style = Splines, these values must be in ascending order. |
|
|
the time mesh: real numerical values. |
|
Y0: |
the initial condition of the ODE: a list or a 1-dimensional array. See numeric::odesolve. |
|
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. |
|
method: |
use a specific numerical scheme (see numeric::odesolve) |
Options:
|
Style = style: |
sets the style in which the plot data are displayed. The following styles are available: Points, Lines, Splines, [Lines, Points], and [Splines, Points]. The default style is [Splines, Points]. |
|
Color = c: |
sets the RGB color c in which the plot data are displayed. The default color of the |
|
RelErr = rtol: |
sets a numerical discretization tolerance (see numeric::odesolve) |
|
AbsErr = atol: |
sets a numerical discretization tolerance (see numeric::odesolve) |
|
Stepsize = h: |
sets a constant stepsize (see numeric::odesolve) |
Related Domains:
plot::Curve2d, plot::Curve3d, plot::PointList2d, plot::PointList3d, plot::Polygon2d, plot::Polygon3d, plot::Streamlines2d
Related Functions:
numeric::ode2vectorfield, numeric::odesolve, numeric::odesolve2
Details:
and
compute a mesh of numerical sample points
representing the solution
of the first order differential equation (dynamical system)
![]()
The procedure
![]()
maps these solution points
in
to a mesh of 2D plot points
or 3D plot points
, respectively. These points can be connected by straight lines or interpolating splines.
The calling syntax of plot::Ode2d und plot::Ode3d as well as the functionality of these two procedures is identical. The only difference is that plot::Ode2d expects graphical generators G1, G2 etc. that produce graphical 2D points, whereas plot::Ode3d expects graphical generators producing 3D points.
Internally, a sequence of numerical sample points
,
etc.
is computed, where Options is some combination of method, RelativeError = rtol, AbsoluteError = 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
from a set of differential expressions representing the ODE. Cf. Example 1.
Each of the “generators of plot data” G1, G2 etc. creates a graphical solution curve from the numerical sample points Y0, Y1 etc. Each generator G, say, is internally called in the form
to produce a sequence of plot points in 2D or 3D, respectively.
The solver numeric::odesolve returns the solution points Y0, Y1 etc. as lists or 1-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 2 or 3 elements representing the
or
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, i.e., 2D data as lists with 2 elements for plot::Ode2d or, for plot::Ode3d, 3D data as lists with 3 elements.
Some examples:
creates a 2D plot of the first component of the solution vector along the
-axis, plotted against the time variable t along the
-axis
creates a 2D phase plot, plotting the first component of the solution along the
-axis and the second component along the
-axis. The result is a solution curve in phase space (parametrized by the time t).
creates a 3D phase plot of the first three components of the solution curve.
If no generators are given, plot::Ode2d by default plots all components of the solution as functions of time, using [Splines, Points] as the style. 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. Cf. examples 2 and 5.
Several generators
etc. can be specified to generate several curves associated with the same numerical mesh
. Cf. examples 1, 2, and 3.
The graphical data produced by each of the generators
etc. consists of a sequence of mesh points in 2D or 3D, respectively.
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, i.e., both the evaluation points and the straight lines or splines, respectively, are displayed.
The plot attributes accepted by plot::Ode2d,Ode3d include Submesh = n, where
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. ![]()
is the number of plot points between two consecutive numerical points corresponding to the time mesh. The default value is
, i.e., the splines are plotted as 5 straight line segments connecting the numerical sample points.
Example 1
The following procedure f together with the initial value Y0 represent the initial value problem
,
. In MuPAD®, the 1-dimensional vector
is represented by a list with one element. The body of the function f below addresses the first (and only) entry of this list as Y1 and returns the 1-dimensional vector
as a list with one element. Also the initial condition Y0 is a 1-dimensional vector represented by a list:
f := (t, Y) -> [t*Y[1] - Y[1]^2]:
Y0 := [2]:
Alternatively, the utility function numeric::ode2vectorfield can be used to generate the input parameters in a more intuitive way:
[f, t0, Y0] := [numeric::ode2vectorfield(
{y'(t) = t*y(t) - y(t)^2, y(0) = 2}, [y(t)])]
![]()
The numerical solution is to consist of sample points over the time mesh
,
. We use the default generator of plot::Ode2d. This generates the sample points together with a smooth spline curve connecting these points:
p := plot::Ode2d(f, [$ 0..10], Y0,
PointSize = 2*unit::mm,
PointStyle = Stars):
Finally, the ode solution is rendered by a call to plot:
plot(p, TicksDistance = 2.0, GridVisible = TRUE,
SubgridVisible = TRUE):

Example 2
We consider the nonlinear oscillator
,
. As a dynamical system for
, we have to solve the following initial value problem
,
:
f := (t, Y) -> [Y[2], - Y[1]^7]:
Y0 := [1, 0]:
The following generator produces a plot of the solution
against the time parameter
:
G1 := (t, Y) -> [t, Y[1]]:
Further, we are interested in the values of the function
. The generator G2 produces the values
along the solution and plots these values against
:
G2 := (t, Y) -> [t, Y[1]^2/2 + Y[2]^2/2]:
The energy function (the “Hamiltonian”)
should be conserved along the solution curve. We define a corresponding generator G3 to plot
as a function of
:
G3 := (t, Y) -> [t, Y[1]^8/8 + Y[2]^2/2]:
The solution curve is combined with the graph of the function
and the conserved energy
:
p := plot::Ode2d(f, [i/2 $ i = 0..40], Y0,
[G1, Style = Lines, Color = RGB::Red],
[G1, Style = Points, Color = RGB::Black],
[G2, Style = Lines, Color = RGB::Blue],
[G2, Style = Points, Color = RGB::Black],
[G3, Style = Lines, Color = RGB::Green],
[G3, Style = Points, Color = RGB::Black],
PointSize = 1.5*unit::mm,
LineWidth = 0.2*unit::mm
):
Note that by using each generator twice, we are able to set different colors for the lines and points. The renderer is called:
plot(p):

To visualize the dependency of the trajectory on the initial conditions, we animate plot::Ode2d over different values of
:
plot(plot::Ode2d(f, [i/6 $ i = 0..120], [1, a], a = -1/2..1/2,
[G1, Style = Lines, Color = RGB::Red],
[G2, Style = Lines, Color = RGB::Blue],
[G3, Style = Lines, Color = RGB::Green],
LineWidth = 0.2*unit::mm, Frames=25))


Example 3
We consider the initial value problem
, ![]()
f := (t, y) -> t*sin(t + y^2): Y0:= [0]:
The following vector field is tangent to the solution curves:
p1 := plot::VectorField2d([1, f(t, y)], t = 0..4, y = -1.2..1.2,
Mesh = [21, 25], Color = RGB::Black):
The following object represents the plot of the solution as a function of t:
p2 := plot::Ode2d(
(t,Y) -> [f(t, Y[1])], [i/3 $ i=0..12], Y0,
[(t, Y) -> [t, Y[1]], Style = Points, Color = RGB::Red],
[(t, Y) -> [t, Y[1]], Style = Splines, Color = RGB::Blue]):
We define the point size explicitly:
p2::PointSize := 2*unit::mm:
Finally, we combine the vector field and the ODE plot to a scene and call the renderer:
plot(p1, p2, XTicksDistance = 0.5, YTicksDistance = 0.2,
Axes = Frame, AxesTitles = ["t", "y"],
GridVisible = TRUE):

Example 4
By default, numeric::odesolve (which is used by plot::Ode2d and plot::Ode3d internally) uses adaptive step sizes and a method of order 8. Usually, there is no reason to change these settings, except for demonstrative purposes. In the following animation, we use a straightforward explicit Euler method (of first order) and show how decreasing the step size improves the quality of the calculated solution.
Our differential equation is
, obviously fulfilled by the exponential function:
[f, t0, Y0] := [numeric::ode2vectorfield(
{y'(t)=y(t), y(0)=1}, [y(t)])]:
To judge the quality of the numerical solution, we plot the symbolic solution alongside the approximation:
plot(plot::Function2d(exp(x), x=0..3,
Color = RGB::Black, LineStyle = Dashed),
plot::Ode2d(f, [Automatic, 0, 3, 1/n], Y0, n = 1..50,
EULER1, Stepsize = 1/n,
[(t, Y) -> [t, Y[1]], Style=[Lines, Points]]))


Example 5
We consider the nonlinear oscillator
,
. As a dynamical system for
, we have to solve the following initial value problem
,
:
f := (t, Y) -> [Y[2], sin(t) - Y[1]^3]:
Y0 := [0, 0.5]:
The following generator produces a phase plot in the
plane, embedded in a 3D plot:
G1 := (t, Y) -> [Y[1], Y[2], 0]:
Further, we use the
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
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]):
We 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 6
The Lorenz ODE is the system
![diff(matrix([[x], [y], [z]]), t) = matrix([[p*(y - x)], [- x*z + r*x - y], [x*y - b*z]])](PRIMITIV_Ode2d3d_images/math90.png)
with fixed parameters
,
,
. As a dynamical system for
, we have to solve the ODE
with the following vector field:
f := proc(t, Y)
local x, y, z;
begin
[x, y, z] := Y:
[p*(y - x), -x*z + r*x - y, x*y - b*z]
end_proc:
We 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
plane with
; the generator Gxz projects the solution curve to the
plane with
; the generator Gxy projects the solution curve to the
plane with
:
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, we 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])


Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |