diff --git a/lib/ControlSystemsBase/Project.toml b/lib/ControlSystemsBase/Project.toml index db2dcbf49..c2fc68c3a 100644 --- a/lib/ControlSystemsBase/Project.toml +++ b/lib/ControlSystemsBase/Project.toml @@ -2,7 +2,7 @@ name = "ControlSystemsBase" uuid = "aaaaaaaa-a6ca-5380-bf3e-84a91bcd477e" authors = ["Dept. Automatic Control, Lund University"] repo = "https://github.com/JuliaControl/ControlSystems.jl.git" -version = "1.22.0" +version = "1.22.1" [deps] ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" diff --git a/lib/ControlSystemsBase/src/hammerstein_weiner.jl b/lib/ControlSystemsBase/src/hammerstein_weiner.jl index c3b955d2d..e9a7bef7b 100644 --- a/lib/ControlSystemsBase/src/hammerstein_weiner.jl +++ b/lib/ControlSystemsBase/src/hammerstein_weiner.jl @@ -40,7 +40,7 @@ This function can also be used to linearize an output equation `C, D = linearize """ function linearize(f, xi::AbstractVector, ui::AbstractVector, args...) A = ForwardDiff.jacobian(x -> f(x, ui, args...), xi) - B = ForwardDiff.jacobian(u -> f(convert(typeof(u), xi), u, args...), ui) + B = ForwardDiff.jacobian(u -> f(convert.(eltype(u), xi), u, args...), ui) A, B end diff --git a/lib/ControlSystemsBase/test/test_hammerstein_wiener.jl b/lib/ControlSystemsBase/test/test_hammerstein_wiener.jl index 2c26e3b2c..b4e0b0e9e 100644 --- a/lib/ControlSystemsBase/test/test_hammerstein_wiener.jl +++ b/lib/ControlSystemsBase/test/test_hammerstein_wiener.jl @@ -127,6 +127,15 @@ A, B = ControlSystemsBase.linearize((x,u)->x.^2 + sin.(u), [1.0], [2.0]) @test A ≈ [2.0;;] @test B ≈ [cos(2);;] +# The state may have a different length and array type than the input +using StaticArrays, ComponentArrays +A, B = ControlSystemsBase.linearize((x,u)->SA[x[2], -sin(x[1]) + u[1]*u[2], x[3]], SA[0.0, 1.0, 2.0], SA[2.0, 3.0]) +@test A ≈ [0 1 0; -1 0 0; 0 0 1] +@test B ≈ [0 0; 3 2; 0 0] +A, B = ControlSystemsBase.linearize((x,u)->[x.v, -x.p + u[1]], ComponentArray(p=1.0, v=2.0), [3.0]) +@test A ≈ [0 1; -1 0] +@test B ≈ [0; 1;;] + ## Test nonlinear_components coverage ========================================== using ControlSystemsBase: Saturation, DeadZone, Offset, Hysteresis, describing_function, deadzone