Skip to content

Added basic implementation of compreal for state space realization#26

Open
JD123473 wants to merge 1 commit into
gnu-octave:mainfrom
JD123473:main
Open

Added basic implementation of compreal for state space realization#26
JD123473 wants to merge 1 commit into
gnu-octave:mainfrom
JD123473:main

Conversation

@JD123473
Copy link
Copy Markdown

@JD123473 JD123473 commented May 6, 2026

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

  • Controllable form: T = ctrb(A, B)
  • Observable form: T = inv(obsv(A, C))

Testing

  • Tests added via %!test and %!error blocks
  • Covers: TF equivalence, correct T matrix, invalid realization error

Reference

T. Kailath, Linear Systems. Prentice-Hall, 1980. ISBN 0-13-536961-4

  • eq(15a) and eq(15b)

Copy link
Copy Markdown
Member

@ttl-octave ttl-octave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread inst/compreal.m
@@ -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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess "statistics package" is a copy & paste artifact? ;-)

Comment thread inst/compreal.m
## Author: J. Román <jdaniel.roman2004@gmail.com>
## Created: May 2026

function [csys, T] = compreal (sys, realization)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread inst/compreal.m

## Matrix T

if strcmp(realization, "c")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space between function name and argument list. Indentation within if-else-block

Comment thread inst/compreal.m
endif

if rank (T) < size (T, 1)
error ("compreal: system is not controllable/observable, T is singular");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants