@@ -132,14 +132,13 @@ function linearization_function(sys::AbstractSystem, inputs,
132132 return lin_fun, sys
133133end
134134
135+ """
136+ Return the set of indexes of differential equations and algebraic equations in the simplified system.
137+ """
135138function eq_idxs (sys:: AbstractSystem )
136139 eqs = equations (sys)
137- alg_start_idx = findfirst (! isdiffeq, eqs)
138- if alg_start_idx === nothing
139- alg_start_idx = length (eqs) + 1
140- end
141- diff_idxs = 1 : (alg_start_idx - 1 )
142- alge_idxs = alg_start_idx: length (eqs)
140+ alge_idxs = findall (! isdiffeq, eqs)
141+ diff_idxs = setdiff (1 : length (eqs), alge_idxs)
143142
144143 diff_idxs, alge_idxs
145144end
@@ -556,6 +555,9 @@ function linearize_symbolic(sys::AbstractSystem, inputs,
556555 (; A, B, C, D, f_x, f_z, g_x, g_z, f_u, g_u, h_x, h_z, h_u), sys
557556end
558557
558+ """
559+ Modify the variable metadata of system variables to indicate which ones are inputs, outputs, and disturbances. Needed for `inputs`, `outputs`, `disturbances`, `unbound_inputs`, `unbound_outputs` to return the proper subsets.
560+ """
559561function markio! (state, orig_inputs, inputs, outputs, disturbances; check = true )
560562 fullvars = get_fullvars (state)
561563 inputset = Dict {Any, Bool} (i => false for i in inputs)
@@ -586,6 +588,7 @@ function markio!(state, orig_inputs, inputs, outputs, disturbances; check = true
586588 if v in keys (disturbanceset)
587589 v = setio (v, true , false )
588590 v = setdisturbance (v, true )
591+ disturbanceset[v] = true
589592 fullvars[i] = v
590593 end
591594 end
@@ -596,11 +599,16 @@ function markio!(state, orig_inputs, inputs, outputs, disturbances; check = true
596599 " Some specified inputs were not found in system. The following variables were not found " ,
597600 ikeys)
598601 end
599- end
600- check && (all (values (outputset)) ||
601- error (
602- " Some specified outputs were not found in system. The following Dict indicates the found variables " ,
602+ dkeys = keys (filter (! last, disturbanceset))
603+ if ! isempty (dkeys)
604+ error (
605+ " Specified disturbance inputs were not found in system. The following variables were not found " ,
606+ ikeys)
607+ end
608+ (all (values (outputset)) || error (
609+ " Some specified outputs were not found in system. The following Dict indicates the found variables " ,
603610 outputset))
611+ end
604612 state, orig_inputs
605613end
606614
0 commit comments