Пример #1
0
/***
 * FUNCTION: Integrates equation using Simpson method
 *   RETURN: Definite integral of equation
 *    PARAM: [IN] equation      - equation to integrate
 *    PARAM: [IN] start         - left integration border
 *    PARAM: [IN] end           - right integration border
 *    PARAM: [IN] numIterations - number of iterations
 *      SEE: write me
 *   AUTHOR: Eliseev Dmitry
 ***/
Equation ParametricIntegrator::Simpson( const Equation &equation, const double start, const double end, const unsigned int numIterations )
{
  unsigned int i = 0;

  /* Timer creation */
  Timer timer;

  /* Result equation */
  Equation result = Equation(start) + Equation(end);

  /* Odd members */
  Equation oddResult("0");
  for (i = 1; i <= 2 * numIterations - 1; i+=2)
    oddResult += equation.GetEquation(start + (end - start) * i / (2 * numIterations));

  /* Even members */
  Equation evenResult("0");
  for (i = 2; i <= 2 * numIterations - 2; i+=2)
    evenResult += equation.GetEquation(start + (end - start) * i / (2 * numIterations));

  /* Add calculated values */
  result += Equation("4") * oddResult + Equation("2") * evenResult;

  /* That's it */
  result *= Equation((end - start) / (6 * numIterations));
  result.Simplify();

  /* Determine spent time */
  numSeconds = timer.GetTimePassed();
  return result;
} /* End of 'Integrator::Simpson' method */
Пример #2
0
int main(int argc, char** argv)
{
	Equation e1[2] = {Equation(-2.0, 1.0, -1.0), Equation(0.0, 0.0, 1.0)};
	Equation e2(0.0, 1.0, 0.0);
	std::cout << "---------------test1-----------------\n";
	std::cout << "[" << e1[0] << " /\\ "<< e1[1] << "]\t==>\t[" << e2 << "]? ";
	int ret = Equation::multi_imply(e1, 2, e2);
	switch(ret) {
		case 0: std::cout << "False\n"; break;
		case 1: std::cout << "True\n"; break;
		case 2: std::cout << "Could not answer query\n"; break;
		case 3: std::cout << "Timeout.\n"; break;
		default: std::cout << "Unhandled error\n";
	}
	
	/*
	Equation e3[2] = {Equation(-2.0, 1.0), Equation(5.0, -1.0)};
	Equation e4(-1.0, 1.0);
	std::cout << "---------------test2-----------------\n";
	std::cout << "[" << e3[0] << " /\\ "<< e3[1] << "]\t==>\t[" << e4 << "]? ";
	ret = Equation::multi_imply(e3, 2, e4);
	switch(ret) {
		case 0: std::cout << "False\n"; break;
		case 1: std::cout << "True\n"; break;
		case 2: std::cout << "Could not answer query\n"; break;
		case 3: std::cout << "Timeout.\n"; break;
		default: std::cout << "Unhandled error\n";
	}


	Equation e5[2] = {Equation(-2.0, 1.0), Equation(5.0, -1.0)};
	Equation e6(-3.0, 1.0);
	std::cout << "---------------test2-----------------\n";
	std::cout << "[" << e5[0] << " /\\ "<< e5[1] << "]\t==>\t[" << e6 << "]? ";
	ret = Equation::multi_imply(e5, 2, e6);
	switch(ret) {
		case 0: std::cout << "False\n"; break;
		case 1: std::cout << "True\n"; break;
		case 2: std::cout << "Could not answer query\n"; break;
		case 3: std::cout << "Timeout.\n"; break;
		default: std::cout << "Unhandled error\n";
	}
	*/
	return 0;
}
Пример #3
0
Equation Equation::randomQuadraticEquation( int nGen , int nVar , int len )
{
  int l = len+2*nVar;
  vector< int > result( l , 0 );
  
  // assign positions to variables
  for( int v=0 ; v<nVar ; ++v ) {    // for all variables
    for( int p=0 ; p<2 ; ++p ) {     // for each variable twice

      // loop until the position and power for a variable is found
      bool posFound = false;
      while( !posFound ) {
	int pos = RandLib::ur.irand( 0 , l-1 );
	if( result[pos]!=0 )
	  continue;
	
	int l_pos = pos==0 ? l-1 : pos-1;
	int r_pos = pos==l-1 ? 0 : pos+1;
	
	int var = RandLib::ur.irand( 0 , 1 ) ? v+nGen+1 : -v-nGen-1;
	if( result[l_pos]+var==0 || result[r_pos]+var==0 )
	  continue;
	result[pos] = var;
	posFound = true;
      }
    }
  }
  
  
  for( int pos=0 ; pos<l ; ++pos ) {
    
    if( result[pos]!=0 )
      continue;
    
    int l_pos = pos==0 ? l-1 : pos-1;
    int r_pos = pos==l-1 ? 0 : pos+1;
    
    while( 1 ) {
      int gen = RandLib::ur.irand( 0 , nGen-1 );
      gen = RandLib::ur.irand( 0 , 1 ) ? gen+1 : -gen-1;
      if( result[l_pos]+gen==0 || result[r_pos]+gen==0 )
	continue;
      result[pos] = gen;
      break;
    }
    
  }
  
  return Equation( nGen , nVar , Word(result) );
}
Equation instantiate_equation(Equation innerEq, Name variable, Real index, VarSymbolTable &symbolTable) {
  VarSymbolTable v=symbolTable;
  VarInfo vinfo = VarInfo(TypePrefixes(1,parameter), "Integer", Option<Comment>(), Modification(ModEq(Expression(index))));
  v.insert(variable,vinfo);
  if (is<Equality>(innerEq)) {
      Equality eqeq = boost::get<Equality>(innerEq);
      Expression l=eqeq.left(), r=eqeq.right();
      //std::cout << "Left= " << l << " right " << r << std::endl;
      return Equality(Visit(Modelica::PartEvalExp(v),l),Visit(Modelica::PartEvalExp(v),r));
  } else {
      ERROR("process_for_equations - instantiate_equation:\n"
            "Incorrect equation type or not supported yet.\n");
  }
  return Equation();
}
void CsFiringRateStimulus::Load(CStdXml &oXml)
{
	ExternalStimulus::Load(oXml);

	oXml.IntoElem();  //Into Simulus Element

	TargetNodeID(oXml.GetChildString("TargetNodeID"));

	ConstantRate(oXml.GetChildFloat("ConstantRate", m_fltConstantRate));
	Equation(oXml.GetChildString("Equation", ""));
	Coverage(oXml.GetChildString("Coverage", "WholePopulation"));

	if(oXml.FindChildElement("Cells", false))
		LoadCellsToStim(oXml);

	oXml.OutOfElem(); //OutOf Simulus Element
}
int main(){
	double a;
	double b;
	double c;
	double x;

	printf("Compute \"ax+b=c\"¡ú_¡ú\nPlease input a:");
	scanf("%lf", &a);
	printf("Please input b:");
	scanf("%lf", &b);
	printf("Please input c:");
	scanf("%lf", &c);

	if (a == 0){
		printf("\n\tError!");
	}
	else{
		x = Equation(a, b, c);
		printf("\t\t%.10gx+%.10g=%.10g\n\t\tx=%.10g", a, b, c, x);
	}
}
bool CsFiringRateStimulus::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
{
	std::string strType = Std_CheckString(strDataType);

	if(ExternalStimulus::SetData(strDataType, strValue, false))
		return true;

	if(strType == "CONSTANTRATE")
	{
		ConstantRate((float) atof(strValue.c_str()));
		return true;
	}

	if(strType == "COVERAGE")
	{
		Coverage(strValue);
		return true;
	}

	if(strType == "EQUATION")
	{
		Equation(strValue);
		return true;
	}

	if(strType == "CELLSTOSTIM")
	{
		CellsToStim(strValue);
		return true;
	}

	//If it was not one of those above then we have a problem.
	if(bThrowError)
		THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);

	return false;
}
Пример #8
0
	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();
		//
		auto camera = CamMatrixf::Orbiting(
			Vec3f(),
			5.5,
			FullCircles(time / 10.0),
			Degrees(45.0 + SineWave(time / 7.0)*30.0)
		);

		// Render the plane
		plane_prog.Use();
		plane_camera_matrix.Set(camera);

		plane_model_matrix.Set(
			ModelMatrixf::Translation(0.0f, -1.1f, 0.0f)
		);

		gl.Bind(plane);
		plane_instr.Draw(plane_indices);


		// Render the shape
		shape_prog.Use();

		auto clip_plane = Planef::FromNormal(Vec3f(Data(camera.Row(2)), 3));

		shape_clip_plane.Set(clip_plane.Equation());

		shape_camera_matrix.Set(camera);

		shape_model_matrix.Set(
			ModelMatrixf::RotationX(FullCircles(time / 12.0))
		);

		gl.Bind(shape);

		gl.Enable(Capability::CullFace);
		gl.Enable(Functionality::ClipDistance, 0);

		gl.FrontFace(make_shape.FaceWinding());

		GLfloat clip_dirs[2] = {-1.0f, 1.0f};
		Face facing_dirs[2] = {Face::Front, Face::Back};

		for(int c=0; c!=2; ++c)
		{
			shape_clip_direction.Set(clip_dirs[c]);
			for(int f=0; f!=2; ++f)
			{
				Texture::CopyImage2D(
					Texture::Target::_2D,
					0,
					PixelDataInternalFormat::RGB,
					tex_side == width ? 0 : (width - tex_side) / 2,
					tex_side == height? 0 : (height- tex_side) / 2,
					tex_side, tex_side,
					0
				);
				gl.CullFace(facing_dirs[f]);
				shape_instr.Draw(shape_indices);
			}
		}

		gl.Disable(Functionality::ClipDistance, 0);
		gl.Disable(Capability::CullFace);
	}