Post Reply 
Script to find the root locus
11-27-2018, 04:56 PM (This post was last modified: 11-27-2018 05:03 PM by rushfan.)
Post: #1
Script to find the root locus
The root locus part of the Control Systems program in this forum does not work.
I wrote a little script that can generate the root locus of a system, with instructions on how to plot.
With thanks to members @ThomasA and @Tim Wessman for suggestions on how to properly plot it.
Here is the code:

Code:

// This is a script to find the root locus of system
// Arguments are num, den coefficients of polynomial
// Stepp is the size of the change in K
// Endd is the max value that K takes
// Example:  rls([1,3],[1,7,14,8,0],0.01,10)
// To use this program:
// In the Statistics 2var, symbolic
// Set independent varibale to L0
// Set dependent variable to L1
// Plot

EXPORT rls(num, den, stepp, endd)
BEGIN
LOCAL begg;
LOCAL xv:={};
LOCAL yv:={};
begg:=0.0001;
FOR K FROM begg TO endd STEP stepp DO
xv := concat(xv, RE(POLYROOT(poly2symb(den)+K*poly2symb(num))));
yv := concat(yv, IM(POLYROOT(poly2symb(den)+K*poly2symb(num))));
END;
L0:= xv;
L1 := yv;
END;
Find all posts by this user
Quote this message in a reply
11-29-2018, 08:41 AM
Post: #2
RE: Script to find the root locus
Inside CAS, point(proot(polynomial)) will display the list of roots of a polynomial. For several polynomials you can create an empty list l and run l:=concat(l,(proot(..)) inside the loop and run point(l) after the loop.
Find all posts by this user
Quote this message in a reply
12-02-2018, 03:59 PM (This post was last modified: 12-04-2018 07:24 PM by rushfan.)
Post: #3
RE: Script to find the root locus
(11-29-2018 08:41 AM)parisse Wrote:  Inside CAS, point(proot(polynomial)) will display the list of roots of a polynomial. For several polynomials you can create an empty list l and run l:=concat(l,(proot(..)) inside the loop and run point(l) after the loop.

That works better, thanks!

Code:

// This is a script to plot the root locus of a system
// Arguments are num, den coefficients of polynomial
// Stepp is the size of the change in K. If the script runs too slow, increase the stepp size. 
// Endd is the max value that K takes, if it is too slow to plot, decrease the max value. 
// Example:  rlscas([1,3],[1,7,14,8,0],0.01,10)
#cas
rlscas(num,den,stepp,endd):=
BEGIN
LOCAL K, begg, l:={};
begg:=0.001;
FOR K FROM begg TO endd STEP stepp DO
l := concat(l, proot(poly2symb(den)+K*poly2symb(num)));
END;
point(l);
END;
#end
Find all posts by this user
Quote this message in a reply
03-30-2019, 03:27 PM
Post: #4
RE: Script to find the root locus
It surprisingly works on the PC emulator but not on the physical calculator!!

Error: Execute evaluator not recursive
Find all posts by this user
Quote this message in a reply
03-31-2019, 07:56 PM
Post: #5
RE: Script to find the root locus
Take a look what I've got on the calc:

[Image: IMG-5685.jpg]

But in the emulator It runs nicely, I don't know why.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)