Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Feb 21, 2024
1 parent 647e45f commit 1bdd386
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 11 deletions.
9 changes: 4 additions & 5 deletions src/SwitchOnSafety.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function LinearAlgebra.opnorm(ab::AB, p::Real=2)
if p != 2
throw(ArgumentError("`opnorm(::AB, $p)` not supported, only `2` is supported."))
end
C = nullspace(ab.B')
C = nullspace(ab.B', atol = 1.0)
return opnorm(C' * ab.A, 2)
end

Expand All @@ -41,13 +41,12 @@ function ρ(A::Matrix, B::Matrix)
n = size(A, 1)
powerA = I
Cspace = zeros(n, 0)
for i in (1: n)
for _ in 1:n
Cspace = [Cspace (powerA * B)]
powerA *= A
end
C = nullspace(Cspace')
E = (C) * (C)'
A22 = (C)' * A * C
C = nullspace(Cspace', atol = 1.0)
A22 = C' * A * C
if size(C, 2) == 0
return 0
end
Expand Down
6 changes: 0 additions & 6 deletions src/periodic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ function periodicswitching(s::AbstractDiscreteSwitchedSystem, period::Vector, A:
end

function periodicswitching(s::DiscreteSwitchedLinearControlSystem, period::Vector, A::AB; scaling = nothing)
B = zeros(size(A.A, 1), 0)
for sigma in period
Bsigma = s.resetmaps[symbol(s, sigma)].B
#TODO: Multiply by As
B = [A.B Bsigma]
end
lambda = ρ(A)
growthrate = _scale(adaptgrowthrate(abs(lambda), period), scaling)
periodicswitching(s, period, growthrate)
Expand Down
42 changes: 42 additions & 0 deletions testingtest/dcdc.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Revise
using SwitchOnSafety

function controlswitch(A::AbstractVector{<:AbstractMatrix}, B::AbstractVector{<:AbstractMatrix})
G = OneStateAutomaton(length(A))
n = 1
modes = ContinuousIdentitySystem.(map(s -> HybridSystems._getstatedim(A, G, s), states(G)))
rm = LinearControlMap.(A, B)
sw = HybridSystems.Fill(AutonomousSwitching(), n)
HybridSystem(G, modes, rm, sw, Dict{Symbol, Any}())
end

r_l = 2
r_c = 2
r_0 = 2
x_l = 0.1
x_c = 3

a1_11 = (-(r_l / x_l))
a1_22 = (-((1 / x_c) * (1 / (r_0 + r_c))))
a2_11 = ((-(1 / x_l)) * (r_l + (((r_0 * r_c))/(r_0 + r_c))))
a2_12 = ((-(1 / x_l)) * (r_0 / (r_0 + r_c)))
a2_21 = ((1 / x_c) * (r_0 / (r_0 + r_c)))
a2_22 = ((-(1 / x_c)) * (1 / (r_0 + r_c)))

Δt = 1e-1

A1 = [
a1_11 0 1/x_l
0 a1_22 0
0 0 0
]
A2 = [
a2_11 a2_12 1 / x_l
a2_21 a2_22 0
0 0 0
]

B = reshape([0.0, 0.0, 1.0], 3, 1)

s = controlswitch([I + Δt * A1, I + Δt * A2], [B, B])
psw, ub = gripenberg(s, δ=0.004)

0 comments on commit 1bdd386

Please sign in to comment.