Exemple #1
0
returnValue ShootingMethod::differentiateBackward( const int    &idx ,
                                                   const Matrix &seed,
                                                         Matrix &Gx  ,
                                                         Matrix &Gp  ,
                                                         Matrix &Gu  ,
                                                         Matrix &Gw    ){

    uint run1;

    Gx.init( seed.getNumRows(), nx );
    Gp.init( seed.getNumRows(), np );
    Gu.init( seed.getNumRows(), nu );
    Gw.init( seed.getNumRows(), nw );

    for( run1 = 0; run1 < seed.getNumRows(); run1++ ){

         Vector tmp = seed.getRow( run1 );
         Vector tmpX( nx );
         Vector tmpP( np );
         Vector tmpU( nu );
         Vector tmpW( nw );

         ACADO_TRY( integrator[idx]->setBackwardSeed( 1, tmp )                              );
         ACADO_TRY( integrator[idx]->integrateSensitivities( )                              );
         ACADO_TRY( integrator[idx]->getBackwardSensitivities( tmpX, tmpP, tmpU, tmpW , 1 ) );

         Gx.setRow( run1, tmpX );
         Gp.setRow( run1, tmpP );
         Gu.setRow( run1, tmpU );
         Gw.setRow( run1, tmpW );
    }

    return SUCCESSFUL_RETURN;
}
Exemple #2
0
returnValue PlotWindow::addSubplot(	const Expression& _expressionX,
									const Expression& _expressionY,
									const char* const _title,
									const char* const _xLabel,
									const char* const _yLabel,
									PlotMode _plotMode,
									double _xRangeLowerLimit,
									double _xRangeUpperLimit,
									double _yRangeLowerLimit,
									double _yRangeUpperLimit
									)
{

    ASSERT( _expressionX.getDim() == _expressionY.getDim() );

    uint run1;

    for( run1 = 0; run1 < _expressionX.getDim(); run1++ ){

		PlotWindowSubplot* newSubplot = new PlotWindowSubplot(	_expressionX(run1),_expressionY(run1),
																_title,_xLabel,_yLabel,_plotMode,
																_xRangeLowerLimit,_xRangeUpperLimit,
																_yRangeLowerLimit,_yRangeUpperLimit );

		if ( number == 0 )
		{
			first = newSubplot;
			last = newSubplot;
		}
		else
		{
			if ( last->setNext( newSubplot ) != SUCCESSFUL_RETURN )
				return ACADOERROR( RET_OPTIONS_LIST_CORRUPTED );
			last = newSubplot;
		}

        Expression tmpX( _expressionX(run1) );

		if ( addPlotDataItem( &tmpX ) != SUCCESSFUL_RETURN )
			return ACADOERROR( RET_LOG_RECORD_CORRUPTED );

        Expression tmpY( _expressionY(run1) );

		if ( addPlotDataItem( &tmpY ) != SUCCESSFUL_RETURN )
			return ACADOERROR( RET_LOG_RECORD_CORRUPTED );

		++number;
    }

	return SUCCESSFUL_RETURN;
}
void quotRemainder(const BigReal &x,  const BigReal &y, BigInt *quotient, BigReal *remainder) {
  DEFINEMETHODNAME;
  if(y.isZero()) {
    throwBigRealInvalidArgumentException(method, _T("Division by zero. (%s / 0)."), x.toString().cstr());
  }
  if(quotient == remainder) { // also takes care of the stupid situation where both are NULL
    throwBigRealInvalidArgumentException(method, _T("quotient is the same variable as remainder"));
  }
  if(quotient == &x || quotient == &y) {
    throwBigRealInvalidArgumentException(method, _T("quotient cannot be the same variable as x or y"));
  }
  if(remainder == &x || remainder == &y) {
    throwBigRealInvalidArgumentException(method, _T("remainder cannot be the same variable as x or y"));
  }

  if(x.isZero()) {
    if(quotient ) quotient->setToZero();
    if(remainder) remainder->setToZero();
    return;
  }

  DigitPool *pool = x.getDigitPool();
  const int cmpAbs = compareAbs(x, y);
  if(cmpAbs < 0) {
    if(remainder) *remainder = x;
    if(quotient)  quotient->setToZero();
    return;
  } else if(cmpAbs == 0) {
    if(remainder) remainder->setToZero();
    if(quotient) {
      *quotient = quotient->getDigitPool()->get1();
    }
    return;
  }

  BigReal tmpX(x);
  tmpX.setPositive();
  BigReal tmpY(y);
  tmpY.setPositive();
  BigInt q   = floor(quot(tmpX, tmpY, modulusC1));
  BigReal mod = tmpX - q * tmpY;

  if(mod.isNegative()) {
    if(remainder) {
      *remainder = mod + tmpY;
    }
    if(quotient) {
      --q;
      *quotient = q;
    }
  } else if(mod >= tmpY) {
    if(remainder) {
      *remainder = mod - tmpY;
    }
    if(quotient) {
      ++q;
      *quotient = q;
    }
  } else {
    if(remainder) {
      *remainder = mod;
    }
    if(quotient) {
      *quotient = q;
    }
  }

  if(remainder && (remainder->m_negative != x.m_negative)) {
    remainder->m_negative = x.m_negative; // sign(x % y) = sign(x), equivalent to build-in % operator
  }
}