How would I get an inverse and transfer function of a matrix with variable s?

So I'm trying to write a code that gets the inverse of a 4x4 matrix and then the transfer function for each of the 4 state inputs, the issue is these matrices include the s variable and with higher powers/coefficients. How would I go about implementing the variables into the matrix and subsequently get the transfer function?
I don't even need the code to get the transfer function as that can easily be obtained by hand if the inverse function worked with the variable, so that is the more pressing issue.
Example of what I'm trying to do and what I get:
A = [('s' + 0.06728) -0.02323 0 9.81;0.396 ('s' +1.729) -50 0;-0.0078 0.2431 ('s'+3.192) 0;0 0 -1 's'];
A_Inverse = inv(A)
Error code:
Check for missing argument or incorrect argument data type in call to function 'inv'.
Error in Matrices_Eigen (line 12)
A_Inverse = inv(A)

 Accepted Answer

A is of class char. What I think you want is a transfer function matrix from the Control Systems Toolbox
A = [('s' + 0.06728) -0.02323 0 9.81;0.396 ('s' +1.729) -50 0;-0.0078 0.2431 ('s'+3.192) 0;0 0 -1 's'];
whos A
Name Size Bytes Class Attributes A 4x4 32 char
s = tf('s')
s = s Continuous-time transfer function.
A = [(s + 0.06728) -0.02323 0 9.81;0.396 (s +1.729) -50 0;-0.0078 0.2431 (s+3.192) 0;0 0 -1 s];
whos A
Name Size Bytes Class Attributes A 4x4 4857 tf
A
A = From input 1 to output... 1: s + 0.06728 2: 0.396 3: -0.0078 4: 0 From input 2 to output... 1: -0.02323 2: s + 1.729 3: 0.2431 4: 0 From input 3 to output... 1: 0 2: -50 3: s + 3.192 4: -1 From input 4 to output... 1: 9.81 2: 0 3: 0 4: s Continuous-time transfer function.
Ai = inv(A)
Ai = From input 1 to output... s^3 + 4.921 s^2 + 17.67 s + 1.645e-16 1: --------------------------------------------- s^4 + 4.988 s^3 + 18.01 s^2 + 1.286 s + 1.077 -0.396 s^2 - 0.874 s + 4.015e-17 2: --------------------------------------------- s^4 + 4.988 s^3 + 18.01 s^2 + 1.286 s + 1.077 0.0078 s^2 + 0.1098 s - 1.935e-18 3: --------------------------------------------- s^4 + 4.988 s^3 + 18.01 s^2 + 1.286 s + 1.077 0.0078 s + 0.1098 4: --------------------------------------------- s^4 + 4.988 s^3 + 18.01 s^2 + 1.286 s + 1.077 From input 2 to output... 0.02323 s^2 + 0.07415 s + 2.385 1: --------------------------------------------- s^4 + 4.988 s^3 + 18.01 s^2 + 1.286 s + 1.077 s^3 + 3.259 s^2 + 0.2148 s + 0.07652 2: --------------------------------------------- s^4 + 4.988 s^3 + 18.01 s^2 + 1.286 s + 1.077 -0.2431 s^2 - 0.01617 s - 1.334e-19 3: --------------------------------------------- s^4 + 4.988 s^3 + 18.01 s^2 + 1.286 s + 1.077 -0.2431 s - 0.01617 4: --------------------------------------------- s^4 + 4.988 s^3 + 18.01 s^2 + 1.286 s + 1.077 From input 3 to output... -8.649 s - 16.96 1: --------------------------------------------- s^4 + 4.988 s^3 + 18.01 s^2 + 1.286 s + 1.077 50 s^2 + 3.364 s + 3.885 2: --------------------------------------------- s^4 + 4.988 s^3 + 18.01 s^2 + 1.286 s + 1.077 s^3 + 1.796 s^2 + 0.1255 s + 3.366e-17 3: --------------------------------------------- s^4 + 4.988 s^3 + 18.01 s^2 + 1.286 s + 1.077 s^2 + 1.796 s + 0.1255 4: --------------------------------------------- s^4 + 4.988 s^3 + 18.01 s^2 + 1.286 s + 1.077 From input 4 to output... -9.81 s^2 - 48.28 s - 173.4 1: --------------------------------------------- s^4 + 4.988 s^3 + 18.01 s^2 + 1.286 s + 1.077 3.885 s + 8.574 2: --------------------------------------------- s^4 + 4.988 s^3 + 18.01 s^2 + 1.286 s + 1.077 -0.07652 s - 1.077 3: --------------------------------------------- s^4 + 4.988 s^3 + 18.01 s^2 + 1.286 s + 1.077 s^3 + 4.988 s^2 + 18.01 s + 1.209 4: --------------------------------------------- s^4 + 4.988 s^3 + 18.01 s^2 + 1.286 s + 1.077 Continuous-time transfer function.

3 Comments

Thanks a lot for that, it works, but I run into issues whenever I multiply the inverse matrix by another, could you also lend some clarification on that?
e.g.
B = [0;-17.01;-44.37;0];
C = Ai*B
This equation yields different results to the ones I have in a writted down solution, such as the denominator having an s^8 term and the numerator having up to s^7/s^6 terms as the highest order.
s = tf('s');
A = [(s + 0.06728) -0.02323 0 9.81;0.396 (s +1.729) -50 0;-0.0078 0.2431 (s+3.192) 0;0 0 -1 s];
Ai = inv(A);
B = [0;-17.01;-44.37;0];
C = Ai*B
C = From input to output... -0.3951 s^6 + 380.5 s^5 + 2613 s^4 + 1.044e04 s^3 + 1.332e04 s^2 + 1327 s + 766.6 1: --------------------------------------------------------------------------------------------- s^8 + 9.977 s^7 + 60.91 s^6 + 182.3 s^5 + 339.5 s^4 + 57.07 s^3 + 40.44 s^2 + 2.769 s + 1.159 -17.01 s^7 - 2359 s^6 - 1.18e04 s^5 - 4.192e04 s^4 - 6563 s^3 - 5773 s^2 - 388 s - 187 2: --------------------------------------------------------------------------------------------- s^8 + 9.977 s^7 + 60.91 s^6 + 182.3 s^5 + 339.5 s^4 + 57.07 s^3 + 40.44 s^2 + 2.769 s + 1.159 -44.37 s^7 - 296.9 s^6 - 1182 s^5 - 1445 s^4 - 240.3 s^3 - 88.17 s^2 - 5.7 s - 1.606e-15 3: --------------------------------------------------------------------------------------------- s^8 + 9.977 s^7 + 60.91 s^6 + 182.3 s^5 + 339.5 s^4 + 57.07 s^3 + 40.44 s^2 + 2.769 s + 1.159 -44.37 s^6 - 296.9 s^5 - 1182 s^4 - 1445 s^3 - 240.3 s^2 - 88.17 s - 5.7 4: --------------------------------------------------------------------------------------------- s^8 + 9.977 s^7 + 60.91 s^6 + 182.3 s^5 + 339.5 s^4 + 57.07 s^3 + 40.44 s^2 + 2.769 s + 1.159 Continuous-time transfer function.
Convert to ZPK form, we see lots of potential pole/zero cancellations
C = zpk(C)
C = From input to output... -0.39514 (s-969.8) (s+1.858) (s^2 + 0.05575s + 0.0609) (s^2 + 4.933s + 17.68) 1: ----------------------------------------------------------------------------- (s^2 + 0.05575s + 0.0609)^2 (s^2 + 4.933s + 17.68)^2 -17.01 (s+133.6) (s^2 + 0.05575s + 0.0609) (s^2 + 0.06671s + 0.07641) (s^2 + 4.933s + 17.68) 2: -------------------------------------------------------------------------------------------- (s^2 + 0.05575s + 0.0609)^2 (s^2 + 4.933s + 17.68)^2 -44.37 s (s+1.63) (s+0.07321) (s^2 + 0.05575s + 0.0609) (s^2 + 4.933s + 17.68) 3: ------------------------------------------------------------------------------ (s^2 + 0.05575s + 0.0609)^2 (s^2 + 4.933s + 17.68)^2 -44.37 (s+1.63) (s+0.07321) (s^2 + 0.05575s + 0.0609) (s^2 + 4.933s + 17.68) 4: ---------------------------------------------------------------------------- (s^2 + 0.05575s + 0.0609)^2 (s^2 + 4.933s + 17.68)^2 Continuous-time zero/pole/gain model.
Use minreal on each element of C to simplify the expressions
for ii = 1:4
C(ii) = minreal(C(ii),1e-4);
end
C
C = From input to output... -0.39514 (s-969.8) (s+1.858) 1: ------------------------------------------------ (s^2 + 0.05575s + 0.0609) (s^2 + 4.933s + 17.68) -17.01 (s+133.6) (s^2 + 0.06671s + 0.07641) 2: ------------------------------------------------ (s^2 + 0.05575s + 0.0609) (s^2 + 4.933s + 17.68) -44.37 s (s+1.63) (s+0.07321) 3: ------------------------------------------------ (s^2 + 0.05575s + 0.0609) (s^2 + 4.933s + 17.68) -44.37 (s+1.63) (s+0.07321) 4: ------------------------------------------------ (s^2 + 0.05575s + 0.0609) (s^2 + 4.933s + 17.68) Continuous-time zero/pole/gain model.

Sign in to comment.

More Answers (0)

Categories

Asked:

on 10 Nov 2021

Commented:

on 10 Nov 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!