DynamicSystems
Simulate
simulate a system
Calling Sequence
Parameters
Options
Description
Examples
Simulate( sys, input, opts )
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
initialconditions = Vector( realcons ) or list( equation ):
Specifies the initial conditions of the system. For a state-space system the initial condition is specified as a Vector, while for the differential equation system, the initial conditions is a list of equations. The discrete difference equation is first converted to a transfer function representation and then to state-space representation, and as a result any initial conditions specified are ignored. The transfer function, coefficients, and zero-pole-gain systems ignore the initial conditions. If omitted, the zero initial conditions are used.
parameters = set(name = complexcons) or list(name = complexcons)
Specifies numeric values for parameters in sys. These values override those specified by the parameters field of the system object, which in turn override the settings in in SystemOptions(parameters). The numeric value on the right-hand side of each equation is substituted for the name on the left-hand side in the expressions that define the model. No checking is done during the substitution to determine whether the substituted value is valid. For example, a complex value can be substituted for the coefficient of a polynomial. If the complex value had been originally assigned to the model at creation, a warning would be generated.
Continuous System Options
The following options apply to continuous systems.
output = solution, de, statevariable, outputvariable or a list of same
Specifies the content of the output. The following describes the output for each of the possible values. Multiple values can be selected by enclosing them in a list. Each element in the returned list/sequence (see returnlist, below) corresponds to the selected value.
solution: dsolve solution procedure; the default
de: system of diff-equations
outputvariable: list of the output-variables
statevariable: list of the state-variables
dsolveargs: additional arguments passed to dsolve; includes the value of the option dsolveargs (see below).
dsolveargs = list( equation )
Specifies additional parameters to be passed to dsolve. For typical values, see dsolve,numeric.
returnlist = truefalse
True means return a list; false means return an expression sequence. The default is false.
ignoredirac = truefalse
True means replace any function calls to Dirac in the system with 0; false means raise an error when a Dirac is present in the system. The default is false.
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.
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.
with⁡DynamicSystems:
ts≔0.1
t_sim≔10.0
in_t≔Sine⁡1,1,0,0
in_t≔0t<0sin⁡totherwise
in_z≔Sine⁡1,1,0,0,samplecount=round⁡t_simts,sampletime=ts,discrete
sys≔DiffEquation⁡0.5⁢diff⁡i⁡t,t+i⁡t=v⁡t−0.01⁢diff⁡θ⁡t,t,0.01⁢diff⁡diff⁡θ⁡t,t,t+0.1⁢diff⁡θ⁡t,t=0.01⁢i⁡t,inputvariable=v⁡t,outputvariable=θ⁡t,i⁡t
sys≔Diff. Equationcontinuous2 output(s); 1 input(s)inputvariable=v⁡toutputvariable=θ⁡t,i⁡t
sysz≔ToDiscrete⁡sys,ts
sysz≔Diff. Equationdiscrete; sampletime = .12 output(s); 1 input(s)inputvariable=v⁡qoutputvariable=θ⁡q,i⁡q
sol≔Simulate⁡sys,in_t
sol ≔ procx_rkf45...end proc
p1≔plotsodeplot⁡sol,t,θ⁡t,t=0..t_sim,numpoints=200,color=red:
ret≔Simulate⁡sysz,in_z
out_z≔ret1
p2≔DiscretePlot⁡out_z,0,ts,style=stair,color=blue:
plotsdisplay⁡p1,p2
sys2≔TransferFunction⁡1s2+s+10
sys2≔Transfer Functioncontinuous1 output(s); 1 input(s)inputvariable=u1⁡soutputvariable=y1⁡s
ret≔Simulate⁡sys2,in_t,output=solution,de,statevariable,outputvariable:
sol≔ret1:
de_list≔ret2:
state_v≔ret3:
output_v≔ret4:
sol⁡0.1
t=0.1,x1⁡t=0.000161695975336734,x2⁡t=0.00479344012872838,y1⁡t=0.000161695975336734
de_list
ⅆⅆtx1⁡t=x2⁡t,ⅆⅆtx2⁡t=−10.⁢x1⁡t−1.⁢x2⁡t+0t<0sin⁡totherwise,y1⁡t=1.⁢x1⁡t,x1⁡0=0,x2⁡0=0
state_v
x1⁡t,x2⁡t
output_v
y1⁡t
plotsodeplot⁡sol,seq⁡t,i,i=state_v,t=0..10,title=system states
plotsodeplot⁡sol,seq⁡t,i,i=output_v,t=0..10,title=system output
See Also
DynamicSystems[ResponsePlot]
Download Help Document