# How to convert symbolic transfer function to state space?

53 views (last 30 days)

Show older comments

##### 0 Comments

### Accepted Answer

Sam Chak
on 29 Nov 2023

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)

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

% Check result if they are equivalent Gp = Gq

Gq = tf(sys)

##### 9 Comments

Sam Chak
on 30 Nov 2023

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.

Paul
on 30 Nov 2023

Edited: Paul
on 1 Dec 2023

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.

### More Answers (2)

Paul
on 1 Dec 2023

Moved: Sam Chak
on 2 Dec 2023

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)

[num, den] = numden(Gp)

[numcoeff, numterm] = coeffs(num, s, 'all')

[dencoeff, denterm] = coeffs(den, s, 'all')

[A, B, C, D] = tf2ss(numcoeff, dencoeff)

simplify(C*inv(s*eye(3)-A)*B + D) % verify

##### 1 Comment

Sam Chak
on 2 Dec 2023

Sam Chak
on 1 Dec 2023

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

%% tf2ss(num, den) requires inputs of numerator and denominator in vector form

[num, den] = numden(Gp)

[numcoeff, numterm] = coeffs(num, s)

[dencoeff, denterm] = coeffs(den, s)

%% check data type

class(numcoeff)

%% Obtain state-space matrices in symbolic form

[A, B, C, D] = tf2ss(numcoeff, [1 0 9 0])

##### 0 Comments

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!