DoubleAbsoluteFunction.java
/*
* $Id: AbsoluteFunction.java,v 1.9 2008/06/26 10:10:34 koga Exp $
*
* Copyright (C) 2004 Koga Laboratory. All rights reserved.
*
*/
package org.mklab.tool.control.system.math;
import java.util.ArrayList;
import java.util.List;
import org.mklab.nfc.matrix.DoubleMatrix;
import org.mklab.nfc.ode.DoublePiecewiseContinuousAlgebraicSystem;
import org.mklab.nfc.ode.PiecewiseUtil;
import org.mklab.tool.control.system.continuous.DoubleBaseContinuousStaticSystem;
/**
* 入力の絶対値を出力するシステムを表わすクラスです。
*
* @author Koga Laboratory
* @version $Revision: 1.9 $, 2004/11/12
*/
public class DoubleAbsoluteFunction extends DoubleBaseContinuousStaticSystem implements DoublePiecewiseContinuousAlgebraicSystem {
/**
* 新しく生成された<code>AbsoluteFunction</code>オブジェクトを初期化します。
*/
public DoubleAbsoluteFunction() {
super(-1, -1);
setAutoSize(true);
setHasDirectFeedthrough(true);
}
/**
* {@inheritDoc}
*/
@Override
public DoubleMatrix outputEquation( final double t, final DoubleMatrix u) {
return u.absElementWise();
}
/**
* {@inheritDoc}
*/
@SuppressWarnings("boxing")
public List<Integer> getPiece( final double t, final DoubleMatrix u) {
final int size = u.getRowSize();
final List<Integer> pieces = new ArrayList<>(size);
for (int i = 1; i <= size; i++) {
if (u.getDoubleElement(i) < 0) {
pieces.add(0);
} else {
pieces.add(1);
}
}
return pieces;
}
/**
* {@inheritDoc}
*/
public double getDiscontinuousPoint(final double t1, final DoubleMatrix u1, final double t2, final DoubleMatrix u2) {
final List<Integer> pieces1 = getPiece(t1, u1);
final List<Integer> pieces2 = getPiece(t2, u2);
if (pieces1.equals(pieces2)) {
return Double.NaN;
}
final int number = PiecewiseUtil.getDistinctPiece(pieces1, pieces2);
final double uu1 = u1.getDoubleElement(number);
final double uu2 = u2.getDoubleElement(number);
return t1 + (0 - uu1) / (uu2 - uu1) * (t2 - t1);
}
/**
* @see org.mklab.tool.control.system.SystemOperator#setInputSize(int)
*/
@Override
public void setInputSize(final int size) {
super.setInputSize(size);
super.setOutputSize(size);
}
/**
* @see org.mklab.tool.control.system.SystemOperator#setOutputSize(int)
*/
@Override
public void setOutputSize(final int size) {
super.setInputSize(size);
super.setOutputSize(size);
}
}