XsinYcos2D constructor

XsinYcos2D(int nrows, int ncols, double xstart, double ystart)

Computes the function f(x,y)=xsin(y)+ycos(x). Returns a 2D array with nrows rows and ncols columns. The function is computed at the x,y-positions xColCoordinates and yRowCoordinates (which can be accessed via the respective getters) ranging from -xstart to xstart, and -ystart and ystart, respectively. The start coodinates must be specified in radians (1 rad= 360 degr / 2*pi).

Implementation

XsinYcos2D(int nrows, int ncols, double xstart, double ystart) {
  _matrix = List<Float64List>(nrows); // the matrix
  _xColCoord = Float64List(ncols); // its col coordinates
  _yRowCoord = Float64List(nrows); // its row coordinates

  double x, y;
  for (int i = 0; i < nrows; i++) {
    _matrix[i] = Float64List(ncols);
    y = ystart * (-1.0 + 2 * i / (nrows - 1));
    _yRowCoord[i] = i / (nrows - 1); // normalize to 0.0 ... 1.0
    for (int k = 0; k < ncols; k++) {
      x = xstart * (-1.0 + 2 * k / (ncols - 1));
      _matrix[i][k] = x * math.sin(y) - y * math.cos(x);
      _xColCoord[k] = k / (ncols - 1); // normalize to 0.0 ... 1.0
    }
  }
}