Added basic implementation of compreal for state space realization#26
Added basic implementation of compreal for state space realization#26JD123473 wants to merge 1 commit into
Conversation
ttl-octave
left a comment
There was a problem hiding this comment.
Thank you very much for the contribution. I have some comments regarding parameter check (in order to prevent misleading error messages).
And what do you mean by "Based on the MATLAB implementation"? Please note that the code that you provide is completely yours and must not, under no circumstances, be somehow based on any MATLAB code.
| @@ -0,0 +1,152 @@ | |||
| ## Copyright (C) 2026 J. Román <jdaniel.roman2004@gmail.com> | |||
| ## | |||
| ## This file is part of the statistics package for GNU Octave. | |||
There was a problem hiding this comment.
I guess "statistics package" is a copy & paste artifact? ;-)
| ## Author: J. Román <jdaniel.roman2004@gmail.com> | ||
| ## Created: May 2026 | ||
|
|
||
| function [csys, T] = compreal (sys, realization) |
There was a problem hiding this comment.
Please check the parameters before using them, otherwise the error message might be misleadig for the user. As far as I can see:
- First arg must be a SISO LTI system
- Second must be a string, where the default is
'c'if it is omitted - It would also be helpful to check for controllability or observability resp. before computing the transformaiton in order to prevent ambiguous error messages
|
|
||
| ## Matrix T | ||
|
|
||
| if strcmp(realization, "c") |
There was a problem hiding this comment.
Space between function name and argument list. Indentation within if-else-block
| endif | ||
|
|
||
| if rank (T) < size (T, 1) | ||
| error ("compreal: system is not controllable/observable, T is singular"); |
There was a problem hiding this comment.
In case of a non observable system, inverting the observability matrix in line 105 already fails (either because matrix is not invertible or because matrix is not square (MIMO)).
Summary
Based on the MATLAB implementation, this function returns the state space realization to observable or canonical companion form, as well as the transformation matrix T.
Implementation
Testing
%!testand%!errorblocksReference
T. Kailath, Linear Systems. Prentice-Hall, 1980. ISBN 0-13-536961-4