From 45ae08c4672e1a56c679191ec596901f594c1218 Mon Sep 17 00:00:00 2001 From: Zdenek Hurak <hurak@fel.cvut.cz> Date: Sat, 9 Mar 2019 00:28:48 +0100 Subject: [PATCH 1/4] Updated the call of lsim in test_timeresp.jl to use keyword arguments for x0. The same modification done in timeresp.jl, wherein additionally the string for the label was corrected (transpose removed) and `using Plots` added. --- src/timeresp.jl | 6 ++++-- test/test_timeresp.jl | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/timeresp.jl b/src/timeresp.jl index 6c072754f..36026fc79 100644 --- a/src/timeresp.jl +++ b/src/timeresp.jl @@ -88,6 +88,8 @@ To simulate a unit step, use `(x,i)-> 1`, for a ramp, use `(x,i)-> i*h`, for a s Usage example: ```julia using LinearAlgebra # For identity matrix I +using Plots + A = [0 1; 0 0] B = [0;1] C = [1 0] @@ -99,8 +101,8 @@ L = lqr(sys,Q,R) u(x,t) = -L*x # Form control law, t=0:0.1:5 x0 = [1,0] -y, t, x, uout = lsim(sys,u,t,x0) -plot(t,x, lab=["Position", "Velocity"]', xlabel="Time [s]") +y, t, x, uout = lsim(sys,u,t;x0=x0) +plot(t,x, lab=["Position", "Velocity"], xlabel="Time [s]") ``` """ function lsim(sys::StateSpace, u::AbstractVecOrMat, t::AbstractVector; diff --git a/test/test_timeresp.jl b/test/test_timeresp.jl index e0a116d58..e1b783e35 100644 --- a/test/test_timeresp.jl +++ b/test/test_timeresp.jl @@ -13,7 +13,7 @@ L = lqr(sys,Q,R) u(x,i) = -L*x # Form control law t=0:0.1:50 x0 = [1.,0] -y, t, x, uout = lsim(sys,u,t,x0=x0) # Continuous time +y, t, x, uout = lsim(sys,u,t;x0=x0) # Continuous time th = 1e-6 @test sum(abs.(x[end,:])) < th From cd20136d5b7a73421bfa94c5ea9702006d164eb6 Mon Sep 17 00:00:00 2001 From: hurak <hurak@fel.cvut.cz> Date: Tue, 12 Mar 2019 14:00:02 +0100 Subject: [PATCH 2/4] A corrected correction of example for lsim (label in plot must be a row) --- src/timeresp.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/timeresp.jl b/src/timeresp.jl index 36026fc79..084882021 100644 --- a/src/timeresp.jl +++ b/src/timeresp.jl @@ -102,7 +102,7 @@ u(x,t) = -L*x # Form control law, t=0:0.1:5 x0 = [1,0] y, t, x, uout = lsim(sys,u,t;x0=x0) -plot(t,x, lab=["Position", "Velocity"], xlabel="Time [s]") +plot(t,x, lab=["Position" "Velocity"], xlabel="Time [s]") ``` """ function lsim(sys::StateSpace, u::AbstractVecOrMat, t::AbstractVector; From ad1b8b71f20f42d84855f269714bd73b9c71e19c Mon Sep 17 00:00:00 2001 From: hurak <hurak@fel.cvut.cz> Date: Tue, 12 Mar 2019 14:07:00 +0100 Subject: [PATCH 3/4] Reverted the semicolon back to comma with the keyword argument x0 in lsim --- src/timeresp.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/timeresp.jl b/src/timeresp.jl index 084882021..061fed0dc 100644 --- a/src/timeresp.jl +++ b/src/timeresp.jl @@ -101,7 +101,7 @@ L = lqr(sys,Q,R) u(x,t) = -L*x # Form control law, t=0:0.1:5 x0 = [1,0] -y, t, x, uout = lsim(sys,u,t;x0=x0) +y, t, x, uout = lsim(sys,u,t,x0=x0) plot(t,x, lab=["Position" "Velocity"], xlabel="Time [s]") ``` """ From ff1ddc4e2fd9afa5993208039405fe3a289a182a Mon Sep 17 00:00:00 2001 From: hurak <hurak@fel.cvut.cz> Date: Tue, 12 Mar 2019 14:11:03 +0100 Subject: [PATCH 4/4] Reverted the semicolon back to comma with the keyword argument x0 in lsim in a test --- test/test_timeresp.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_timeresp.jl b/test/test_timeresp.jl index e1b783e35..e0a116d58 100644 --- a/test/test_timeresp.jl +++ b/test/test_timeresp.jl @@ -13,7 +13,7 @@ L = lqr(sys,Q,R) u(x,i) = -L*x # Form control law t=0:0.1:50 x0 = [1.,0] -y, t, x, uout = lsim(sys,u,t;x0=x0) # Continuous time +y, t, x, uout = lsim(sys,u,t,x0=x0) # Continuous time th = 1e-6 @test sum(abs.(x[end,:])) < th