这是我应该怎么做的。代码是自我解释的。
clear all;
close all;
clc;
% Generate random state-space system
sys = rss(2,2,2);
%% Generate transfer function matrix with Matlab tf
% For each output
for i = 1:size(sys,1)
% For each input
for j = 1:size(sys,2)
% Get SISO transfer function
[num,den] = ss2tf(sys(i,j).A,sys(i,j).B,sys(i,j).C,sys(i,j).D);
% Compute tf
Gtf(i,j) = tf(num,den);
end
end
%% Generate transfer function matrix symbolic
% Laplace variable
s = sym('s');
% For each output
for i = 1:size(sys,1)
% For each input
for j = 1:size(sys,2)
% Get SISO transfer function
[num,den] = ss2tf(sys(i,j).A,sys(i,j).B,sys(i,j).C,sys(i,j).D);
% Compute tf
Gsym(i,j) = poly2sym(num,s);
end
end
% Den is the same for all elements
Gsym = Gsym / poly2sym(den,s);
% Numeric vectors is transformed to symbolic vector, to make everything
% readable change the variable precision arithmetic to 4 digits for output
pretty(vpa(Gsym,4))
-Edit- 我不得不说,Matlab 没有将这个功能整合到函数ss2tf
本身中,这让我感到有点惊讶。