simulate a system - Maple Help

Home : Support : Online Help : Science and Engineering : Dynamic Systems : Simulation Tools : DynamicSystems/Simulate

DynamicSystems[Simulate] - simulate a system

 Calling Sequence Simulate( sys, input, opts )

Parameters

 sys - System; system object input - algebraic, list(algebraic), Vector(realcons), list(Vector(realcons)), or Matrix(realcons); input signal opts - (optional) equation(s) of the form option = value; specify options for the Simulate command

Description

 • The Simulate command computes the transient response of sys, a linear system object, to input, a given input waveform. Both continuous and discrete systems can be simulated.

Continuous Systems

 • Continuous systems are simulated using dsolve[numeric]. The system is converted to a set of differential equations and initial conditions that are passed to dsolve.
 • Systems of type transfer function, coefficient, or zero-pole-gain are converted to a state-space representation that is then converted to a set of differential-equations.
 • If the variable names for the states are not given (transfer function, coefficient, and zero-pole-gain) then the value of statevariable from DynamicSystems[SystemOptions] is used with a numerical index appended.
 • A state-space system is converted to a set of differential equations.
 • A diff-equation system is used as is.
 • The input waveform, input, is given in terms of t, the time variable. For a single input system input is an algebraic expression, for a multiple-input system input is a list of algebraic expressions.  Heaviside functions in the input are converted to equivalent event-based steps.
 • By default the output is a dsolve procedure that takes the value of t as the input parameter.

Discrete Systems

 • A discrete system is simulated by converting it to a state-space representation and then iterating through the state-space equations.
 • If the variable names for the states are not given (transfer function, coefficient, and zero-pole-gain) then the value of statevariable from DynamicSystems[SystemOptions] is used with a numerical index appended.
 • The input waveform, input, consists of discrete values. For a single input system it is a Vector or a one-column Matrix. For a multiple input system it is a list of Vectors or a Matrix; the number of Vectors (columns of the Matrix) corresponds to the number of inputs of sys.
 • The output is a list of Vectors. Each Vector corresponds to an output of the system. The dimension of the Vectors match the dimension of the input Vector.
 • The calculation can be performed either as a hardware floating-point or software floating-point.  The environment variable UseHardwareFloats determines which floating-point representation is used.

Examples

 > $\mathrm{with}\left(\mathrm{DynamicSystems}\right):$
 > $\mathrm{ts}:=0.1$
 ${\mathrm{ts}}{:=}{0.1}$ (1)
 > $\mathrm{t_sim}:=10.0$
 ${\mathrm{t_sim}}{:=}{10.0}$ (2)
 > $\mathrm{in_t}:=\mathrm{Sine}\left(1,1,0,0\right)$
 ${\mathrm{in_t}}{:=}{{}\begin{array}{cc}{0}& {t}{<}{0}\\ {\mathrm{sin}}{}\left({t}\right)& {\mathrm{otherwise}}\end{array}$ (3)
 > $\mathrm{in_z}:=\mathrm{Sine}\left(1,1,0,0,\mathrm{samplecount}=\mathrm{round}\left(\frac{\mathrm{t_sim}}{\mathrm{ts}}\right),\mathrm{sampletime}=\mathrm{ts},\mathrm{discrete}\right)$
 ${\mathrm{in_z}}{:=}\left[\begin{array}{c}{\mathrm{1 .. 100}}{{\mathrm{Vector}}}_{{\mathrm{column}}}\\ {\mathrm{Data Type:}}{\mathrm{anything}}\\ {\mathrm{Storage:}}{\mathrm{rectangular}}\\ {\mathrm{Order:}}{\mathrm{Fortran_order}}\end{array}\right]$ (4)
 > $\mathrm{sys}:=\mathrm{DiffEquation}\left(\left[0.5\left(\frac{ⅆ}{ⅆt}i\left(t\right)\right)+i\left(t\right)=v\left(t\right)-0.01\left(\frac{ⅆ}{ⅆt}\mathrm{θ}\left(t\right)\right),0.01\left(\frac{ⅆ}{ⅆt}\left(\frac{ⅆ}{ⅆt}\mathrm{θ}\left(t\right)\right)\right)+0.1\left(\frac{ⅆ}{ⅆt}\mathrm{θ}\left(t\right)\right)=0.01i\left(t\right)\right],\mathrm{inputvariable}=\left[v\left(t\right)\right],\mathrm{outputvariable}=\left[\mathrm{θ}\left(t\right),i\left(t\right)\right]\right)$
 ${\mathrm{sys}}{:=}\left[\begin{array}{c}{\mathbf{Diff. Equation}}\\ {\mathrm{continuous}}\\ {\mathrm{2 output\left(s\right); 1 input\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{v}{}\left({t}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{\theta }}{}\left({t}\right){,}{i}{}\left({t}\right)\right]\end{array}\right$ (5)
 > $\mathrm{sysz}:=\mathrm{ToDiscrete}\left(\mathrm{sys},\mathrm{ts}\right)$
 ${\mathrm{sysz}}{:=}\left[\begin{array}{c}{\mathbf{Diff. Equation}}\\ {\mathrm{discrete; sampletime = .1}}\\ {\mathrm{2 output\left(s\right); 1 input\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{v}{}\left({q}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{\theta }}{}\left({q}\right){,}{i}{}\left({q}\right)\right]\end{array}\right$ (6)
 > $\mathrm{sol}:=\mathrm{Simulate}\left(\mathrm{sys},\left[\mathrm{in_t}\right]\right)$
 ${\mathrm{sol}}{:=}{\mathbf{proc}}\left({\mathrm{x_rkf45}}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{...}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (7)
 > $\mathrm{p1}:=\mathrm{plots}[\mathrm{odeplot}]\left(\mathrm{sol},\left[\left[t,\mathrm{θ}\left(t\right)\right]\right],t=0..\mathrm{t_sim},\mathrm{numpoints}=200,\mathrm{color}=\mathrm{red}\right):$
 > $\mathrm{ret}:=\mathrm{Simulate}\left(\mathrm{sysz},\left[\mathrm{in_z}\right]\right)$
 ${\mathrm{ret}}{:=}\left[\left[\begin{array}{c}{\mathrm{1 .. 100}}{{\mathrm{Vector}}}_{{\mathrm{column}}}\\ {\mathrm{Data Type:}}{{\mathrm{float}}}_{{8}}\\ {\mathrm{Storage:}}{\mathrm{rectangular}}\\ {\mathrm{Order:}}{\mathrm{Fortran_order}}\end{array}\right]{,}\left[\begin{array}{c}{\mathrm{1 .. 100}}{{\mathrm{Vector}}}_{{\mathrm{column}}}\\ {\mathrm{Data Type:}}{{\mathrm{float}}}_{{8}}\\ {\mathrm{Storage:}}{\mathrm{rectangular}}\\ {\mathrm{Order:}}{\mathrm{Fortran_order}}\end{array}\right]\right]$ (8)
 > $\mathrm{out_z}:={\mathrm{ret}}_{1}$
 ${\mathrm{out_z}}{:=}\left[\begin{array}{c}{\mathrm{1 .. 100}}{{\mathrm{Vector}}}_{{\mathrm{column}}}\\ {\mathrm{Data Type:}}{{\mathrm{float}}}_{{8}}\\ {\mathrm{Storage:}}{\mathrm{rectangular}}\\ {\mathrm{Order:}}{\mathrm{Fortran_order}}\end{array}\right]$ (9)
 > $\mathrm{p2}:=\mathrm{DiscretePlot}\left(\mathrm{out_z},0,\mathrm{ts},\mathrm{style}=\mathrm{stair},\mathrm{color}=\mathrm{blue}\right):$
 > $\mathrm{plots}[\mathrm{display}]\left(\mathrm{p1},\mathrm{p2}\right)$
 > $\mathrm{sys2}:=\mathrm{TransferFunction}\left(\frac{1}{{s}^{2}+s+10}\right)$
 ${\mathrm{sys2}}{:=}\left[\begin{array}{c}{\mathbf{Transfer Function}}\\ {\mathrm{continuous}}\\ {\mathrm{1 output\left(s\right); 1 input\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{\mathrm{u1}}{}\left({s}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{y1}}{}\left({s}\right)\right]\end{array}\right$ (10)
 > $\mathrm{ret}:=\mathrm{Simulate}\left(\mathrm{sys2},\left[\mathrm{in_t}\right],'\mathrm{output}'=\left['\mathrm{solution}','\mathrm{de}','\mathrm{statevariable}','\mathrm{outputvariable}'\right]\right):$
 > $\mathrm{sol}:={\mathrm{ret}}_{1}:$
 > $\mathrm{de_list}:={\mathrm{ret}}_{2}:$
 > $\mathrm{state_v}:={\mathrm{ret}}_{3}:$
 > $\mathrm{output_v}:={\mathrm{ret}}_{4}:$
 > $\mathrm{sol}\left(0.1\right)$
 $\left[{t}{=}{0.1}{,}{\mathrm{x1}}{}\left({t}\right){=}{0.000161695975336734}{,}{\mathrm{x2}}{}\left({t}\right){=}{0.00479344012872838}{,}{\mathrm{y1}}{}\left({t}\right){=}{0.000161695975336734}\right]$ (11)
 > $\mathrm{de_list}$
 $\left[\frac{{ⅆ}}{{ⅆ}{t}}{}{\mathrm{x1}}{}\left({t}\right){=}{\mathrm{x2}}{}\left({t}\right){,}\frac{{ⅆ}}{{ⅆ}{t}}{}{\mathrm{x2}}{}\left({t}\right){=}{-}{10.}{}{\mathrm{x1}}{}\left({t}\right){-}{1.}{}{\mathrm{x2}}{}\left({t}\right){+}\left({{}\begin{array}{cc}{0}& {t}{<}{0}\\ {\mathrm{sin}}{}\left({t}\right)& {\mathrm{otherwise}}\end{array}\right){,}{\mathrm{y1}}{}\left({t}\right){=}{1.}{}{\mathrm{x1}}{}\left({t}\right){,}{\mathrm{x1}}{}\left({0}\right){=}{0}{,}{\mathrm{x2}}{}\left({0}\right){=}{0}\right]$ (12)
 > $\mathrm{state_v}$
 $\left[{\mathrm{x1}}{}\left({t}\right){,}{\mathrm{x2}}{}\left({t}\right)\right]$ (13)
 > $\mathrm{output_v}$
 $\left[{\mathrm{y1}}{}\left({t}\right)\right]$ (14)
 > $\mathrm{plots}[\mathrm{odeplot}]\left(\mathrm{sol},\left[\mathrm{seq}\left(\left[t,i\right],i=\mathrm{state_v}\right)\right],t=0..10,\mathrm{title}="system states"\right)$
 > $\mathrm{plots}[\mathrm{odeplot}]\left(\mathrm{sol},\left[\mathrm{seq}\left(\left[t,i\right],i=\mathrm{output_v}\right)\right],t=0..10,\mathrm{title}="system output"\right)$