state space into transformer function ......where is the problem

8 views (last 30 days)
clear all, close all, clc;
syms f j k1 k R l
%% State space representation
A = [-f/j k1/j;(-k-k1)/l -R/l];
% the state matrix
B = [0 -1/j;k/j 0];
% the input vector
C = [1 0;0 1];
% the output vector
D = zeros(size(C,2),size(B,2));
% the feedforward
%% Verify the controllability and observability
Mc = ctrb(A,B);
% Controllability matrix
Om = obsv(A,C)
% matrix
the_means_not_controllable = length(A)-length(Mc)
if rank(Mc) == size(A,2)
'It is controllable'
else
'It is not controllable'
end
if rank(Om) == size(A,2)
'It is observable'
else
'It is not observable'
end
%% Transform into transfer function
[num,den] = ss2tf(A,B,C,D)
sys = tf(num,den)
%Order system
Order_system = order(sys)
step(sys,'g')
grid on
.................................................................the problem
Error using ctrb (line 20)
The "ctrb" command cannot be used for models of class "sym".
Error in state_space (line 19)
Mc = ctrb(A,B);

Answers (1)

Pavl M.
Pavl M. on 30 Nov 2024 at 13:40
I found and corrected it:
clear all, close all, clc;
syms f j k1 k R l
%% State space representation
A = [-f/j k1/j;(-k-k1)/l -R/l];
% the state matrix
B = [0 -1/j;k/j 0];
% the input vector
C = [1 0;0 1];
% the output vector
D = zeros(size(C,2),size(B,2));
A = double(subs(A,{f,j,k1,k,R,l},{1,2,3,4,5,6}))
A = 2×2
-0.5000 1.5000 -1.1667 -0.8333
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
B = double(subs(B,{j,k},{2,4}))
B = 2×2
0 -0.5000 2.0000 0
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
% the feedforward
%% Verify the controllability and observability
Mc = ctrb(A,B);
% Controllability matrix
Om = obsv(A,C)
Om = 4×2
1.0000 0 0 1.0000 -0.5000 1.5000 -1.1667 -0.8333
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
% matrix
the_means_not_controllable = length(A)-length(Mc)
the_means_not_controllable = -2
if rank(Mc) == size(A,2)
'It is controllable'
else
'It is not controllable'
end
ans = 'It is controllable'
if rank(Om) == size(A,2)
'It is observable'
else
'It is not observable'
end
ans = 'It is observable'
%% Transform into transfer function
[num,den] = ss2tf(A,B,C,D,1)
num = 2×3
0 0 3 0 2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
den = 1×3
1.0000 1.3333 2.1667
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
sys1 = tf(num(1,:),den)
sys1 = 3 --------------------- s^2 + 1.333 s + 2.167 Continuous-time transfer function.
sys2 = tf(num(2,:),den)
sys2 = 2 s + 1 --------------------- s^2 + 1.333 s + 2.167 Continuous-time transfer function.
%Order system
Order_system1 = order(sys1)
Order_system1 = 2
Order_system2 = order(sys2)
Order_system2 = 2
step(sys1,'g')
hold on
grid on
step(sys2,'b')
grid on

Categories

Find more on Matrix Computations in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!