File tree Expand file tree Collapse file tree 2 files changed +15
-10
lines changed
Expand file tree Collapse file tree 2 files changed +15
-10
lines changed Original file line number Diff line number Diff line change @@ -137,24 +137,24 @@ function siso_tf_to_ss(T::Type, f::SisoRational)
137137 N = length (den) - 1 # The order of the rational function f
138138
139139 # Get numerator coefficient of the same order as the denominator
140- bN = length (num) == N+ 1 ? num[1 ] : 0
140+ bN = length (num) == N+ 1 ? num[1 ] : zero (num[ 1 ])
141141
142- if N == 0 # || num == zero(Polynomial{T})
143- A = zeros (T, ( 0 , 0 ) )
144- B = zeros (T, ( 0 , 1 ) )
145- C = zeros (T, ( 1 , 0 ) )
142+ @views if N == 0 # || num == zero(Polynomial{T})
143+ A = zeros (T, 0 , 0 )
144+ B = zeros (T, 0 , 1 )
145+ C = zeros (T, 1 , 0 )
146146 else
147147 A = diagm (1 => ones (T, N- 1 ))
148- A[end , :] .= - reverse (den)[1 : end - 1 ]
148+ A[end , :] .= . -reverse (den)[1 : end - 1 ]
149149
150- B = zeros (T, ( N, 1 ) )
150+ B = zeros (T, N, 1 )
151151 B[end ] = one (T)
152152
153- C = zeros (T, ( 1 , N) )
153+ C = zeros (T, 1 , N)
154154 C[1 : min (N, length (num))] = reverse (num)[1 : min (N, length (num))]
155- C[:] -= bN * reverse (den)[1 : end - 1 ] # Can index into polynomials at greater inddices than their length
155+ C[:] . -= bN . * reverse (den)[1 : end - 1 ] # Can index into polynomials at greater inddices than their length
156156 end
157- D = fill (bN, ( 1 , 1 ) )
157+ D = fill (bN, 1 , 1 )
158158
159159 return A, B, C, D
160160end
Original file line number Diff line number Diff line change 11@testset " test_conversion" begin
22
3+ G = tf (1.0 ,[1 ,1 ])
4+ H = zpk ([0.0 ], [1.0 ], 1.0 )
5+ @inferred ControlSystems. siso_tf_to_ss (Float64, G. matrix[1 ,1 ])
6+ @inferred ControlSystems. siso_tf_to_ss (Float64, H. matrix[1 ,1 ])
7+
38# Easy second order system
49sys1 = ss ([- 1 0 ;1 1 ],[1 ;0 ],[1 1 ],0 )
510G1 = tf ([1 ,0 ],[1 ,0 ,- 1 ])
You can’t perform that action at this time.
0 commit comments