Introduction
Installation
ControlSystems.jl is written in the Julia programming language and is available through the Julia package manager. To install Julia, follow the instructions at julialang.org.
To install the full set of features of ControlSystems.jl, simply run the following command in the Julia REPL:
using Pkg; Pkg.add("ControlSystems")
For workflows that do not require continuous-time simulation, you may instead opt to install the much lighter package ControlSystemsBase.jl
using Pkg; Pkg.add("ControlSystemsBase")
ControlSystemsBase contains all functionality of ControlSystems except continuous-time simulation and root locus, and is considerably faster to load and precompile. To enjoy the faster pre-compilation, do not even install ControlSystems since this will cause pre-compilation of OrdinaryDiffEq, which can take several minutes.
Basic functions
State-space systems can be created using the function ss
and transfer functions can be created using the function tf(num, den)
or tf(num, den, Ts)
, where num
and den
are vectors representing the numerator and denominator of a rational function and Ts
is the sample time for a discrete-time system. See tf
or the section [Creating Systems] for more info. These functions can then be connected and modified using the operators +,-,*,/
and functions like append
.
Example:
P = tf([1.0],[1,1])
T = P/(1+P)
# output
TransferFunction{Continuous, ControlSystemsBase.SisoRational{Float64}}
1.0s + 1.0
-------------------
1.0s^2 + 3.0s + 2.0
Continuous-time transfer function model
Notice that the poles are not canceled automatically, to do this, the function minreal
is available
minreal(T)
# output
TransferFunction{Continuous, ControlSystemsBase.SisoRational{Float64}}
1.0
----------
1.0s + 2.0
Continuous-time transfer function model
or use feedback(P)
to get a minimal realization directly (recommended):
feedback(P) # Equivalent to P/(1+P)
TransferFunction{Continuous, ControlSystemsBase.SisoRational{Float64}}
1.0
----------
1.0s + 2.0
Continuous-time transfer function model
Transfer functions represent systems using polynomials and may have poor numerical properties for high-order systems. Well-balanced state-space representations are often better behaved. See Performance considerations for more details.
Plotting
The ControlSystems package is using RecipesBase.jl
(link) as interface to generate all the plots. This means that it is up to the user to choose a plotting library that supports RecipesBase.jl
, a suggestion would be Plots.jl
with which the user is also able to freely choose a back-end. The plots in this manual are generated using Plots.jl
with the GR
backend. If you have several back-ends for plotting then you can select the one you want to use with the corresponding Plots
call (for GR
this is Plots.gr()
, some alternatives are pyplot(), plotly(), pgfplots()
). A simple example where we generate a plot and save it to a file is shown below.
More examples of plots are provided in Plotting functions.
using Plots
bodeplot(tf(1,[1,2,1]))