DerivativeSystem.java

package org.mklab.tool.control.system.continuous;

import org.mklab.nfc.matrix.ComplexNumericalMatrix;
import org.mklab.nfc.matrix.RealNumericalMatrix;
import org.mklab.nfc.scalar.ComplexNumericalScalar;
import org.mklab.nfc.scalar.RealNumericalScalar;
import org.mklab.tool.control.LinearSystemFactory;

/**
 * 微分器を表すクラスです
 * 
 * @author esumi
 * @param <RS> type of real scalar
 * @param <RM> type of real matrix
 * @param <CS> type of complex scalar
 * @param <CM> type of complex matrix
 * 
 */
public class DerivativeSystem<RS extends RealNumericalScalar<RS,RM,CS,CM>, RM extends RealNumericalMatrix<RS,RM,CS,CM>, CS extends ComplexNumericalScalar<RS,RM,CS,CM>, CM extends ComplexNumericalMatrix<RS,RM,CS,CM>> extends ContinuousLinearDynamicSystem<RS,RM,CS,CM> {
  
  /**
   * 新しく生成された<code>TDerivativeSystem</code>オブジェクトを初期化します。
   * @param sunit unit of scalar
   */
  public DerivativeSystem(RS sunit) {
    super(sunit);
    setAutoSize(false);
  }

  /**
   * @see org.mklab.tool.control.system.SystemOperator#setInputSize(int)
   */
  @Override
  public void setInputSize(final int size) {
    if (size < 0) {
      return;
    }

    super.setInputSize(size);
    super.setOutputSize(size);

    if (getStateSize() != size) {
      setStateSize(size);
      super.setInitialState(this.sunit.createZeroGrid(size, 1));
      setSystem();
    }
  }

  /**
   * @see org.mklab.tool.control.system.SystemOperator#setOutputSize(int)
   */
  @Override
  public void setOutputSize(final int size) {
    if (size < 0) {
      return;
    }

    super.setInputSize(size);
    super.setOutputSize(size);

    if (getStateSize() != size) {
      setStateSize(size);
      super.setInitialState(this.sunit.createZeroGrid(size, 1));
      setSystem();
    }
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public void setInitialState(RM initialState) {
    super.setInitialState(initialState);

    final int size = initialState.length();

    if (getStateSize() != size) {
      setStateSize(size);
      setSystem();
    }

    setInputSize(initialState.length());
    setOutputSize(initialState.length());
  }

  private void setSystem() {
    RS [][] aa = this.sunit.createArray(2, 2);
    aa[0][0] = this.sunit.createZero();
    aa[0][1] = this.sunit.createUnit();
    aa[1][0] = this.sunit.createUnit().unaryMinus();
    aa[1][1] = this.sunit.createZero();
    RM a = this.sunit.createGrid(aa);

    RS[][] bb = this.sunit.createArray(2, 1);
    bb[0][0] = this.sunit.createZero();
    bb[1][0] = this.sunit.createUnit();
    RM b = this.sunit.createGrid(bb);

    RS[][] cc =  this.sunit.createArray(1, 2);
    cc[0][0] = this.sunit.createZero();
    cc[0][1] = this.sunit.createUnit();
    RM c = this.sunit.createGrid(cc);

    RS[][] dd = this.sunit.createArray(1, 1);
    dd[0][0] = this.sunit.createZero();
    RM d = this.sunit.createGrid(dd);
    
    RS[][] ee = this.sunit.createArray(2, 2);
    ee[0][0] = this.sunit.createUnit();
    ee[0][1] = this.sunit.createZero();
    ee[1][0] = this.sunit.createZero();
    ee[1][1] = this.sunit.createZero();
    RM e = this.sunit.createGrid(ee);
    
    setLinearSystem(LinearSystemFactory.createLinearSystem(a, b, c, d, e));
  }



}