-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
51 lines (37 loc) · 1.33 KB
/
Copy pathProgram.cs
File metadata and controls
51 lines (37 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using CatLab.blockat;
using CatLab.blockat.blocks;
using CatLab.catlab.catlabscript;
using CatLab.catlab.plot;
namespace CatLab.catlab;
public class Program
{
public static void Main(string[] args)
{
CatLabScript.run("example.js");
}
public void controlExample()
{
LTI sys = new LTI();
sys.A = new Matrix(2, 2) { Content = [3, 1, 2, -4] };
sys.B = new Matrix([0, 1]);
Matrix K = Control.place(sys, [-2, -2]);
Simulation sim = new Simulation();
Integrator integrator = new Integrator(sim, new Matrix([2, 1]));
LTISystem system = new LTISystem(sim, sys);
Gain gain = new Gain(sim, -K);
Output output = new Output(sim);
system.bindToInput(0, integrator, 0);
system.setOutputDims(0,1,2);
integrator.bindToInput(0, system, 0);
integrator.bindToInput(0, gain, 0);
integrator.setOutputDims(0,1,2);
gain.bindToInput(0, system, 1);
integrator.bindToInput(0, output, 0);
Console.Out.WriteLine("running sim!");
sim.run();
Console.Out.WriteLine("sim done!");
Console.Out.WriteLine(output.getSteadyState());
Plotting.Plot(output.t,output.y);
Console.Out.WriteLine("plotted!");
}
}