@@ -169,6 +169,26 @@ function ExtendedStateSpace(
169169 )
170170end
171171
172+ """
173+ ExtendedStateSpace(sys::AbstractStateSpace, w, u, z, y)
174+
175+ Create an [`ExtendedStateSpace`](@ref) from an existing state-space system with specified index vectors.
176+
177+ This constructor preserves the type of `sys` (e.g., `NamedStateSpace`).
178+
179+ # Arguments
180+ - `sys`: The underlying state-space system
181+ - `w`: Disturbance input indices (corresponds to B1)
182+ - `u`: Control input indices (corresponds to B2)
183+ - `z`: Performance output indices (corresponds to C1)
184+ - `y`: Measured output indices (corresponds to C2)
185+ """
186+ function ExtendedStateSpace (sys:: S , w:: I , u:: I , z:: I , y:: I ) where {S<: AbstractStateSpace , I}
187+ TE = typeof (sys. timeevol)
188+ T = ControlSystemsBase. numeric_type (sys)
189+ ExtendedStateSpace {TE, T, S, I} (sys, w, u, z, y)
190+ end
191+
172192"""
173193 ss(A, B1, B2, C1, C2, D11, D12, D21, D22 [, Ts])
174194
@@ -383,14 +403,29 @@ end
383403
384404function Base.:* (s1:: ExtendedStateSpace , s2:: Number )
385405 A, B1, B2, C1, C2, D11, D12, D21, D22 = ssdata_e (s1)
406+ # The reason for only scaling one channel is the use in UncertainSS
386407 ss (A, s2* B1, B2, C1, C2, s2* D11, D12, s2* D21, D22, s1. timeevol)
408+ # ExtendedStateSpace(s1.sys*s2, s1.w, s1.u, s1.z, s1.y)
387409end
388410
389411function Base.:* (s2:: Number , s1:: ExtendedStateSpace )
390412 A, B1, B2, C1, C2, D11, D12, D21, D22 = ssdata_e (s1)
391413 ss (A, B1, B2, s2* C1, C2, s2* D11, s2* D12, D21, D22, s1. timeevol)
414+ # ExtendedStateSpace(s2*s1.sys, s1.w, s1.u, s1.z, s1.y)
392415end
393416
417+ # function invert_mappings(s::ExtendedStateSpace)
418+ # # Reorder system: inputs [u; w] and outputs [y; z]
419+ # # This swaps the w↔u and z↔y mappings
420+ # (; w,u,z,y) = s
421+ # new_i = [u; w]
422+ # new_o = [y; z]
423+ # ExtendedStateSpace(s.sys, s.u, s.w, s.y, s.z)
424+ # # ExtendedStateSpace(s.sys[new_o, new_i], s.u, s.w, s.y, s.z)
425+ # # ExtendedStateSpace(s.sys[new_o, new_i], s.w, s.u, s.z, s.y)
426+ # end
427+
428+
394429function invert_mappings (s:: ExtendedStateSpace )
395430 A, B1, B2, C1, C2, D11, D12, D21, D22 = ssdata_e (s)
396431 ss (A, B2, B1, C2, C1, D22, D21, D12, D11, s. timeevol)
409444# end
410445
411446# # NEGATION ##
412- function Base.:- (sys:: ST ) where ST <: ExtendedStateSpace
413- A, B1, B2, C1, C2, D11, D12, D21, D22 = ssdata_e ( sys)
414- ST (A, B1, B2, - C1, - C2, - D11, - D12, - D21, - D22, sys. timeevol )
447+ function Base.:- (sys:: ExtendedStateSpace )
448+ # Negating a StateSpace negates C and D matrices, preserving the internal sys type
449+ ExtendedStateSpace ( - sys . sys, sys . w, sys . u, sys . z, sys. y )
415450end
416451
417452# ####################################################################
0 commit comments