Dynamic Systems Examples
The DynamicSystems package is a collection of procedures for creating, manipulating, simulating, and plotting linear systems models.
Getting Started
While any command in the package can be referred to using the long form, for example, DynamicSystems, it is often easier to load the package and then use the short form command names.
restart;
with(DynamicSystems):
System Object Creation
Assign a differential system with derivatives in the input.
deq := 3*(diff(y(t), t, t))-2*y(t) = u(t)+diff(u(t), t):
sys1 := DiffEquation(deq, u, y):
Using the MagnitudePlot command, the magnitude of the response vs. frequency can be plotted, adding circles at selected frequencies. This is done by generating and combining two plots.
plots[display](MagnitudePlot(sys1), MagnitudePlot(sys1, frequencies = [.1, 1, 10], style = point, symbolsize = 20, symbol = circle));
Options
Parameters Option
All system constructors, such as TransferFunction and DiffEquation, accept a parameters option that consists of a list of equations specifying the parameter names and corresponding values. These parameters are used by procedures that require numeric values, for example, the plot routines. Most procedures that require numeric systems also provide a parameters option that can override the parameters assigned to the system.
sys2 := TransferFunction( A/(s+omega), parameters = [A=1, omega=2]):
MagnitudePlot(sys2);
Here, the parameters option of the plot procedure overrides the parameter A in the object:
MagnitudePlot(sys2, parameters=[A=100]);
StateSpace Options
The StateSpace constructor accepts options, such as randomtest and genbound, which are useful for generating random stable state-space systems.
ss1 := StateSpace('randomtest','numstates'=3,'numinputs'=2,'numoutputs'=1, 'genbound'=5.):
PrintSystem(ss1);
State Spacecontinuous1 output(s); 2 input(s); 3 state(s)inputvariable=u1⁡t,u2⁡toutputvariable=y1⁡tstatevariable=x1⁡t,x2⁡t,x3⁡ta=−4.42493164565702−4.02459595000590−3.730131837064940.468815192049838−7.676407537745904.05791937075619−2.215017811329524.13375856139019−5.85276313606821b=3.002804688888002004.70592781760615608−0.146243512771587980−3.423869183224517174.571669482429456374.64888535199276554c=4.15735525189067090−0.782387173737250308−3.58113661372784664d=4.594924263929030422.92207329559554374
The StateSpace constructor also accepts the usesymbols keyword option, which can be used to construct state matrices with symbolic elements.
ss2 := StateSpace('numstates'=3,'numinputs'=2,'numoutputs'=1,'usesymbols'):
PrintSystem(ss2);
State Spacecontinuous1 output(s); 2 input(s); 3 state(s)inputvariable=u1⁡t,u2⁡toutputvariable=y1⁡tstatevariable=x1⁡t,x2⁡t,x3⁡ta=a1,1a1,2a1,3a2,1a2,2a2,3a3,1a3,2a3,3b=b1,1b1,2b2,1b2,2b3,1b3,2c=c1,1c1,2c1,3d=d1,1d1,2
System Conversion
The ToContinuous command converts discrete systems to continuous systems using a specified conversion method.
sysd := TransferFunction(1/(z+a),discrete,parameters=[a=3]):
sysc1 := ToContinuous(sysd, method=forward):
PrintSystem(sysc1);
Transfer Functioncontinuous1 output(s); 1 input(s)inputvariable=u1⁡soutputvariable=y1⁡stf1,1=1s+1.+a
sysc2 := ToContinuous(sysd, method=prewarp):
PrintSystem(sysc2);
Transfer Functioncontinuous1 output(s); 1 input(s)inputvariable=u1⁡soutputvariable=y1⁡stf1,1=s−2.a⁢s−1.⁢s−2.⁢a−2.
The Resample command resamples a discrete system with a new sampling time.
sysd2 := Resample(sysd, 2, method=prewarp):
PrintSystem(sysd2);
Transfer Functiondiscrete; sampletime = 21 output(s); 1 input(s)inputvariable=u1⁡zoutputvariable=y1⁡ztf1,1=z+3a⁢z+3⁢z+3⁢a+1
Plotting
A Nichols plot is useful for quickly estimating the closed-loop response of system with unity-feedback, given its open-loop transfer function. For example, let the open-loop transfer function be:
G := 1/(s*(s+1)*((1/2)*s+1)):
By default a Nichols plot includes constant-phase and constant-magnitude contour plots of a closed-loop system. From the graph below, the peak closed-loop response is about 5 dB, at 0.8 rad/s, because that is the highest constant-magnitude contour that it touches (estimating).
NicholsPlot(TransferFunction(G), gainrange = -20 .. 20, frequencies = [.8]);
Here we plot the actual closed-loop response and confirm that the maximum gain is approximately 5 dB, at 0.8 rad/s.
CL := TransferFunction(G/(1+G)):
MagnitudePlot(CL, range = .1 .. 10);
System Analysis
The NormH2 and NormHinf commands compute each respective norm of a system.
sys3 := TransferFunction(1/(s+1)^2):
NormH2(sys3);
0.500000000000000
NormHinf(sys3);
1.000001000
The Covariance command computes the output covariance Matrix with the inputs driven by white Gaussian noise.
Covariance(sys3,<<1>>);
0.250000000000000
System Manipulation
sys4 := StateSpace(usesymbols, numstates=2, numinputs=1, numoutputs=1, symbols=[A1,B1,C1,D1]):
PrintSystem(sys4);
State Spacecontinuous1 output(s); 1 input(s); 2 state(s)inputvariable=u1⁡toutputvariable=y1⁡tstatevariable=x1⁡t,x2⁡ta=A11,1A11,2A12,1A12,2b=B11,1B12,1c=C11,1C11,2d=D11,1
sys5 := StateSpace(usesymbols, numstates=2, numinputs=1, numoutputs=1, symbols=[A2,B2,C2,D2]):
PrintSystem(sys5);
State Spacecontinuous1 output(s); 1 input(s); 2 state(s)inputvariable=u1⁡toutputvariable=y1⁡tstatevariable=x1⁡t,x2⁡ta=A21,1A21,2A22,1A22,2b=B21,1B22,1c=C21,1C21,2d=D21,1
The SeriesConnect command creates the equivalent system representation of two or more system objects connected in series.
sys_series := SeriesConnect([sys4,sys5]):
PrintSystem(sys_series);
State Spacecontinuous1 output(s); 1 input(s); 4 state(s)inputvariable=u1⁡toutputvariable=y1⁡tstatevariable=x1⁡t,x2⁡t,x3⁡t,x4⁡ta=A11,1A11,200A12,1A12,200B21,1⁢C11,1B21,1⁢C11,2A21,1A21,2B22,1⁢C11,1B22,1⁢C11,2A22,1A22,2b=B11,1B12,1B21,1⁢D11,1B22,1⁢D11,1c=D21,1⁢C11,1D21,1⁢C11,2C21,1C21,2d=D21,1⁢D11,1
The ParallelConnect command creates the equivalent system representation of two or more system objects connected in parallel.
sys_parallel := ParallelConnect([sys4,sys5]):
PrintSystem(sys_parallel);
State Spacecontinuous1 output(s); 1 input(s); 4 state(s)inputvariable=u1⁡toutputvariable=y1⁡tstatevariable=x1⁡t,x2⁡t,x3⁡t,x4⁡ta=A11,1A11,200A12,1A12,20000A21,1A21,200A22,1A22,2b=B11,1B12,1B21,1B22,1c=C11,1C11,2C21,1C21,2d=D11,1+D21,1
See Also
DynamicSystems
Download Help Document