How can I extract elements from a transfer function matrix in Octave?
Asked Answered
V

0

6

I am working with Octave in the control package, and I want to take an array of transfer functions (initialized as follows) and just extract the diagonal elements of the matrix. Whenever I try to do this, I run into the following error. I have tried lots of workarounds (converting it to a state space diagram, storing the elements in a cell, etc.), but I either run into a similar error or I end up with an object that can no longer interact with other matrices of transfer functions. There are some unimplemented functions (like ss2ss) in the documentation that I think would be useful but are unavailable.

How can I work around this?

The code initializing the type of object I'm working with:

s = tf('s');
m = inv(s*e - mat); // e and mat are just square matrices of numbers

The code I am using to try to extract the diagonal components:

function D = getD(W) // W is of the similar type as above
    n = size(W,1);
    Dtemp = tf(eye(n));
    for i = 1:n
        Dtemp(i,i) = W(i,i);
    end
    D = Dtemp;
end

Errors that I keep getting:

error: lti: subsasgn: invalid subscripted assignment type '()'.  you must select an LTI key first, i.e.  sys.keyname(...) = ...

Note that when I initialized Dtemp as cell (n,n), I get this type:

{
  [1,1] =

    <class tf>

  [2,1] =

    <class tf>
etc.

Instead of this type: (which is what I want it to interact with)

{
  [1,1] =

    <class tf>

}

Even though they are both nxn in size. I am hoping to be able to convert the former into the latter, so I can interact with other objects of the latter type.

Veradis answered 19/5, 2023 at 22:54 Comment(3)
Did you try diag?Cranage
@CrisLuengo Yeah, unfortunately the type doesn’t play well with the control packageVeradis
this appears to be a compatibility limitation of octave's transfer function implementation of subsasgn. the D(1,1) = A(1,1) syntax above works in matlab but produces an error in octave 9.2.0 with control 4.0.1. I opened a bug report at savannah.gnu.org/bugs/?66091Boehike

© 2022 - 2024 — McMap. All rights reserved.