Customizing legends of rootlocusplot by ControlSystem.jl?

Hello mates, I would like to manipulate the rootlocusplot syntax by modifying the legends to be able to differentiate the system that I am graphing. Has anyone tried this?

My algorithm is this

using ControlSystems
using Plots

Gid = tf(numI,den);
Gvd = tf(numV,den);
rlocusplot(Gvd,xlims=(-4e4,4e4),ylims=(-2.5e4,2.5e4),) # ← ,label=‘Gvd’ ?
rlocusplot!(Gid,xlims=(-4e4,4e4),ylims=(-2.5e4,2.5e4),) # ← ,label=‘Gid’ ?

It seems like that is not implemented, though doesn’t seem like it would be a problem to add.

In the meantime you could call rlocus to get the roots and zeros and then plot them yourself, though this was only added in ControlSystems v1.5.1 so you have to make sure you have the latest version.

I haven’t tested the code, but I think something like this should work.

roots1, Z1, K1 = rlocus(Gid; K)
roots2, Z2, K2 = rlocus(Gvd; K)

plot(real.(roots1), imag.(roots1), label="Gid poles")
plot!(real.(Z1), imag.(Z1), label="Gid zeros")
plot!(real.(roots2), imag.(roots2), label="Gvd poles")
plot!(real.(Z2), imag.(Z2), label="Gvd zeros")
1 Like

Thanks for reply albheim, I tried to include the function rlocus but my problem now is I don’t know what ‘K’ must be in the algorithm, the thing that I did was use the module Polynomials.jl and simple plot the roots. In the future if you test the rlocus function, it will be awesome to share…

If you are in the REPL you can go into help mode by entering a question mark on an empty line, and then write the name of a function to get the docstrings for it.

help?> rlocus
search: rlocus rlocusplot rlocusplot!

  roots, Z, K = rlocus(P::LTISystem; K)

  Compute the root locus of the SISO LTISystem P with a negative feedback loop and feedback gains
  between 0 and K. rlocus will use an adaptive step-size algorithm to determine the values of the
  feedback gains used to generate the plot.

  roots is a complex matrix containig the poles trajectories of the closed-loop 1+k⋅G(s) as a
  function of k, Z contains the zeros of the open-loop system G(s) and K the values of the
  feedback gain.

So here you see that we generate the closed loop poles and zeros for feedback gains between 0 and K. Though, something we don’t see here but can find in the code is that you can leave K out from the call and then it will default to 500.

I also realised you would get some double labels with what I said before, so here is a better recreation of the plot. It doesn’t take care of the colors well, but I’m sure you can fix that if you want.

roots1, Z1, K1 = rlocus(Gid)
roots2, Z2, K2 = rlocus(Gvd)

plot(real.(roots1), imag.(roots1), label=false)
scatter!(real.(roots1)[1,:], imag.(roots1)[1,:], markershape=:xcross, label="Gid poles")
scatter!(real.(Z1), imag.(Z1), markershape=:circle, label="Gid zeros")
plot!(real.(roots2), imag.(roots2), label=false)
scatter!(real.(roots2)[1,:], imag.(roots2)[1,:], markershape=:xcross, label="Gvd poles")
scatter!(real.(Z2), imag.(Z2), markershape=:circle, label="Gvd zeros")