UnitLeadSystem.java

/*
 * Created on 2012/05/17
 * Copyright (C) 2012 Koga Laboratory. All rights reserved.
 *
 */
package org.mklab.tool.control.system.discrete;

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;


/**
 * 
 * 1サンプル進みを表わすクラスです。
 * @author esumi
 * @version $Revision$, 2012/05/17
 * @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 UnitLeadSystem<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 DiscreteLinearDynamicSystem<RS,RM,CS,CM> {
  
  /**
   * 新しく生成された<code>UnitDelaySystem</code>オブジェクトを初期化します。
   * @param sunit unit of scalar
   */
  public UnitLeadSystem(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));
      RS[][] aa = this.sunit.createArray(2, 2);
      aa[0][0] = this.sunit.create(0);
      aa[0][1] = this.sunit.create(1);
      aa[1][0] = this.sunit.create(-1);
      aa[1][1] = this.sunit.create(0);
      RM a = this.sunit.createGrid(aa);

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

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

      RS[][] dd = this.sunit.createArray(1,1);
      dd[0][0] = this.sunit.create(0);
      RM d = this.sunit.createGrid(dd);

      RS[][] ee = this.sunit.createArray(2, 2);
      ee[0][0] = this.sunit.create(1);
      ee[0][1] = this.sunit.create(0);
      ee[1][0] = this.sunit.create(0);
      ee[1][1] = this.sunit.create(0);
      RM e = this.sunit.createGrid(ee);

      setLinearSystem(LinearSystemFactory.createLinearSystem(a, b, c, d, e));
    }
  }

  /**
   * @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));
      
      RS[][] aa = this.sunit.createArray(2, 2);
      aa[0][0] = this.sunit.create(0);
      aa[0][1] = this.sunit.create(1);
      aa[1][0] = this.sunit.create(-1);
      aa[1][1] = this.sunit.create(0);
      RM a = this.sunit.createGrid(aa);

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

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

      RS[][] dd = this.sunit.createArray(1,1);
      dd[0][0] = this.sunit.create(0);
      RM d = this.sunit.createGrid(dd);

      RS[][] ee = this.sunit.createArray(2, 2);
      ee[0][0] = this.sunit.create(1);
      ee[0][1] = this.sunit.create(0);
      ee[1][0] = this.sunit.create(0);
      ee[1][1] = this.sunit.create(0);
      RM e = this.sunit.createGrid(ee);

      setLinearSystem(LinearSystemFactory.createLinearSystem(a, b, c, d, e));
    }
  }

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

    final int size = initialState.length();

    if (getStateSize() != size) {
      setStateSize(size);
      
      RS[][] aa = this.sunit.createArray(2, 2);
      aa[0][0] = this.sunit.create(0);
      aa[0][1] = this.sunit.create(1);
      aa[1][0] = this.sunit.create(-1);
      aa[1][1] = this.sunit.create(0);
      RM a = this.sunit.createGrid(aa);

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

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

      RS[][] dd = this.sunit.createArray(1,1);
      dd[0][0] = this.sunit.create(0);
      RM d = this.sunit.createGrid(dd);

      RS[][] ee = this.sunit.createArray(2, 2);
      ee[0][0] = this.sunit.create(1);
      ee[0][1] = this.sunit.create(0);
      ee[1][0] = this.sunit.create(0);
      ee[1][1] = this.sunit.create(0);
      RM e = this.sunit.createGrid(ee);

      setLinearSystem(LinearSystemFactory.createLinearSystem(a, b, c, d, e));
    }

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

    
}