 Dynamic Systems Examples - Maple Help

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); 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);
 $\left[\begin{array}{l}{\mathbf{State Space}}\\ {\mathrm{continuous}}\\ {\mathrm{1 output\left(s\right); 2 input\left(s\right); 3 state\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{\mathrm{u1}}{}\left({t}\right){,}{\mathrm{u2}}{}\left({t}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{y1}}{}\left({t}\right)\right]\\ {\mathrm{statevariable}}{=}\left[{\mathrm{x1}}{}\left({t}\right){,}{\mathrm{x2}}{}\left({t}\right){,}{\mathrm{x3}}{}\left({t}\right)\right]\\ {\mathrm{a}}{=}\left[\begin{array}{ccc}{{a}}_{{1}{,}{1}}& {{a}}_{{1}{,}{2}}& {{a}}_{{1}{,}{3}}\\ {{a}}_{{2}{,}{1}}& {{a}}_{{2}{,}{2}}& {{a}}_{{2}{,}{3}}\\ {{a}}_{{3}{,}{1}}& {{a}}_{{3}{,}{2}}& {{a}}_{{3}{,}{3}}\end{array}\right]\\ {\mathrm{b}}{=}\left[\begin{array}{cc}{{b}}_{{1}{,}{1}}& {{b}}_{{1}{,}{2}}\\ {{b}}_{{2}{,}{1}}& {{b}}_{{2}{,}{2}}\\ {{b}}_{{3}{,}{1}}& {{b}}_{{3}{,}{2}}\end{array}\right]\\ {\mathrm{c}}{=}\left[\begin{array}{ccc}{{c}}_{{1}{,}{1}}& {{c}}_{{1}{,}{2}}& {{c}}_{{1}{,}{3}}\end{array}\right]\\ {\mathrm{d}}{=}\left[\begin{array}{cc}{{d}}_{{1}{,}{1}}& {{d}}_{{1}{,}{2}}\end{array}\right]\end{array}\right$ (1) 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);
 $\left[\begin{array}{l}{\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]\\ {{\mathrm{tf}}}_{{1}{,}{1}}{=}\frac{{1}}{{s}{+}{1.}{+}{a}}\end{array}\right$ (2)
 > sysc2 := ToContinuous(sysd, method=prewarp):
 > PrintSystem(sysc2);
 $\left[\begin{array}{l}{\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]\\ {{\mathrm{tf}}}_{{1}{,}{1}}{=}\frac{{s}{-}{2.}}{{a}{}{s}{-}{1.}{}{s}{-}{2.}{}{a}{-}{2.}}\end{array}\right$ (3)

The Resample command resamples a discrete system with a new sampling time.

 > sysd2 := Resample(sysd, 2, method=prewarp):
 > PrintSystem(sysd2);
 $\left[\begin{array}{l}{\mathbf{Transfer Function}}\\ {\mathrm{discrete; sampletime = 2}}\\ {\mathrm{1 output\left(s\right); 1 input\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{\mathrm{u1}}{}\left({z}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{y1}}{}\left({z}\right)\right]\\ {{\mathrm{tf}}}_{{1}{,}{1}}{=}\frac{{z}{+}{3}}{{a}{}{z}{+}{3}{}{z}{+}{3}{}{a}{+}{1}}\end{array}\right$ (4) 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}$ (5)
 > NormHinf(sys3);
 ${1.000001000}$ (6)

The Covariance command computes the output covariance Matrix with the inputs driven by white Gaussian noise.

 > Covariance(sys3,<<1>>);
 $\left[\begin{array}{c}0.2500000000000001\end{array}\right]$ (7) System Manipulation

 > sys4 := StateSpace(usesymbols, numstates=2, numinputs=1, numoutputs=1, symbols=[A1,B1,C1,D1]):
 > PrintSystem(sys4);
 $\left[\begin{array}{l}{\mathbf{State Space}}\\ {\mathrm{continuous}}\\ {\mathrm{1 output\left(s\right); 1 input\left(s\right); 2 state\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{\mathrm{u1}}{}\left({t}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{y1}}{}\left({t}\right)\right]\\ {\mathrm{statevariable}}{=}\left[{\mathrm{x1}}{}\left({t}\right){,}{\mathrm{x2}}{}\left({t}\right)\right]\\ {\mathrm{a}}{=}\left[\begin{array}{cc}{{\mathrm{A1}}}_{{1}{,}{1}}& {{\mathrm{A1}}}_{{1}{,}{2}}\\ {{\mathrm{A1}}}_{{2}{,}{1}}& {{\mathrm{A1}}}_{{2}{,}{2}}\end{array}\right]\\ {\mathrm{b}}{=}\left[\begin{array}{c}{{\mathrm{B1}}}_{{1}{,}{1}}\\ {{\mathrm{B1}}}_{{2}{,}{1}}\end{array}\right]\\ {\mathrm{c}}{=}\left[\begin{array}{cc}{{\mathrm{C1}}}_{{1}{,}{1}}& {{\mathrm{C1}}}_{{1}{,}{2}}\end{array}\right]\\ {\mathrm{d}}{=}\left[\begin{array}{c}{{\mathrm{D1}}}_{{1}{,}{1}}\end{array}\right]\end{array}\right$ (8)
 > sys5 := StateSpace(usesymbols, numstates=2, numinputs=1, numoutputs=1, symbols=[A2,B2,C2,D2]):
 > PrintSystem(sys5);
 $\left[\begin{array}{l}{\mathbf{State Space}}\\ {\mathrm{continuous}}\\ {\mathrm{1 output\left(s\right); 1 input\left(s\right); 2 state\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{\mathrm{u1}}{}\left({t}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{y1}}{}\left({t}\right)\right]\\ {\mathrm{statevariable}}{=}\left[{\mathrm{x1}}{}\left({t}\right){,}{\mathrm{x2}}{}\left({t}\right)\right]\\ {\mathrm{a}}{=}\left[\begin{array}{cc}{{\mathrm{A2}}}_{{1}{,}{1}}& {{\mathrm{A2}}}_{{1}{,}{2}}\\ {{\mathrm{A2}}}_{{2}{,}{1}}& {{\mathrm{A2}}}_{{2}{,}{2}}\end{array}\right]\\ {\mathrm{b}}{=}\left[\begin{array}{c}{{\mathrm{B2}}}_{{1}{,}{1}}\\ {{\mathrm{B2}}}_{{2}{,}{1}}\end{array}\right]\\ {\mathrm{c}}{=}\left[\begin{array}{cc}{{\mathrm{C2}}}_{{1}{,}{1}}& {{\mathrm{C2}}}_{{1}{,}{2}}\end{array}\right]\\ {\mathrm{d}}{=}\left[\begin{array}{c}{{\mathrm{D2}}}_{{1}{,}{1}}\end{array}\right]\end{array}\right$ (9)

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);
 $\left[\begin{array}{l}{\mathbf{State Space}}\\ {\mathrm{continuous}}\\ {\mathrm{1 output\left(s\right); 1 input\left(s\right); 4 state\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{\mathrm{u1}}{}\left({t}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{y1}}{}\left({t}\right)\right]\\ {\mathrm{statevariable}}{=}\left[{\mathrm{x1}}{}\left({t}\right){,}{\mathrm{x2}}{}\left({t}\right){,}{\mathrm{x3}}{}\left({t}\right){,}{\mathrm{x4}}{}\left({t}\right)\right]\\ {\mathrm{a}}{=}\left[\begin{array}{cccc}{{\mathrm{A1}}}_{{1}{,}{1}}& {{\mathrm{A1}}}_{{1}{,}{2}}& {0}& {0}\\ {{\mathrm{A1}}}_{{2}{,}{1}}& {{\mathrm{A1}}}_{{2}{,}{2}}& {0}& {0}\\ {{\mathrm{B2}}}_{{1}{,}{1}}{}{{\mathrm{C1}}}_{{1}{,}{1}}& {{\mathrm{B2}}}_{{1}{,}{1}}{}{{\mathrm{C1}}}_{{1}{,}{2}}& {{\mathrm{A2}}}_{{1}{,}{1}}& {{\mathrm{A2}}}_{{1}{,}{2}}\\ {{\mathrm{B2}}}_{{2}{,}{1}}{}{{\mathrm{C1}}}_{{1}{,}{1}}& {{\mathrm{B2}}}_{{2}{,}{1}}{}{{\mathrm{C1}}}_{{1}{,}{2}}& {{\mathrm{A2}}}_{{2}{,}{1}}& {{\mathrm{A2}}}_{{2}{,}{2}}\end{array}\right]\\ {\mathrm{b}}{=}\left[\begin{array}{c}{{\mathrm{B1}}}_{{1}{,}{1}}\\ {{\mathrm{B1}}}_{{2}{,}{1}}\\ {{\mathrm{B2}}}_{{1}{,}{1}}{}{{\mathrm{D1}}}_{{1}{,}{1}}\\ {{\mathrm{B2}}}_{{2}{,}{1}}{}{{\mathrm{D1}}}_{{1}{,}{1}}\end{array}\right]\\ {\mathrm{c}}{=}\left[\begin{array}{cccc}{{\mathrm{D2}}}_{{1}{,}{1}}{}{{\mathrm{C1}}}_{{1}{,}{1}}& {{\mathrm{D2}}}_{{1}{,}{1}}{}{{\mathrm{C1}}}_{{1}{,}{2}}& {{\mathrm{C2}}}_{{1}{,}{1}}& {{\mathrm{C2}}}_{{1}{,}{2}}\end{array}\right]\\ {\mathrm{d}}{=}\left[\begin{array}{c}{{\mathrm{D2}}}_{{1}{,}{1}}{}{{\mathrm{D1}}}_{{1}{,}{1}}\end{array}\right]\end{array}\right$ (10)

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);
 $\left[\begin{array}{l}{\mathbf{State Space}}\\ {\mathrm{continuous}}\\ {\mathrm{1 output\left(s\right); 1 input\left(s\right); 4 state\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{\mathrm{u1}}{}\left({t}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{y1}}{}\left({t}\right)\right]\\ {\mathrm{statevariable}}{=}\left[{\mathrm{x1}}{}\left({t}\right){,}{\mathrm{x2}}{}\left({t}\right){,}{\mathrm{x3}}{}\left({t}\right){,}{\mathrm{x4}}{}\left({t}\right)\right]\\ {\mathrm{a}}{=}\left[\begin{array}{cccc}{{\mathrm{A1}}}_{{1}{,}{1}}& {{\mathrm{A1}}}_{{1}{,}{2}}& {0}& {0}\\ {{\mathrm{A1}}}_{{2}{,}{1}}& {{\mathrm{A1}}}_{{2}{,}{2}}& {0}& {0}\\ {0}& {0}& {{\mathrm{A2}}}_{{1}{,}{1}}& {{\mathrm{A2}}}_{{1}{,}{2}}\\ {0}& {0}& {{\mathrm{A2}}}_{{2}{,}{1}}& {{\mathrm{A2}}}_{{2}{,}{2}}\end{array}\right]\\ {\mathrm{b}}{=}\left[\begin{array}{c}{{\mathrm{B1}}}_{{1}{,}{1}}\\ {{\mathrm{B1}}}_{{2}{,}{1}}\\ {{\mathrm{B2}}}_{{1}{,}{1}}\\ {{\mathrm{B2}}}_{{2}{,}{1}}\end{array}\right]\\ {\mathrm{c}}{=}\left[\begin{array}{cccc}{{\mathrm{C1}}}_{{1}{,}{1}}& {{\mathrm{C1}}}_{{1}{,}{2}}& {{\mathrm{C2}}}_{{1}{,}{1}}& {{\mathrm{C2}}}_{{1}{,}{2}}\end{array}\right]\\ {\mathrm{d}}{=}\left[\begin{array}{c}{{\mathrm{D1}}}_{{1}{,}{1}}{+}{{\mathrm{D2}}}_{{1}{,}{1}}\end{array}\right]\end{array}\right$ (11) See Also