DoubleIntervalDerivativeMatrix.java

/**
 * Copyright (C) 2021 MKLab.org (Koga Laboratory)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.mklab.cga.derivative;

import org.mklab.cga.interval.matrix.DoubleComplexIntervalMatrix;
import org.mklab.cga.interval.matrix.DoubleIntervalMatrix;
import org.mklab.cga.interval.scalar.DoubleComplexIntervalNumber;
import org.mklab.cga.interval.scalar.DoubleIntervalNumber;
import org.mklab.nfc.matrix.DoubleComplexMatrix;
import org.mklab.nfc.matrix.DoubleMatrix;
import org.mklab.nfc.scalar.DoubleComplexNumber;
import org.mklab.nfc.scalar.DoubleNumber;

/**
 * @author koga
 * @version $Revision$, 2021/09/10
 */
public class DoubleIntervalDerivativeMatrix extends AbstractIntervalDerivativeRealMatrix<DoubleIntervalDerivativeNumber,DoubleIntervalDerivativeMatrix,DoubleComplexIntervalDerivativeNumber,DoubleComplexIntervalDerivativeMatrix,DoubleIntervalNumber,DoubleIntervalMatrix,DoubleComplexIntervalNumber,DoubleComplexIntervalMatrix,DoubleNumber,DoubleMatrix,DoubleComplexNumber,DoubleComplexMatrix> {

  /** */
  private static final long serialVersionUID = 1L;

  /**
   * Creates {@link DoubleIntervalDerivativeMatrix}.
   * @param elements elements
   */
  public DoubleIntervalDerivativeMatrix(DoubleIntervalDerivativeNumber[][] elements) {
    super(elements);
  }

  /**
   * Creates {@link DoubleIntervalDerivativeMatrix}.
   * @param elements elements
   */
  public DoubleIntervalDerivativeMatrix(DoubleIntervalDerivativeNumber[] elements) {
    super(elements);
  }

  /**
   * Creates {@link DoubleIntervalDerivativeMatrix}.
   * @param rowSize row size
   * @param columnSize column size
   * @param elements elements
   */
  public DoubleIntervalDerivativeMatrix(int rowSize, int columnSize, DoubleIntervalDerivativeNumber[][] elements) {
    super(rowSize, columnSize, elements);
  }

  /**
   * Creates {@link DoubleIntervalDerivativeMatrix}.
   * @param matrix matrix
   */
  public DoubleIntervalDerivativeMatrix(DoubleIntervalMatrix matrix) {
    this(createDerivativeElements(matrix));
  }

  /**
   * Creates {@link DoubleIntervalDerivativeMatrix}.
   * @param x x
   * @param dx dx
   */
  public DoubleIntervalDerivativeMatrix(DoubleIntervalMatrix x, DoubleIntervalMatrix dx) {
    this(createDerivativeElements(x, dx));
  }

  
  /**
   * {@inheritDoc}
   */
  public DoubleIntervalDerivativeMatrix create(DoubleIntervalMatrix matrix) {
    return new DoubleIntervalDerivativeMatrix(matrix);
  }

  /**
   * {@inheritDoc}
   */
  public DoubleIntervalDerivativeMatrix create(DoubleIntervalMatrix x, DoubleIntervalMatrix dx) {
    return new DoubleIntervalDerivativeMatrix(x, dx);
  }
  
  /**
   * Creates interval derivative elements.
   * 
   * @param matrix matrix
   * @return interval derivative elements
   */
  private static DoubleIntervalDerivativeNumber[][] createDerivativeElements(DoubleIntervalMatrix matrix) {
    int rowSize = matrix.getRowSize();
    int columnSize = matrix.getColumnSize();
    
    DoubleIntervalDerivativeNumber[][] elements = new DoubleIntervalDerivativeNumber[rowSize][columnSize];
    for (int i = 0; i < rowSize; i++) {
      for (int j = 0; j < columnSize; j++) {
        elements[i][j] = new DoubleIntervalDerivativeNumber(matrix.getElement(i+1, j+1));
      }
    }
    return elements;
  }

  /**
   * Creates interval derivative elements.
   * 
   * @param x x
   * @param dx dx
   * @return interval derivative elements
   */
  private static DoubleIntervalDerivativeNumber[][] createDerivativeElements(DoubleIntervalMatrix x, DoubleIntervalMatrix dx) {
    int rowSize = x.getRowSize();
    int columnSize = x.getColumnSize();
    DoubleIntervalDerivativeNumber[][] elements = new DoubleIntervalDerivativeNumber[rowSize][columnSize];
    for (int i = 0; i < rowSize; i++) {
      for (int j = 0; j < columnSize; j++) {
        elements[i][j] = new DoubleIntervalDerivativeNumber(x.getElement(i+1, j+1), dx.getElement(i+1, j+1));
      }
    }
    return elements;
  }
}