@@ -1027,13 +1027,22 @@ function linearization_function(sys::AbstractSystem, inputs, outputs; simplify =
1027
1027
lin_fun = let fun = fun,
1028
1028
h = ModelingToolkit. build_explicit_observed_function (sys, outputs)
1029
1029
1030
- (u, p, t) -> begin
1031
- uf = SciMLBase. UJacobianWrapper (fun, t, p)
1032
- fg_xz = ForwardDiff. jacobian (uf, u)
1033
- pf = SciMLBase. ParamJacobianWrapper (fun, t, u)
1034
- # TODO : this is very inefficient, p contains all parameters of the system
1035
- fg_u = ForwardDiff. jacobian (pf, p)[:, input_idxs]
1036
- h_xz = ForwardDiff. jacobian (xz -> h (xz, p, t), u)
1030
+ function (u, p, t)
1031
+ if u != = nothing # Handle systems without states
1032
+ length (sts) == length (u) ||
1033
+ error (" Number of state variables does not match the number of input states" )
1034
+ uf = SciMLBase. UJacobianWrapper (fun, t, p)
1035
+ fg_xz = ForwardDiff. jacobian (uf, u)
1036
+ h_xz = ForwardDiff. jacobian (xz -> h (xz, p, t), u)
1037
+ pf = SciMLBase. ParamJacobianWrapper (fun, t, u)
1038
+ # TODO : this is very inefficient, p contains all parameters of the system
1039
+ fg_u = ForwardDiff. jacobian (pf, p)[:, input_idxs]
1040
+ else
1041
+ length (sts) == 0 ||
1042
+ error (" Number of state variables does not match the number of input states" )
1043
+ fg_xz = zeros (0 ,0 )
1044
+ h_xz = fg_u = zeros (0 , length (inputs))
1045
+ end
1037
1046
h_u = ForwardDiff. jacobian (p -> h (u, p, t), p)[:, input_idxs]
1038
1047
(f_x = fg_xz[diff_idxs, diff_idxs],
1039
1048
f_z = fg_xz[diff_idxs, alge_idxs],
0 commit comments