-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use imports consequently in Examples.StateSpace
- Loading branch information
Showing
22 changed files
with
338 additions
and
467 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 49 additions & 60 deletions
109
Modelica_LinearSystems2/Examples/StateSpace/analysisImpulseResponse.mo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,49 @@ | ||
within Modelica_LinearSystems2.Examples.StateSpace; | ||
function analysisImpulseResponse "Impulse response example" | ||
extends Modelica.Icons.Function; | ||
|
||
import Modelica_LinearSystems2.StateSpace; | ||
|
||
protected | ||
Modelica_LinearSystems2.StateSpace sc=Modelica_LinearSystems2.StateSpace( | ||
A=[-1,1; 0,-2], | ||
B=[4,0; 0,2], | ||
C=[2,0; 0,3], | ||
D=[0,0; 0,0]); | ||
|
||
Real t[:] "Time vector: (number of samples)"; | ||
Real x_continuous[:,size(sc.A, 1),size(sc.B, 2)] | ||
"State trajectories: (number of samples) x (number of states) x (number of inputs)"; | ||
|
||
public | ||
output Real y[:,size(sc.C, 1),size(sc.B, 2)] | ||
"Output response: (number of samples) x (number of outputs) x (number of inuputs)"; | ||
|
||
algorithm | ||
(y,t,x_continuous) := Modelica_LinearSystems2.StateSpace.Analysis.impulseResponse(sc=sc,dt=0.1,tSpan=5); | ||
|
||
Modelica_LinearSystems2.Utilities.Plot.diagramVector({ | ||
Modelica_LinearSystems2.Utilities.Plot.Records.Diagram( | ||
curve={ | ||
Modelica_LinearSystems2.Utilities.Plot.Records.Curve( | ||
x=t, | ||
y=y[:,1,1], | ||
legend="y1"), | ||
Modelica_LinearSystems2.Utilities.Plot.Records.Curve( | ||
x=t, | ||
y=y[:,2,1], | ||
legend="y2")}, | ||
heading="Impulse response to u1", | ||
xLabel="time [s]", | ||
yLabel="y1, y2"), | ||
Modelica_LinearSystems2.Utilities.Plot.Records.Diagram( | ||
curve={ | ||
Modelica_LinearSystems2.Utilities.Plot.Records.Curve( | ||
x=t, | ||
y=y[:,1,2], | ||
legend="y1"), | ||
Modelica_LinearSystems2.Utilities.Plot.Records.Curve( | ||
x=t, | ||
y=y[:,2,2], | ||
legend="y2")}, | ||
heading="Impulse response to u2", | ||
xLabel="time [s]", | ||
yLabel="y1, y2")}); | ||
|
||
annotation ( | ||
__Dymola_interactive=true, | ||
Documentation(info="<html> | ||
<p> | ||
Computes and plots the impulse response of a state space system. | ||
</p> | ||
</html>")); | ||
end analysisImpulseResponse; | ||
within Modelica_LinearSystems2.Examples.StateSpace; | ||
function analysisImpulseResponse "Impulse response example" | ||
extends Modelica.Icons.Function; | ||
|
||
import Modelica_LinearSystems2.StateSpace; | ||
import Modelica_LinearSystems2.Utilities.Plot; | ||
|
||
protected | ||
StateSpace sc = StateSpace( | ||
A=[-1,1; 0,-2], | ||
B=[4,0; 0,2], | ||
C=[2,0; 0,3], | ||
D=[0,0; 0,0]); | ||
|
||
Real t[:] "Time vector: (number of samples)"; | ||
Real x_continuous[:,size(sc.A, 1),size(sc.B, 2)] | ||
"State trajectories: (number of samples) x (number of states) x (number of inputs)"; | ||
|
||
public | ||
output Real y[:,size(sc.C, 1),size(sc.B, 2)] | ||
"Output response: (number of samples) x (number of outputs) x (number of inuputs)"; | ||
|
||
algorithm | ||
(y,t,x_continuous) := StateSpace.Analysis.impulseResponse(sc=sc,dt=0.1,tSpan=5); | ||
|
||
Plot.diagramVector({ | ||
Plot.Records.Diagram( | ||
curve={ | ||
Plot.Records.Curve(x=t, y=y[:,1,1], legend="y1"), | ||
Plot.Records.Curve(x=t, y=y[:,2,1], legend="y2")}, | ||
heading="Impulse response to u1", | ||
xLabel="time [s]", | ||
yLabel="y1, y2"), | ||
Plot.Records.Diagram( | ||
curve={ | ||
Plot.Records.Curve(x=t, y=y[:,1,2], legend="y1"), | ||
Plot.Records.Curve(x=t, y=y[:,2,2], legend="y2")}, | ||
heading="Impulse response to u2", | ||
xLabel="time [s]", | ||
yLabel="y1, y2")}); | ||
|
||
annotation ( | ||
__Dymola_interactive=true, | ||
Documentation(info="<html> | ||
<p> | ||
Computes and plots the impulse response of a state space system. | ||
</p> | ||
</html>")); | ||
end analysisImpulseResponse; |
102 changes: 52 additions & 50 deletions
102
Modelica_LinearSystems2/Examples/StateSpace/analysisInitialResponse.mo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,52 @@ | ||
within Modelica_LinearSystems2.Examples.StateSpace; | ||
function analysisInitialResponse "Initial response example" | ||
extends Modelica.Icons.Function; | ||
import Modelica_LinearSystems2.StateSpace; | ||
|
||
protected | ||
Modelica_LinearSystems2.StateSpace sc=Modelica_LinearSystems2.StateSpace( | ||
A=[-1,1; 0,-2], | ||
B=[1,0; 0,1], | ||
C=[1,0; 0,1], | ||
D=[0,0; 0,0]); | ||
|
||
Real t[:] "Time vector: (number of samples)"; | ||
Real x_continuous[:,2,1] | ||
"State trajectories: (number of samples) x (number of states) x 1"; | ||
Real x0[2]=ones(2) "Initial state vector"; | ||
|
||
public | ||
output Real y[:,size(sc.C, 1),1] | ||
"Output response: (number of samples) x (number of outputs) x 1"; | ||
|
||
algorithm | ||
(y,t,x_continuous) := Modelica_LinearSystems2.StateSpace.Analysis.initialResponse(x0=x0,sc=sc,dt=0.1,tSpan=5); | ||
|
||
Modelica_LinearSystems2.Utilities.Plot.diagramVector({ | ||
Modelica_LinearSystems2.Utilities.Plot.Records.Diagram( | ||
curve={ | ||
Modelica_LinearSystems2.Utilities.Plot.Records.Curve( | ||
x=t, | ||
y=y[:,1,1], | ||
legend="y1")}, | ||
heading="Initial response y1", | ||
xLabel="time [s]"), | ||
Modelica_LinearSystems2.Utilities.Plot.Records.Diagram( | ||
curve={ | ||
Modelica_LinearSystems2.Utilities.Plot.Records.Curve( | ||
x=t, | ||
y=y[:,2,1], | ||
legend="y2")}, | ||
heading="Initial response y2", | ||
xLabel="time [s]")}); | ||
|
||
annotation ( | ||
__Dymola_interactive=true, | ||
Documentation(info="<html> | ||
<p> | ||
Computes and plots the initial response of a state space system by given initial values. | ||
</p> | ||
</html>")); | ||
end analysisInitialResponse; | ||
within Modelica_LinearSystems2.Examples.StateSpace; | ||
function analysisInitialResponse "Initial response example" | ||
extends Modelica.Icons.Function; | ||
|
||
import Modelica_LinearSystems2.StateSpace; | ||
import Modelica_LinearSystems2.Utilities.Plot; | ||
|
||
protected | ||
StateSpace sc=StateSpace( | ||
A=[-1,1; 0,-2], | ||
B=[1,0; 0,1], | ||
C=[1,0; 0,1], | ||
D=[0,0; 0,0]); | ||
|
||
Real t[:] "Time vector: (number of samples)"; | ||
Real x_continuous[:,2,1] | ||
"State trajectories: (number of samples) x (number of states) x 1"; | ||
Real x0[2]=ones(2) "Initial state vector"; | ||
|
||
public | ||
output Real y[:,size(sc.C, 1),1] | ||
"Output response: (number of samples) x (number of outputs) x 1"; | ||
|
||
algorithm | ||
(y,t,x_continuous) := StateSpace.Analysis.initialResponse(x0=x0,sc=sc,dt=0.1,tSpan=5); | ||
|
||
Plot.diagramVector({ | ||
Plot.Records.Diagram( | ||
curve={ | ||
Plot.Records.Curve( | ||
x=t, | ||
y=y[:,1,1], | ||
legend="y1")}, | ||
heading="Initial response y1", | ||
xLabel="time [s]"), | ||
Plot.Records.Diagram( | ||
curve={ | ||
Plot.Records.Curve( | ||
x=t, | ||
y=y[:,2,1], | ||
legend="y2")}, | ||
heading="Initial response y2", | ||
xLabel="time [s]")}); | ||
|
||
annotation ( | ||
__Dymola_interactive=true, | ||
Documentation(info="<html> | ||
<p> | ||
Computes and plots the initial response of a state space system by given initial values. | ||
</p> | ||
</html>")); | ||
end analysisInitialResponse; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.