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.
|
|
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]):
|
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.):
|
| (1) |
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'):
|
| (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):
|
| (3) |
>
|
sysc2 := ToContinuous(sysd, method=prewarp):
|
| (4) |
The Resample command resamples a discrete system with a new sampling time.
>
|
sysd2 := Resample(sysd, 2, method=prewarp):
|
| (5) |
|
|
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):
|
The Covariance command computes the output covariance Matrix with the inputs driven by white Gaussian noise.
>
|
Covariance(sys3,<<1>>);
|
|
|
System Manipulation
|
|
>
|
sys4 := StateSpace(usesymbols, numstates=2, numinputs=1, numoutputs=1, symbols=[A1,B1,C1,D1]):
|
| (9) |
>
|
sys5 := StateSpace(usesymbols, numstates=2, numinputs=1, numoutputs=1, symbols=[A2,B2,C2,D2]):
|
| (10) |
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);
|
| (11) |
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);
|
| (12) |
|
|