+ 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
// corresponding element in B is 0. Otherwise,
// if the elements of A's in this row are also zero,
// then we will have an illegal topology.
inputScales[i][j] = new Scale(this, "b_" + i + "_" + j);
inputScales[i][j].factor.setExpression("B(" + i + ", " + j
+ ")");
inputScales[i][j].input.link(inputs[j]);
connect(inputScales[i][j].output, stateAdders[i].plus);
}
}
// Outputs
AddSubtract[] outputAdders = new AddSubtract[r];
Scale[][] outputScales = new Scale[r][n];
for (int l = 0; l < r; l++) {
outputAdders[l] = new AddSubtract(this, "outputAdder" + l);
connect(outputAdders[l].output, output);
// Create the output scales only if the corresponding
// 'c' element is not 0.
for (int i = 0; i < n; i++) {