# Control Systems/Open source tools/Julia

## Prerequisite

It is necessary to install Julia and afterwards the ControlSystems.jl package. It is recommended to follow the official Julia Documentation. Julia can be executed in a terminal but it is quite practical to use an IDE like Juno/Atom or Visual Studio Code.

The ControlSystems.jl package has to be loaded with

using ControlSystems


before the function can be evaluated.

Throughout this course it is assumed that the source code is typed in the Julia REPL to print the results instantaneously. Otherwise, results can be printed with

print()


## Classical Control

### Transfer Function

Consider the transfer function

$G(s)={\frac {s+2}{3s^{2}+4s+5}}$ The transfer function is created similar to other numerical toolboxes with numerator and denominator as

num = [1, 2]      # Numerator
den = [3, 4, 5]   # Denominator
G = tf(num, den)  # Transfer function


The REPL responses an overview of the created transfer function object

TransferFunction{ControlSystems.SisoRational{Int64}}
s + 2
---------------
3*s^2 + 4*s + 5
Continuous-time transfer function model


### Poles and Zeros

The poles of transfer function $G(s)$ are computed with

pole(G)


and the REPL responses

 2-element Array{Complex{Float64},1}:
-0.6666666666666665 + 1.1055415967851332im
-0.6666666666666665 - 1.1055415967851332im


The zeros of transfer function $G(s)$ are computed with

tzero(G)


and resulting in

1-element Array{Float64,1}:
-2.0


The function

zpkdata(G)


will response the zeros, poles and the gain.

The Pole-Zero Plot is created with

pzmap(G)


### Impulse and Step Response

It is handy to define the simulation time and a label for both plots with

Tf = 20 # Final simulation time in seconds
impulse_lbl = "y(t) = g(t)" # Label for impulse response g(t)
step_lbl    = "y(t) = h(t)" # Label for step response h(t)


The impulse response is created with

impulseplot(G, Tf, label=impulse_lbl) # Impulse response


and the step response is built with

stepplot(G, Tf, label=impulse_lbl) # Step response


### Bode and Nyquist Plot

The Bode plot is printed with

bodeplot(G) # Bode plot


and the Nyquist plot (without gain circles) is printed with

nyquistplot(G, gaincircles=false) # Nyquist plot


The gain circles can be toggled with the boolean flag.

Note:

If only the numerical results of the Bode/Nyquist plot are of interest and not their visualization, then one can use

bode(G)


and

nyquist(G)