Skip to content

Commit 1c20bf2

Browse files
committed
better tests
1 parent 3b38e7d commit 1c20bf2

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

test/test_reduction.jl

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -303,32 +303,35 @@ controller_reduction_plot(info.Gs,info.Ks, method=:cr)
303303
# ncfmargin(P, W1*Ksr)
304304

305305

306-
# === Scaling tests for model reduction ===
306+
307+
# === Scaling invariance tests for model reduction ===
307308
using RobustAndOptimalControl: baltrunc2, baltrunc_coprime, baltrunc_unstab
308309

309310
# Simple SISO system
310-
As = [-1.0]
311-
Bs = [2.0]
312-
Cs = [3.0]
313-
Ds = [0.5]
314-
sys_siso = ss(As, Bs, Cs, Ds)
311+
312+
sys_siso = ssrand(1,1,9,proper=true)
315313

316314
# Non-unit scaling factors
317315
scaleY = 5.0
318316
scaleU = 0.2
319317

320-
# baltrunc2 scaling test
321-
sysr, _ = baltrunc2(sys_siso; n=1, scaleY, scaleU)
322-
@test sysr.nx == 1
323-
@test abs(dcgain(sys_siso) - dcgain(sysr)) < 1e-8
318+
# baltrunc2: compare frequency response with and without scaling
319+
sysr_noscale, _ = baltrunc2(sys_siso; n=3)
320+
sysr_scale, _ = baltrunc2(sys_siso; n=3, scaleY=scaleY, scaleU=scaleU)
321+
@test sysr_noscale.nx == sysr_scale.nx == 3
322+
@test hinfnorm2(minreal(sysr_noscale - sysr_scale))[1] < 1e-5
323+
324+
325+
# baltrunc_coprime: compare frequency response with and without scaling
326+
sysr_coprime_noscale, _, _ = baltrunc_coprime(sys_siso; n=3)
327+
sysr_coprime_scale, _, _ = baltrunc_coprime(sys_siso; n=3, scaleY=scaleY, scaleU=scaleU)
328+
@test sysr_coprime_noscale.nx == sysr_coprime_scale.nx == 3
329+
@test hinfnorm2(minreal(sysr_coprime_noscale - sysr_coprime_scale))[1] < 1e-5
324330

325-
# baltrunc_coprime scaling test
326-
sysr_coprime, _, _ = baltrunc_coprime(sys_siso; n=1, scaleY, scaleU)
327-
@test sysr_coprime.nx == 1
328-
@test abs(dcgain(sys_siso) - dcgain(sysr_coprime)) < 1e-8
329331

330-
# baltrunc_unstab scaling test
332+
# baltrunc_unstab: compare frequency response with and without scaling
331333
sys_unstab = ss([1.0], [1.0], [1.0], [0.0]) # Unstable pole
332-
sysr_unstab, _, _ = baltrunc_unstab(sys_unstab; n=1, scaleY, scaleU)
333-
@test sysr_unstab.nx == 1
334-
@test abs(dcgain(sys_unstab) - dcgain(sysr_unstab)) < 1e-8
334+
sysr_unstab_noscale, _, _ = baltrunc_unstab(sys_unstab; n=3)
335+
sysr_unstab_scale, _, _ = baltrunc_unstab(sys_unstab; n=3, scaleY=scaleY, scaleU=scaleU)
336+
@test sysr_unstab_noscale.nx == sysr_unstab_scale.nx == 3
337+
@test hinfnorm2(minreal(sysr_unstab_noscale - sysr_unstab_scale))[1] < 1e-5

0 commit comments

Comments
 (0)