Пример #1
0
int	pass(char *su, char *bin)
{
  int	change;
  int	i;
  int	j;
  int	k;
  int	sum[4];

  change = 0;
  k = -1;
  while (++k < 9 && (j = -1))
    while (++j < 9 && (i = -1))
      while (++i < 9)
	if (!su[9 * i + j] && bin[81 * i + 9 * j + k])
	  {
	    sum[0] = sum_line(bin, i, k);
	    sum[1] = sum_column(bin, j, k);
	    sum[2] = sum_untitled(bin, i, j);
	    sum[3] = sum_square(bin, i, j, k);
	    if ((sum[0] == 1 || sum[1] == 1 || sum[2] == 1 || sum[3] == 1) &&
		++change)
	      add_sol(su, bin, i, j, k);
	  }
  if (change)
    return (1);
  return (0);
}
/* >>> start tutorial code >>> */
int main( ){

    USING_NAMESPACE_ACADO

    int i;

    // DEFINE VALRIABLES:
    // ---------------------------
    Matrix                 A(3,3);
    Vector                 b(3);
    DifferentialState      x(3);
    DifferentialState      y;
    Function               f[7];

    // DEFINE THE VECTOR AND MATRIX ENTRIES:
    // -------------------------------------
    A.setZero() ;
    A(0,0) = 1.0;  A(1,1) = 2.0;  A(2,2) = 3.0;
    b(0)   = 1.0;  b(1)   = 1.0;  b(2)   = 1.0;


    // DEFINE TEST FUNCTIONS:
    // -----------------------
    f[0] << A*x + b;
    f[1] << y + euclidean_norm(A*x + b);
    f[2] << y*y;
    f[3] << square(y);
    f[4] << 5.0*log_sum_exp( x );
//    f[5] << entropy( y );
    f[6] << -sum_square( x );


    for( i = 0; i < 7; i++ ){
        if( f[i].isConvex() == BT_TRUE )
            printf("f[%d] is convex. \n", i );
        else{
            if( f[i].isConcave() == BT_TRUE )
                  printf("f[%d] is concave. \n", i );
            else
                  printf("f[%d] is neither convex nor concave. \n", i );
        }
    }
    return 0;
}