forked from Future-Power-Networks/Simplus-Grid-Tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtf2sym.m
45 lines (33 loc) · 1.07 KB
/
tf2sym.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
% This function converts a transfer function model to its symbolic form.
% Author(s): Yunjie Gu, Yitong Li
%%
% Notes:
% This function is based on tf which reported overflow when layout node>=5,
% and was therefore discarded
% This is much faster than ss2sym.m
% The input system can be a SISO transfer function or a MIMO transfer
% function matrix.
%%
function Gsym = tf2sym(Gtf)
% Symbolic form of Laplace operator "s"
s = sym('s');
% Get the size of Gtf
[rmax,cmax] = size(Gtf);
% The input system is empty
if (rmax <= 0) || (cmax <= 0)
error(['Error: Empty input.']);
% The input system is SISO
elseif (rmax == 1) && (cmax == 1)
[Num,Den] = tfdata(Gtf);
Gsym = poly2sym(cell2mat(Num),s)/poly2sym(cell2mat(Den),s);
% The input system is MIMO
else
for r = 1:rmax
for c = 1:cmax
Gtf_ = Gtf(r,c);
[Num,Den] = tfdata(Gtf_);
Gsym(r,c) = poly2sym(cell2mat(Num),s)/poly2sym(cell2mat(Den),s);
end
end
end
end