How to convert symbolic transfer function to state space?

I have this transfer function: where alpha, beta1, and beta2 are unknown constants. I want to convert this to a state space in MATLAB. But regardless of what I do it just doesnt work out.

 Accepted Answer

I am uncertain about your intention regarding the symbolic state-space. The state-space object from the Control System Toolbox cannot be expressed symbolically. However, I can provide you with the conversion formula for the symbolic state-space in LaTeX form.
Plant transfer function:
Equivalent state-space system:
% Parameters
a = 3;
b1 = 5;
b2 = 7;
% Plant transfer function
s = tf('s');
Gp = ((a + b2)*s^2 + 3*b1*s + 9*a)/(s^3 + 9*s)
Gp = 10 s^2 + 15 s + 27 ------------------ s^3 + 9 s Continuous-time transfer function.
% Plant state-space
A = [0 1 0;
0 0 1;
0 -9 0];
B = [a+b2;
3*b1;
9*a-9*(a+b2)];
C = [1 0 0];
D = 0;
sys = ss(A, B, C, D)
sys = A = x1 x2 x3 x1 0 1 0 x2 0 0 1 x3 0 -9 0 B = u1 x1 10 x2 15 x3 -63 C = x1 x2 x3 y1 1 0 0 D = u1 y1 0 Continuous-time state-space model.
% Check result if they are equivalent Gp = Gq
Gq = tf(sys)
Gq = 10 s^2 + 15 s + 27 ------------------ s^3 + 9 s Continuous-time transfer function.

9 Comments

Its unfortunnate that MATLAB doesnt support symbolic transfer functions or state space models. But thank you so much for your answer. It helped.
One can certainly enter symbolic, SISO transfer functions:
syms s alpha beta_1 beta_2
H(s) = (9*alpha + 3*beta_1*s + alpha*s^2 + beta_2*s^2)/(s^3 + 9*s)
H(s) = 
With a little bit of work that could simplified, and with just a little bit more work could be converted into a state space realization in one of the common canonical forms.
What additional support would be useful? In other words, now that we have H(s) defined symbolically, what might one want to do next with H(s)?
transform it into a symbolic state space Paul.
I also have a question for Sam if they dont mind, what will the x vector (x1,x2,x3) represent in the context of the state space now that we transformed the transfer function?
Try to do it yourself .... these functions might be helpful: numden, coeffs, tf2ss.
Once you have the symbolic state space representation, what would you use it for, other than display.
Thats what I tried to do, but tf2ss doesnt accept symbolic transfer functions. I am performing an analysis on how the variation of alpha, beta1, and beta2 effect the dynamics of my system (the state space response). And the method I am specifically planning to do this involves deriving the state space symbolically first.
The symbolic state-space in my previous answer is realized in the Observable Companion Form, which happens to be my preferred state-space form in most design cases. The state represents the output of the transfer function . If the initial condition is known, then . However, and denote the unmeasurable internal states of the system. For instance, if represents position, then the velocity (rate of change of position) is given by . In other words, the velocity is a function of and u, .
Most lectures focus on teaching how to obtain the Controllable Canonical Form or the Observable Canonical Form realization of the transfer function . This emphasis is due to the intuitive Transfer-Function-to-State-Space conversion that can be achieved without mathematical calculations.
In the Controllable Canonical Form, the output of is equivalently the sum of , , and . Often, the output represents a measurable physical quantity. However, there are instances where not all state variables can be directly measured. In such cases, we can attempt to construct an observer to estimate these variables by measuring only the output .
I'm unsure about what you want to do with the symbolic state-space. One reason I can think of for wanting to obtain the symbolic state-space is the need to perform calculations that require knowledge of matrices A and B, such as in the case of LQR. Unfortunately, the functions from the Control System Toolbox cannot handle symbolic objects directly. Thus, you need some workarounds.
State-space in Controllable Canonical Form:
% Parameters
a = 3;
b1 = 5;
b2 = 7;
% Plant transfer function
s = tf('s');
Gp = ((a + b2)*s^2 + 3*b1*s + 9*a)/(s^3 + 9*s)
Gp = 10 s^2 + 15 s + 27 ------------------ s^3 + 9 s Continuous-time transfer function.
[num, den] = tfdata(Gp, 'v');
% State-space in Controllable Canonical Form
A = [ 0 1 0;
0 0 1;
-den(4) -den(3) -den(2)];
B = [0;
0;
1];
C = [num(4) num(3) num(2)];
D = 0;
sys = ss(A, B, C, D)
sys = A = x1 x2 x3 x1 0 1 0 x2 0 0 1 x3 0 -9 0 B = u1 x1 0 x2 0 x3 1 C = x1 x2 x3 y1 27 15 10 D = u1 y1 0 Continuous-time state-space model.
% Check result if they are equivalent Gp = Gq
Gq = tf(sys)
Gq = 10 s^2 + 15 s + 27 ------------------ s^3 + 9 s Continuous-time transfer function.
I am performing an analysis on how the variation of alpha, beta1, and beta2 effect the dynamics of my system (the state space response).
Obtaining the time responses of the system requires some real values for α, , and . Therefore, it cannot be purely symbolic. Also, if the initial condition is zero, then it is unnecessary to convert the transfer function to state-space. However, if the initial condition is non-zero, it becomes necessary to convert the transfer function to state-space. This is because the lsim(sys, u, t, x0) command can specify a vector x0 of initial state values only when sys is a state-space model.
Let's see the code you tried with tf2ss and we can see if it can be sorted out. tf2ss worked for me.
I still don't know what additional information you're trying to gain from the state space realization that you're not able to get from the transfer function.

Sign in to comment.

More Answers (2)

Hi Sam,
I was hoping that the OP would show a little more effort before giving the answer. Anyway ...
The code should be modified to use the 'all' input to coeffs so as to return the 0 coefficients as well. That way we can use dencoeff as well, which is what we'd want in general, and not return numeric A and D matrices
syms s alpha beta_1 beta_2
assume(alpha, 'real');
assume(beta_1, 'real');
assume(beta_2, 'real');
%% Plant transfer function in symbolic form
Gp = ((alpha + beta_2)*s^2 + 3*beta_1*s + 9*alpha)/(s^3 + 0*s^2 + 9*s + 0)
Gp = 
[num, den] = numden(Gp)
num = 
den = 
[numcoeff, numterm] = coeffs(num, s, 'all')
numcoeff = 
numterm = 
[dencoeff, denterm] = coeffs(den, s, 'all')
dencoeff = 
denterm = 
[A, B, C, D] = tf2ss(numcoeff, dencoeff)
A = 
B = 
C = 
D = 
0
simplify(C*inv(s*eye(3)-A)*B + D) % verify
ans = 

1 Comment

Thank you, @Paul.
Don't mind the OP. I'm also learning new things from you. Thus, I believe your proposed solution in the comment should be the true answer to this question because you have demonstrated how to execute this correctly in MATLAB. More importantly, it deserves my vote.

Sign in to comment.

@Paul's method is to use tf2ss(). In the past, I used this approach, but now I no longer use it since learning that the syntax ss(tf(num, den)) can achieve what I want. I also wasn't aware that tf2ss() can accept inputs of 'sym' (symbolic) data type.
syms s alpha beta_1 beta_2
assume(alpha, 'real');
assume(beta_1, 'real');
assume(beta_2, 'real');
%% Plant transfer function in symbolic form
Gp = ((alpha + beta_2)*s^2 + 3*beta_1*s + 9*alpha)/(s^3 + 0*s^2 + 9*s + 0)
Gp = 
%% tf2ss(num, den) requires inputs of numerator and denominator in vector form
[num, den] = numden(Gp)
num = 
den = 
[numcoeff, numterm] = coeffs(num, s)
numcoeff = 
numterm = 
[dencoeff, denterm] = coeffs(den, s)
dencoeff = 
denterm = 
%% check data type
class(numcoeff)
ans = 'sym'
%% Obtain state-space matrices in symbolic form
[A, B, C, D] = tf2ss(numcoeff, [1 0 9 0])
A = 3×3
0 -9 0 1 0 0 0 1 0
B = 
C = 
D = 
0

Products

Release

R2022b

Community Treasure Hunt

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

Start Hunting!