// Integrators
for (int i = 0; i < n; i++) {
integrators[i] = new Integrator(this, "state_" + i);
integrators[i].initialState.setExpression("initialStates(0,"
+ i + ")");
states[i] = new TypedIORelation(this, "relation_state_" + i);
integrators[i].output.link(states[i]);
// One adder per integrator.
stateAdders[i] = new AddSubtract(this, "stateAdder_" + i);
connect(stateAdders[i].output, integrators[i].input);
stateOutput.link(states[i]);
}
// State feedback
Scale[][] feedback = new Scale[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
// We don't create the Scale if the corresponding element
// in the A matrix is 0.
feedback[i][j] = new Scale(this, "feedback_" + i + "_" + j);
feedback[i][j].factor.setExpression("A(" + i + ", " + j
+ ")");
feedback[i][j].input.link(states[j]);
connect(feedback[i][j].output, stateAdders[i].plus);
}
}
// Inputs
Scale[][] inputScales = new Scale[n][m];
IORelation[] inputs = new IORelation[m];
for (int j = 0; j < m; j++) {
inputs[j] = new TypedIORelation(this, "relation_input_" + j);
input.link(inputs[j]);
// Create input scales.
for (int i = 0; i < n; i++) {
// We create a scale for each input even if the