calculateQWhiteNoise method

Matrix calculateQWhiteNoise(
  1. int dim,
  2. double dt,
  3. double variable,
  4. int blockSize,
  5. bool orderByDim,
)

Implementation

Matrix calculateQWhiteNoise(
    int dim, double dt, double variable, int blockSize, bool orderByDim) {
  List<Vector> q = [];
  assert(dim > 1 && dim < 5);

  if (dim == 2) {
    q.add(Vector.fromList([0.25 * pow(dt, 4), 0.5 * pow(dt, 3)]));
    q.add(Vector.fromList([0.5 * pow(dt, 3), pow(dt, 2)]));
  } else if (dim == 3) {
    q.add(Vector.fromList(
        [0.25 * pow(dt, 4), 0.5 * pow(dt, 3), 0.5 * pow(dt, 2)]));
    q.add(Vector.fromList([0.5 * pow(dt, 3), pow(dt, 2), dt]));
    q.add(Vector.fromList([0.5 * pow(dt, 2), dt, 1]));
  } else {
    q.add(Vector.fromList(
        [pow(dt, 6) / 36, pow(dt, 5) / 12, pow(dt, 4) / 6, pow(dt, 3) / 6]));
    q.add(Vector.fromList(
        [pow(dt, 5) / 12, pow(dt, 4) / 4, pow(dt, 3) / 2, pow(dt, 2) / 2]));
    q.add(Vector.fromList([pow(dt, 4) / 6, pow(dt, 3) / 2, pow(dt, 2), dt]));
    q.add(Vector.fromList([pow(dt, 3) / 6, pow(dt, 2) / 2, dt, 1]));
  }

  if (orderByDim) {
    List qList = [];
    for (int i = 0; i < blockSize; i++) {
      qList.add(q);
    }

    return blockDiag(qList) * variable;
  } else {
    return orderByDerivative(Matrix.fromRows(q), dim, blockSize) * variable;
  }
}