int main( ){

    USING_NAMESPACE_ACADO

    DifferentialState a,b;
    TIME t;

    CFunction myFunction( 1, my_function );

    IntermediateState x(3);

    x(0) = t;
    x(1) = a;
    x(2) = b;

    Function f;
    f << myFunction( x );


    // TEST THE FUNCTION f:
    // --------------------
       int x_index, y_index;

       x_index = f.index(VT_DIFFERENTIAL_STATE,0);
       y_index = f.index(VT_DIFFERENTIAL_STATE,1);

       double *xx    = new double[f.getNumberOfVariables()+1];
       double *seed  = new double[f.getNumberOfVariables()+1];
       double *ff    = new double[f.getDim()                ];
       double *df    = new double[f.getDim()                ];

       xx[x_index] = 1.0;
       xx[y_index] = 1.0;

       seed[x_index] = 0.5;
       seed[y_index] = 0.5;


    // FORWARD DIFFERENTIATION:
    // ------------------------
       f.evaluate  ( 0, xx  , ff );
       f.AD_forward( 0, seed, df );


    // PRINT THE RESULTS:
    // ------------------
       printf("     x = %10.16e \n",   xx[x_index] );
       printf("     y = %10.16e \n",   xx[y_index] );
       printf("seed_x = %10.16e \n", seed[x_index] );
       printf("seed_y = %10.16e \n", seed[y_index] );
       printf("     f = %10.16e \n",   ff[0      ] );
       printf("    df = %10.16e \n",   df[0      ] );

    delete[] xx;
    delete[] seed;
    delete[] ff;
    delete[] df;

    return 0;
}
int main()
{
    String<char, SpecA> a;
    String<char, SpecB> b;
    String<char, SpecC> c;

    myFunction(a);            // calls (A)
    myFunction(b);            // calls (B)
    myFunction(c);            // calls (A)
}
Beispiel #3
0
int main()
{
  static jit_insn codeBuffer[1024];
  static jit_state _jit;

  pvfi		myFunction;		/* ptr to generated code */
  char		*start, *end;		/* a couple of labels */
  int		ofs;			/* to get the argument */

  myFunction = (pvfi) (jit_set_ip(codeBuffer).vptr);
  start = jit_get_ip().ptr;
  jit_prolog(1);
  ofs = jit_arg_i();
  jit_movi_p(JIT_R0, "looks like %d bytes sufficed\n");
  jit_getarg_i(JIT_R1, ofs);
  jit_prepare_i(2);
    jit_pusharg_i(JIT_R1);		/* push in reverse order */
    jit_pusharg_p(JIT_R0);
  jit_finish(display_message);
  jit_ret();
  end = jit_get_ip().ptr;

  jit_flush_code(codeBuffer, end);

#ifdef LIGHTNING_DISASSEMBLE
  disassemble(stderr, codeBuffer, end);
#endif
#ifndef LIGHTNING_CROSS
  /* call the generated code, passing its size as argument */
  myFunction(sizeof(codeBuffer));
#endif
  return 0;
}
Beispiel #4
0
int main(int nargs, char** args){ 
    int x,y;
    x = atoi(args[1]);
    y = myFunction(x);
    printf("x=%d, y=%d\n",x,y);
    return 0;
}
int main( )
{
   std::function< double( const double ) > myFunction =
           std::bind( &testFunction, std::placeholders::_1, 3.0 );
   std::cout<<myFunction( 1.0 )<<std::endl;
   std::cout<<( myFunction == nullptr )<<std::endl;

   std::function< double( const double ) > myFunction2;
   std::cout<<( myFunction2 == nullptr )<<std::endl;

   std::shared_ptr< TestClass > test = std::make_shared< TestClass >( 4.0 );


   std::function< Eigen::Vector3d( const std::vector< double >& ) > forceCoefficientFunction;
   std::function< Eigen::Vector3d( const std::vector< double >& ) > momentCoefficientFunction;


   std::function< Eigen::Vector6d( const std::vector< double >& ) > coefficientFunction;

   coefficientFunction = std::bind(
              &concatenateForceAndMomentCoefficients, forceCoefficientFunction, momentCoefficientFunction,
               std::placeholders::_1 );


}
void originGraph::paintEvent(QPaintEvent * /*event*/)
{
    QPainter painter(this);
    QPoint *firstP = new QPoint;        // начальная точка
    QPoint *secondP = new QPoint;   // конечная точка

    int recSizeX = 210, recSizeY = 210;  // размер прямоугольника в котором рисуем
    double multiplyX; // масштаб оси X (*)
    double multiplyY; // масштаб оси Y (*)
    int intervalXleft;      // начало оси X
    int intervalXRight;   // конец оси X
    double step = 0.01; // шаг по оси X

//  рисуем фоновый прямоугольник в котором рисуем
    painter.setBrush(Qt::black);
    painter.setPen(QPen(Qt::blue, 2));
    painter.drawRect(0, 0, recSizeY, recSizeX);

// выбираем цвет для осей
    painter.setPen(QPen(Qt::gray, 1));

// рисуем оси X и Y
    // x
    painter.drawLine(QPointF(0, recSizeY / 2), QPointF(recSizeY, recSizeY / 2));
    // y
    painter.drawLine(QPointF(recSizeX /2, 0), QPointF(recSizeX / 2, recSizeX ));

    multiplyX = 20;
    multiplyY = 5;
    painter.setPen(QPen(Qt::green, 1));        // цвет построенной функции

    intervalXleft = - 10;
    intervalXRight = 10;

    firstP->setX(recSizeX /2 + intervalXleft * multiplyX);
    firstP->setY(recSizeY / 2 -  myFunction(intervalXleft)* multiplyY);

    for (double i = intervalXleft + 1; i <= intervalXRight; i+=step) {
        secondP->setX(recSizeX /2 + i * multiplyX);
        secondP->setY(recSizeY / 2 -  myFunction(i) * multiplyY);
        painter.drawLine(*firstP, *secondP);
        *firstP = *secondP;
    }
}
Beispiel #7
0
int main ()
{
  MyClass test;
  test.b = 4;

  boost::function< void(const int) > myFunction = boost::bind<void>(test, _1);
  myFunction(3);
  //boost::function< void > myFunction = boost::bind<void>(a); // Note the () after void are necessary to avoid "incomplete type" error.

  return 0;
}
Beispiel #8
0
 void PropertySheet::PageAdder::operator() ( const Page& page )
 {
     const ::BOOL result = myFunction(
         page.handle(), myParameter
         );
     if ( result == FALSE )
     {
         const ::DWORD error = ::GetLastError();
         UNCHECKED_WIN32C_ERROR(AddPropSheetPageCallback,error);
     }
 }
Beispiel #9
0
int main()
{
	float inputValue, outputValue;

	inputValue = 42.0;

	outputValue = myFunction(inputValue);

	printf("Results are: %f", outputValue);

	return 0;
}
Table::Table(QWidget *parent) : MyPaint(parent)
{
    rows = 20;
    columns = 2;
    table = QVector< QVector<double> >(rows, QVector<double> (columns) );

    top_F = 11.0 / (M_PI * 2);

    deltaT = 1 / (2 * top_F );

    for (int i = 0; i < rows; i++) {
        table[i][0] = myFunction(i);
        table[i][1] = recoverFunction(i);
    }
}
Beispiel #11
0
int main(int argc, char* argv[]) {
  if (argc < 2) {
    std::cerr << "Example 11: Wrong number of arguments" << std::endl
              << "Example 11: Usage: example11 url [file]" << std::endl;
    return EXIT_FAILURE;
  }
  char* url = argv[1];
  char* filename = NULL;
  if (argc >= 3) {
    filename = argv[2];
  }

  try {
    curlpp::Cleanup cleaner;
    curlpp::Easy request;

    /// Set the writer callback to enable cURL to write result in a memory area
    curlpp::options::WriteFunctionCurlFunction myFunction(WriteCallback);

    FILE* file = stdout;
    if (filename != NULL) {
      file = fopen(filename, "wb");
      if (file == NULL) {
        fprintf(stderr, "%s/n", strerror(errno));
        return EXIT_FAILURE;
      }
    }

    curlpp::OptionTrait<void*, CURLOPT_WRITEDATA> myData(file);

    request.setOpt(myFunction);
    request.setOpt(myData);

    /// Setting the URL to retrive.
    request.setOpt(new curlpp::options::Url(url));
    request.setOpt(new curlpp::options::Verbose(true));
    request.perform();
  }

  catch (curlpp::LogicError& e) {
    std::cout << e.what() << std::endl;
  }

  catch (curlpp::RuntimeError& e) {
    std::cout << e.what() << std::endl;
  }
}
Beispiel #12
0
 void PropertySheet::PageAdder::operator() ( const PageInfo& info )
 {
     // Create a page that will automagically be destroyed.
     const ::HPROPSHEETPAGE page = ::CreatePropertySheetPageW(
         &info.get()
         );
     if ( page == 0 )
     {
         const ::DWORD error = ::GetLastError();
         UNCHECKED_WIN32C_ERROR(CreatePropertySheetPage,error);
     }
     // Add it!
     const ::BOOL result = myFunction(page,myParameter);
     if ( result == FALSE )
     {
         const ::DWORD error = ::GetLastError();
         UNCHECKED_WIN32C_ERROR(AddPropSheetPageCallback,error);
     }
 }
Beispiel #13
0
int main()
{
  pifi  myFunction= (pifi) (jit_set_ip(codeBuffer).iptr);
  int	ofs;				/* offset of the argument */

  jit_leaf(1);
  ofs = jit_arg_i();
  jit_getarg_i(JIT_R0, ofs);
  jit_addi_i(JIT_RET, JIT_R0, 1);
  jit_ret();
  jit_flush_code(codeBuffer, jit_get_ip().ptr);

  /* call the generated code, passing its size as argument */
#ifdef LIGHTNING_DISASSEMBLE
  disassemble(stderr, codeBuffer, jit_get_ip().ptr);
#endif
#ifndef LIGHTNING_CROSS
  printf("%d + 1 = %d\n", 5, myFunction(5));
#endif
  return 0;
}
Beispiel #14
0
int main()
{
  pvfi		myFunction;		/* ptr to generated code */
  char		*start, *end;		/* a couple of labels */
  int		ofs;			/* to get the argument */

  codeBuffer = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE | PROT_EXEC,
                    MAP_PRIVATE | MAP_ANON, -1, 0);
  if (codeBuffer == MAP_FAILED) {
    perror("mmap");
    exit(0);
  }

  myFunction = (pvfi) (jit_set_ip(codeBuffer).vptr);
  start = jit_get_ip().ptr;
  jit_prolog(1);
  ofs = jit_arg_i();
  jit_movi_p(JIT_R0, "looks like %d bytes sufficed\n");
  jit_getarg_i(JIT_R1, ofs);
  jit_prepare_i(2);
    jit_pusharg_i(JIT_R1);		/* push in reverse order */
    jit_pusharg_p(JIT_R0);
  jit_finish(display_message);
  jit_ret();
  end = jit_get_ip().ptr;

  jit_flush_code(codeBuffer, end);

#ifdef LIGHTNING_DISASSEMBLE
  disassemble(stderr, codeBuffer, end);
#endif
#ifndef LIGHTNING_CROSS
  /* call the generated code, with a dummy argument */
  myFunction(1024);
#endif
  return 0;
}
Beispiel #15
0
void jsMyFunction(const FunctionCallbackInfo<Value>& args)
{
	myFunction();
}
// main function
int main()
{
        printf("I\'m from the main function.\n");
        myFunction(); //call myFunction
        return 0;
}
////////////////////////////////////////////////////////////
/// Function called as the thread entry point
////////////////////////////////////////////////////////////
void Thread::Run()
{
    if (myFunction)
        myFunction(myUserData);
}
int SafeGuardedZeroFindingAlgorithm::findZeroPoint(double x0)
{
	if (! theSamplingAnalysis->getContribution()) return 0;  //Gu 2007 Dec 23
 

	// note:  1, the point x0 is not used for this algorithm
	//        2, a & Fa must be set before calling. Fa must be positive (safe domain).
	//        3, either b& Fb set,  or FEconvergence is set to be false (unsafe domain, either G<0 or diverge)
	//        4, isFbValid decide whether Fb is converged value;
    
	//create new array to save history
	double * Xs;
	double * Fs;
	int ii;

	if (functionType ==1) {
		Xs = x_1;
	    Fs = G_1;
		ii=ii_1;
	}

	else if (functionType ==2) {
		Xs = x_2;
	    Fs = G_2;
		ii=ii_2;
	}

/////////////////////////////////////////////////////////

	double TOL=variableTol/1000.0;
	

	double x1,x_new, last_x_new;
	double Fx0, Fx1,Fx_new;
	
	if (Fa < -functionTol) {
		opserr<<"error in SafeGuardedZeroFindingAlgorithm::findZeroPoint. Fa<0"<<endln; 
		return -1;
	}

	

	if (FEconvergence) {  //save data
		isFbValid = true; 

		x_new = -Fb*(b-a)/(Fb-Fa)+b;
		if ((x_new<a-TOL)||(x_new<b+TOL)){  
			x_new=(a+b)/2.0;
		}
	}
	else {  // !FEconvergence, bisection
		x_new = (a+b)/2.0;
		// improve  ??????????????????????????????????????????????????????????????????????
//		x_new = a+0.15;
		isFbValid = false; 
	}

	if (this->functionType == 1){
		iterationNum =2; // here is function evaluation number
	}
	else if (this->functionType == 2){
		iterationNum =0; // here is function evaluation number
	}

	last_x_new = x_new+999;
 

	Fx_new=myFunction(x_new);

	iterationNum++;

	if (FEconvergence) {

		if (fabs(Fx_new)<functionTol) {
			zeroPoint = x_new; 
			opserr<<"Return: x_new is:"<<x_new<<" Fx_new is: "<<Fx_new<<endln;
			return 1;
		}

		if (Fx_new * Fa >functionTol*functionTol){ //good
			
			a = x_new;
			Fa = Fx_new;
			
		}
		else if (Fx_new * Fa < -functionTol*functionTol){
			b = x_new;
			Fb = Fx_new;
			isFbValid = true;

		}
		else { 
			opserr<<"wrong bound!"<<endln; return -1;
		}
	}
	else {//diverge
		b=x_new; Fb=-1.0;
		isFbValid = false;
	
	}
	
	
	
	if (maxIterNum>100) {
		opserr<<"warning: SafeGuardedZeroFindingAlgorithm::findZeroPoint may couse member ";
		opserr<<" error since maxIterNum:"<<maxIterNum<<" exceed the limit 100..."<<endln;
	}

	while (theSamplingAnalysis->getContribution() && /*fabs(Fx_new)>functionTol &&*/ iterationNum < maxIterNum && (b-a)>variableTol) {
	
		iterationNum++;

		if (isFbValid ) { // select x0 and x1..
			if(fabs(Fa)>fabs(Fb)+functionTol) {
				x1=b; Fx1=Fb;

			}
			else {
				x1=a; Fx1=Fa;

			}
		}
		else {// ! isFbValid , begin from a
			x1=a; Fx1=Fa;
		}
		//	--------- select best x0, which is closest to x1 ---------
		double  interval =999;
		for(int i=0;i<ii;i++){
			if ((fabs(Xs[i]-x1)<interval)&&(fabs(Xs[i]-x1)>TOL/1000.0)) 
			{x0= Xs[i];Fx0=Fs[i]; interval=fabs(Xs[i]-x1); }
		}
			

		last_x_new = x_new;  // save old x_new
		// --- newton secant method 
		if (fabs(Fx1-Fx0)> 1.0e-10){
			x_new = -Fx1*(x1-x0)/(Fx1-Fx0)+x1;
		}
		else {
			x_new = (a+b)/2.0;	
		}




		// --- make sure it is in trust region	
		if ((x_new>b+TOL)||(x_new<a-TOL)) {
			x_new=(a+b)/2.0;
		}
		//correction if starked! ----

		if ((fabs(x_new-a)< TOL/1000.)||(fabs(x_new-b)< TOL/1000.))  x_new=(a+b)/2.0;
		if (fabs(last_x_new-x_new)<TOL/1000.) x_new=(a+b)/2.0;
		
		

		// check x_new, is not solution 
		Fx_new=myFunction(x_new);

		if (FEconvergence){
		


		
			if(fabs(Fx_new)<functionTol){
					zeroPoint = x_new;
					opserr<<"Return: x_new is:"<<x_new<<" Fx_new is: "<<Fx_new<<endln;				
					return 1;
			} 

			else if (Fx_new*Fa > functionTol*functionTol){ //good
				
				a = x_new;
				Fa = Fx_new;
				
			}
			else if (Fx_new * Fa < -functionTol*functionTol){
				b = x_new;
				Fb = Fx_new;
				isFbValid = true;

			}
		
			else { opserr<<"bound wrong"<<endln; return -1; }//opserr<<"wrong bound!"<<endln; return -1;}
			printf("a: %f, b: %f, Fa: %f, Fb: %f,x_new: %9.4f, Fx_new: %14.7f \n",a,b,Fa,Fb,x_new,Fx_new );

			}
		else { //FEdivergence
		
			b=x_new;
			Fb=-1.0;
			isFbValid = false;
			printf("diverge-- a: %f, b: %f, Fa: %f, Fb: %f,x_new: %9.4f, Fx_new: %14.7f \n",a,b,Fa,Fb,x_new,Fx_new );	
		}			
		
		
	};//while


	if (iterationNum == maxIterNum) {//not converge
		return -1;
	}
	
	zeroPoint = x_new;


	return 0;
} ;