Use MatLab to convert from state space to transfer function (symbolic)

This script requires the MatLab's symbolic toolbox

% Start by clearing everything
clear all
clc

Declare all symbolic variables

syms a3 a2 a1 s b0 b1

Define state space system

A=[0 1 0; 0 0 1; -3 -4 -2];
B=[0; 0; 1;];
C=[5 1 0];
D=0;

Find State Transition Matrix transition matrix

Phi=inv(s*eye(3)-A)
 
Phi =
 
[ (s^2 + 2*s + 4)/(s^3 + 2*s^2 + 4*s + 3),     (s + 2)/(s^3 + 2*s^2 + 4*s + 3),   1/(s^3 + 2*s^2 + 4*s + 3)]
[              -3/(s^3 + 2*s^2 + 4*s + 3), (s*(s + 2))/(s^3 + 2*s^2 + 4*s + 3),   s/(s^3 + 2*s^2 + 4*s + 3)]
[          -(3*s)/(s^3 + 2*s^2 + 4*s + 3),  -(4*s + 3)/(s^3 + 2*s^2 + 4*s + 3), s^2/(s^3 + 2*s^2 + 4*s + 3)]
 

Find transfer function

H=C*Phi*B+D
 
H =
 
s/(s^3 + 2*s^2 + 4*s + 3) + 5/(s^3 + 2*s^2 + 4*s + 3)
 
%Display
pretty(simple(H))
 
         s + 5 
  ------------------- 
   3      2 
  s  + 2 s  + 4 s + 3