You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Observability Gramian for discrete-time systems #967
# TODO: Check for continuous or discrete, only continuous supported for now
# if isCont():
# dico = 'C'
# elif isDisc():
# dico = 'D'
# else:
I checked and it doesn't raise an exception when you pass a discrete time system but I don't think this means it is calculating a gramian for a discrete-time system:
A = [[-0.31, 0.21], [-0.68, -0.57]]
B = [[1.23], [1.42]]
C = [[ 1.32, -0.55]]
D = [[0.]]
sysd = ct.ss(A, B, C, D, dt=1)
assert sysd.isdtime()
Wo = ct.gram(sysd, 'o')
print(Wo)
array([[ 3.24632551, -0.19876604],
[-0.19876604, 0.19212128]])
What would it take to get it working for discrete time systems? Is it simply a different call to the same slycot module, sb03md, or is it more involved?
Since I need it I'd be happy to try implementing it.
Is there a reason this wasn't implemented? Maybe at the time of writing isCont and isDisc didn't exist and the author was planning to come back and finish it but didn't perhaps?
I noticed this check for stability in the continuous-time case:
# Check for continuous or discreteifsys.isctime():
dico='C'# TODO: Check system is stable, perhaps a utility in ctrlutil.py# or a method of the StateSpace class?ifnp.any(np.linalg.eigvals(sys.A).real>=0.0):
raiseValueError("Oops, the system is unstable!")
Is this the right way to do this for discrete-time systems?
elifsys.isdtime():
dico='D'ifnp.any(np.abs(sys.poles()) >=1.):
raiseValueError("Oops, the system is unstable!")
Correct me if I'm wrong but we don't have an sys.isstable method yet.
Activity
billtubbs commentedon Feb 8, 2024
Expected output should be this I think:
billtubbs commentedon Feb 10, 2024
Where is the documentation on slycot? I tried googling and found the API but couldn't find anything specific on
sb03md.From wikipedia, the two equations that need to be solved are quite similar:
Observability Gramian for a continuous-time system:
$$A^T W_o + W_o A = -C^T C$$
Observability Gramian for a discrete-time system:
$$A^T W_{o} A - W_{o} = -C^T C$$
So I guess I just need to figure out how to do the second one.
Any advice/pointers would be appreciated.
bnavigator commentedon Feb 11, 2024
There is no hosted doc of Slycot (yet) (python-control/Slycot#202).
You are probably looking for the

dico='D'parameter ofslycot.sb03md57.billtubbs commentedon Feb 11, 2024
Okay well that was easy. If I simply allow
dico='D'option it calculates the correct Gramians.The code is all there, just commented-out:
I simply replaced above with:
Is there a reason this wasn't implemented? Maybe at the time of writing
isContandisDiscdidn't exist and the author was planning to come back and finish it but didn't perhaps?billtubbs commentedon Feb 11, 2024
Unless anyone knows of a problem with this, I'll just go ahead and implement it, including updated unit tests.
billtubbs commentedon Feb 11, 2024
I noticed this check for stability in the continuous-time case:
Is this the right way to do this for discrete-time systems?
Correct me if I'm wrong but we don't have an
sys.isstablemethod yet.billtubbs commentedon Feb 11, 2024
I've submitted the pull request.
One other thing I noticed, the gram function has an argument
typewhich is a reserved Python keyword.Should we change this to something else?
Or we could replace
gramwithobsv_gramandctrl_gram.murrayrm commentedon Mar 30, 2024
Fixed in #969.