Пример #1
0
int main(void)
{
    float a, b, c, d, fa, fb, fc,tole;
/**    std::cout<<"a:";
	std::cin>>a;
	std::cout<<"b:";
	std::cin>>b;
**/	
    a = 1;
    b=-3;
    tole = 0.00001;
    d = abso(a,b);
    
	while(d > tole)
	{
	c = (a+b)/2;
	fa = fnc(a);
	fb = fnc(b);
	fc = fnc(c);
	
	if ((fa*fc)>0){
                  a=c;
                  }
                  
                  else{
                       b=c;
                       }
                       d = abso(a,b);
	}
	
	std::cout<<a<<std::endl;
}
Пример #2
0
//---------------------------------------------------------------------------
//Вывод на экран результатов расчета
void kutt2(double yp1, double yp2, double x){
	double k1, k2, k3, k4;
        double k11, k22, k33, k44, gn, gx=StrToFloat(Form1->x1N->Text), y1=yp1, y2=yp2;
	int i, step;

        Form1->Memo1->Lines->Add("x="+Form1->x1N->Text+"; y="+FloatToStr(yp1));
        for(step=0; step<n; step++){
                gx+=h;
                gn=(gx-StrToFloat(Form1->x1N->Text))/gh;
                x=StrToFloat(Form1->x1N->Text);
                yp1=y1;
                yp2=y2;
                for(i=0; i<gn; i++){
                	k11=yp2;
                	k1=fnc(yp1, k11, x);

                        k22=yp2+gh/2*k1;
                	k2=fnc(yp1+gh/2*k1, k22, x+gh/2);

                        k33=yp2+gh/2*k2;
                	k3=fnc(yp1+gh/2*k2, k33, x+gh/2);

                	k44=yp2+gh*k2;
                	k4=fnc(yp1+gh*k3, k44, x+gh);

                	yp1=yp1+gh/6*(k11+2*k22+2*k33+k44);
                	yp2=yp2+gh/6*(k1+2*k2+2*k3+k4);

                	x+=gh;
                }
                Form1->Memo1->Lines->Add("x="+FloatToStr(gx)+"; y="+FloatToStr(yp1));
        }
}
Пример #3
0
DEM red3 (DEM x, int red_arg)
{
DEM t, t1, t2, t3, t4, t5;
int i;
	trace_dem ("red3", x);
        for (i=0; i<nnr; i++)
        {
            trace_dem ("", no_red[i]);
            trace_dem ("", x);
            if (no_red[i] == x)
                return x;
        }

        if (used != NULL && x == left(used))
            return used;

	if ((flags & FLAG_RED_LAMBDA) && node(x) == node_lambda)
        {
	    t1 = red1 (sd0(x), red_arg);
            trace_dem ("DBLambda", t1);
	    t2 = lambda (t1);
            trace_dem ("DBLambda", t2);
            return t2;
        }
	if (atom(x))
            return x;
	if (node(fnc(x)) == node_lambda)
        {
	    return mksubst (subdem(0,fnc(x)), arg(x));
        }
        if (used == NULL && atom (fnc(x)))
	{
                t1 = fnc(x);
                if (red_arg)
                    t2 = red1 (arg(x), red_arg);
                else
                    t2 = arg(x);
		t = ap (t1, t2);
		return t;
	}
	t1 = red1 (fnc(x), red_arg);
        if (red_arg)
        	t2 = red1 (arg(x), red_arg);
        else
            t2 = arg(x);
	t3 = ap (t1, t2);
	if (left(t3) == right(t3))
		return t3;
	t4 = red1 (right(t3), red_arg);
	if (left(t4) == right(t4))
		return t3;
	t = trans (t3, t4);
	return t;
}
Пример #4
0
bool ELJTextValidator::Validate(wxWindow* _prt)
{
	if (obj && fnc)
		return fnc(obj) != 0;
	else
		return wxTextValidator::Validate(_prt);
}
Пример #5
0
// Exact solution.
double exact_solution(double x, double y, double z, double &dx, double &dy, double &dz) {
#if defined X2_Y2_Z2_025
  if ((x*x + y*y + z*z) != 0.0) {
    dx = 0.5 * x * pow(x*x + y*y + z*z, -.75);
    dy = 0.5 * y * pow(x*x + y*y + z*z, -.75);
    dz = 0.5 * z * pow(x*x + y*y + z*z, -.75);
  }
  else {
    // pow(x*x + y*y + z*z, -.75) is not defined
    dx = 0.0;
    dy = 0.0;
    dz = 0.0;
  }
#elif defined X2_Y2_Z2
  dx = 2 * x;
  dy = 2 * y;
  dz = 2 * z;
#elif defined X3_Y3_Z3
  dx = 3 * x*x;
  dy = 3 * y*y;
  dz = 3 * z*z;
#elif defined XN_YM_ZO
  dx = m * pow(x, m-1) * pow(y, n) * pow(z, o) + 2 * x * pow(y, 3) - 2 * x * z;
  dy = n * pow(x, m) * pow(y, n-1) * pow(z, o) + 3 * pow(x, 2) * pow(y, 2);
  dz = o * pow(x, m) * pow(y, n) * pow(z, o-1) - pow(x, 2) + 4 * pow(z, 3);
#endif

  return fnc(x, y, z);
}
Пример #6
0
// needed for calculation norms and used by visualizator
double exact_solution(double x, double y, double z, double &dx, double &dy, double &dz) {
	dx = m * pow(x, m-1) * pow(y, n) * pow(z, o) + 2 * x * pow(y, 3) - 3 * pow(x, 2) * z;
	dy = n * pow(x, m) * pow(y, n-1) * pow(z, o) + 3 * pow(x, 2) * pow(y, 2);
	dz = o * pow(x, m) * pow(y, n) * pow(z, o-1) - pow(x, 3) + 4 * pow(z, 3);

	return fnc(x, y, z);
}
Пример #7
0
T dfnc(T x, T y, T z) {
	T ddxx = m*(m-1) * pow(x, m-2) * pow(y, n) * pow(z, o) + 2 * pow(y, 3) - 6 * x * z;
	T ddyy = n*(n-1) * pow(x, m) * pow(y, n-2) * pow(z, o) + 6 * pow(x, 2) * y;
	T ddzz = o*(o-1) * pow(x, m) * pow(y, n) * pow(z, o-2) + 12 * pow(z, 2);

	return -(ddxx + ddyy + ddzz) + fnc(x, y, z);
}
Пример #8
0
// Dirichlet boundary conditions.
scalar essential_bc_values(int ess_bdy_marker, double x, double y, double z) {
#ifdef DIRICHLET
	return fnc(x, y, z);
#else
	return 0;
#endif
}
Пример #9
0
Файл: port.c Проект: jaw0/jlisp
int prnport(Obj p, Obj s, int h){
	int (*fnc)(Obj,Obj,int);
	int t = SUBPORT(p);

	fnc = pdesc[t].print;

	if(fnc)
		return fnc(p, s, h);
	else{
		writestr(s, "#<ioport:");
		if( RPORTP(p))
			writechar(s, 'R');
		if( WPORTP(p))
			writechar(s, 'W');
		if( SUBPORT(p)){
			writechar(s, '_');
			printnum(s, SUBPORT(p), 16, 0, 0);
			if( SUBSUBPORT(p)){
				writechar(s, ':');
				printnum(s, SUBSUBPORT(p), 16, 0, 0);
			}
		}
		writechar(s, '>');
		return 1;
	}
}
Пример #10
0
double exact_solution(double x, double y, double z, double &dx, double &dy, double &dz) {
	dx = 0.75 * sqrt(3.0 / 2.0) * (((x + 1) * (y + 1) * (z + 1)) - ((y + 1) * (- z - y - x - 1) * (z + 1)));
	dy = 0.75 * sqrt(3.0 / 2.0) * (((x + 1) * (y + 1) * (z + 1)) - ((x + 1) * (- z - y - x - 1) * (z + 1)));
	dz = 0.75 * sqrt(3.0 / 2.0) * (((x + 1) * (y + 1) * (z + 1)) - ((x + 1) * (y + 1) * (- z - y - x - 1)));

	return fnc(x, y, z);
}
Пример #11
0
// Exact solution.
double exact_solution(double x, double y, double z, double &dx, double &dy, double &dz) {
	dx = 2 * x;
	dy = 2 * y;
	dz = 2 * z;

	return fnc(x, y, z);
}
Пример #12
0
T dfnc(T x, T y, T z)
{
	T ddxx = 2;
	T ddyy = 2;
	T ddzz = 2;

	return -(ddxx + ddyy + ddzz) + fnc(x, y, z);
}
Пример #13
0
Файл: port.c Проект: jaw0/jlisp
Obj eqport(Obj a, Obj b){
	Obj (*fnc)(Obj,Obj);
	int t = SUBPORT(a);

	fnc = pdesc[t].equal;

	if(fnc) return fnc(a, b);
	else return eqcdr(a, b);
}
Пример #14
0
Файл: port.c Проект: jaw0/jlisp
int freeport(Obj p){
	int (*fnc)(Obj);
	int t = SUBPORT(p);

	fnc = pdesc[t].free;

	if(fnc) return fnc(p);
	else return free0(p);
}
Пример #15
0
Файл: port.c Проект: jaw0/jlisp
/* entries to vtbl table in jlisp.c */
void markport(Obj p){
	void (*fnc)(Obj);
	int t = SUBPORT(p);

	fnc = pdesc[t].mark;

	if(fnc) fnc(p);
	else mark0(p);
}
Пример #16
0
// needed for calculation norms and used by visualizator
double exact_solution(double x, double y, double z, double &dx, double &dy, double &dz)
{
	// u(x, y, z) = x^m * y^n * z^o + x^2 * y^3 - x^3 * z + z^4
	dx = m * pow(x, m-1) * pow(y, n) * pow(z, o) + 2 * x * pow(y, 3) - 3 * pow(x, 2) * z;
	dy = n * pow(x, m) * pow(y, n-1) * pow(z, o) + 3 * pow(x, 2) * pow(y, 2);
	dz = o * pow(x, m) * pow(y, n) * pow(z, o-1) - pow(x, 3) + 4 * pow(z, 3);

	return fnc(x, y, z);
}
Пример #17
0
DEM redu (DEM x)
{
int forme_Sfg;
DEM rf, ra, f1, a1, x1, r1, r2, t1, t2, t3, t4, t5, t6, r, rr1;
	trace_dem ("redu", x);
	if (atom(x))
        {
                trace_dem ("atom: return", x);
		return x;
        }
        trace_dem ("not atom", x);
        rf = redu (fnc(x)); trace_dem ("", rf);
        ra = redu (arg(x)); trace_dem ("", ra);
	f1 = right (rf); trace_dem ("", f1);
	a1 = right (ra); trace_dem ("", a1);
        trace_dem ("", x);
        if (fnc(x)==f1 && arg(x)==a1)
	{
		r1 = redu1 (x); trace_dem ("", r1);
                rr1 = right(r1); trace_dem ("", rr1);
		if (rr1 == x)
                {
                        trace_dem ("return", r1);
			return r1;
                }
                trace_dem ("", rr1);
		r2 = redu (rr1); trace_dem ("", r2);
		if (left(r2) == right(r2))
			return r1;
		if (left(r1) == right(r1))
			return r2;
		r = trans (r1, r2); trace_dem ("", r);
		return r;
	}
	x1 = ap (f1, a1); trace_dem ("", x1);
	r1 = redu1 (x1); trace_dem ("", r1);
	if (right(r1) == x)
		r2 = r1;
	r2 = redu (right(r1)); trace_dem ("", r2);
	t3 = ap (rf, ra); trace_dem ("", t3);
	t4 = trans (t3, r1); trace_dem ("", t4);
	t5 = trans (t4, r2); trace_dem ("", t5);
	return t5;
}
Пример #18
0
//typedef int (FNC_ADD_TEXT_CALLBACK)(short *pUni, int iMaxLen, void *pUserData);
void CTEditBase::addText(FNC_ADD_TEXT_CALLBACK *fnc, int iMaxLenToAdd, void *pUserData)
{
   int iPos;
   iMaxLenToAdd=checkSize(iMaxLenToAdd,&iPos);
   iLen=iPos;
   iLen += fnc(pData+iLen,iMaxLenToAdd,pUserData);
   pData[iLen]=0;
   if(iCannotRedraw==0)
      onChange();

}
Пример #19
0
Scalar linear_form_surf(int np, double *wt, Func<Scalar> *u_ext[], Func<Real> *u, Geom<Real> *e, ExtData<Scalar> *data) {
	Scalar result = 0;
	for (int i = 0; i < np; i++) {
		Scalar dx = m * pow(e->x[i], m-1) * pow(e->y[i], n) * pow(e->z[i], o) + 2 * e->x[i] * pow(e->y[i], 3) - 3 * pow(e->x[i], 2) * e->z[i];
		Scalar dy = n * pow(e->x[i], m) * pow(e->y[i], n-1) * pow(e->z[i], o) + 3 * pow(e->x[i], 2) * pow(e->y[i], 2);
		Scalar dz = o * pow(e->x[i], m) * pow(e->y[i], n) * pow(e->z[i], o-1) - pow(e->x[i], 3) + 4 * pow(e->z[i], 3);

		result += wt[i] * (u->val[i] * (dx * e->nx[i] + dy * e->ny[i] + dz * e->nz[i] + fnc(e->x[i], e->y[i], e->z[i])));
	}
	return result;
}
Пример #20
0
Scalar linear_form_surf(int np, double *wt, Func<Scalar> *u_ext[], Func<Real> *u, Geom<Real> *e, ExtData<Scalar> *user_data) {
	Scalar result = 0;
	for (int i = 0; i < np; i++) {
		Scalar dx = 2 * e->x[i];
		Scalar dy = 2 * e->y[i];
		Scalar dz = 2 * e->z[i];

		result += wt[i] * (u->val[i] * (dx * e->nx[i] + dy * e->ny[i] + dz * e->nz[i] + fnc(e->x[i], e->y[i], e->z[i])));
	}
	return result;
}
Пример #21
0
typename ignore_value<sizeof(declval<F>()(declval<T>(), declval<const std::vector<T> >())),
         std::vector<T> >::type map_vec(F fnc, const std::vector<T>& source)
{
    std::vector<T> dest;
    dest.reserve(source.size());
    for (typename std::vector<T>::const_iterator i = source.begin(); i != source.end(); ++i)
    {
        dest.push_back(fnc(*i, source));
    }
    return dest;
}
Пример #22
0
res_t linear_form_surf(int np, double *wt, Func<res_t> *u_ext[], Func<f_t> *u, Geom<f_t> *e, ExtData<res_t> *data) {
	res_t result = 0;
	for (int i = 0; i < np; i++) {
		res_t dx = m * pow(e->x[i], m-1) * pow(e->y[i], n) * pow(e->z[i], o) + 2 * e->x[i] * pow(e->y[i], 3) - 3 * pow(e->x[i], 2) * e->z[i];
		res_t dy = n * pow(e->x[i], m) * pow(e->y[i], n-1) * pow(e->z[i], o) + 3 * pow(e->x[i], 2) * pow(e->y[i], 2);
		res_t dz = o * pow(e->x[i], m) * pow(e->y[i], n) * pow(e->z[i], o-1) - pow(e->x[i], 3) + 4 * pow(e->z[i], 3);

		result += wt[i] * (u->fn[i] * (dx * e->nx[i] + dy * e->ny[i] + dz * e->nz[i] + fnc(e->x[i], e->y[i], e->z[i])));
	}
	return result;
}
Пример #23
0
static inline void mdss_mdp_intr_done(int index)
{
	void (*fnc)(void *);
	void *arg;

	spin_lock(&mdss_mdp_intr_lock);
	fnc = mdp_intr_cb[index].func;
	arg = mdp_intr_cb[index].arg;
	spin_unlock(&mdss_mdp_intr_lock);
	if (fnc)
		fnc(arg);
}
Пример #24
0
int lsmash_set_tyrant_chapter( lsmash_root_t *root, char *file_name, int add_bom )
{
    /* This function should be called after updating of the latest movie duration. */
    if( !root || !root->moov || !root->moov->mvhd || !root->moov->mvhd->timescale || !root->moov->mvhd->duration )
        goto error_message;
    /* check each line format */
    fn_get_chapter_data fnc = isom_check_chap_line( file_name );
    if( !fnc )
        goto error_message;
    FILE *chapter = fopen( file_name, "rb" );
    if( !chapter )
    {
        lsmash_log( LSMASH_LOG_ERROR, "failed to open the chapter file \"%s\".\n", file_name );
        goto error_message;
    }
    if( isom_add_udta( root, 0 ) || isom_add_chpl( root->moov ) )
        goto fail;
    isom_chapter_entry_t data = {0};
    while( !fnc( chapter, &data ) )
    {
        if( add_bom )
        {
            char *chapter_name_with_bom = (char *)malloc( strlen( data.chapter_name ) + 1 + UTF8_BOM_LENGTH );
            if( !chapter_name_with_bom )
                goto fail2;
            sprintf( chapter_name_with_bom, "%s%s", UTF8_BOM, data.chapter_name );
            free( data.chapter_name );
            data.chapter_name = chapter_name_with_bom;
        }
        data.start_time = (data.start_time + 50) / 100;    /* convert to 100ns unit */
        if( data.start_time / 1e7 > (double)root->moov->mvhd->duration / root->moov->mvhd->timescale )
        {
            lsmash_log( LSMASH_LOG_WARNING, "a chapter point exceeding the actual duration detected. This chapter point and the following ones (if any) will be cut off.\n" );
            free( data.chapter_name );
            break;
        }
        if( isom_add_chpl_entry( root->moov->udta->chpl, &data ) )
            goto fail2;
        free( data.chapter_name );
        data.chapter_name = NULL;
    }
    fclose( chapter );
    return 0;
fail2:
    if( data.chapter_name )
        free( data.chapter_name );
fail:
    fclose( chapter );
error_message:
    lsmash_log( LSMASH_LOG_ERROR, "failed to set chapter list.\n" );
    return -1;
}
Пример #25
0
int main(int argc, char* argv[])
{
  int lib = 1;
  void *handle = NULL;
  int result[2] = {0, 0};
  int i, answer;
  int cnt1 = 0, cnt2 = 0;

  printf("0: "); fflush(stdout);
  while (1) {
    if (handle != NULL)
      dlclose(handle);

    if (lib == 1) {
      handle = dlopen("libdlopen-lib1.so", RTLD_NOW);
      if (handle == NULL) {
        fprintf(stderr, "dlopen failed: %s\n", dlerror());
        exit(1);
      }
      /* See 'man dlopen' for example:  POSIX.1-2002 prefers this workaround */
      *(void **) (&fnc) = dlsym(handle, "fnc");
    }

    if (lib == 2) {
      handle = dlopen("libdlopen-lib2.so", RTLD_LAZY);
      if (handle == NULL) {
        fprintf(stderr, "dlopen failed: %s\n", dlerror());
        exit(1);
      }
      /* See 'man dlopen' for example:  POSIX.1-2002 prefers this workaround */
      *(void **) (&fnc) = dlsym(handle, "fnc");
    }

    assert(lib == 1 || lib == 2);
    for (i = 0; i < 5; i++) {
      answer = fnc(result);
      if (answer != result[lib - 1]) {
        fprintf(stderr, "lib %d returned wrong answer.\n", lib);
        exit(1);
      }
    }
    if (++cnt1 % 1000 == 0) {
      cnt2++;
      cnt1 = 0;
      printf("."); fflush(stdout);
      if (cnt2 % 50 == 0)
        printf("\n%d: ", cnt2 / 50); fflush(stdout);
    }
    lib = 3 - lib; /* switch libraries to load */
  }
  return 0;
}
Пример #26
0
 void fillLog(int iLastNLines, void *ret, void(*fnc)(void *ret, const char *line, int iLen)){
    
    if(!fnc)return;
    
    if(iLastNLines>iMaxLines)iLastNLines=iMaxLines;
    
    int iFromLine=iNextLine-iLastNLines;
    if(iFromLine<0){
       int f=iMaxLines+iFromLine;
       for(int i=f;i<iMaxLines;i++){
          char *p=getLine(i);
          int l=iBytesInLine[i];
          if(l)fnc(ret,p,l);
       }
    }
    for(int i=0;i<iNextLine;i++){
       char *p=getLine(i);
       int l=iBytesInLine[i];
       if(l)fnc(ret,p,l);
    }
    
 }
Пример #27
0
Scalar form_0_surf(int n, double *wt, Func<Real> *u[], Func<Real> *vi, Geom<Real> *e,
                  ExtData<Scalar> *data)
{
	Scalar res = 0;
	for (int i = 0; i < n; i++) {
		Scalar dx = 2 * e->x[i];
		Scalar dy = 2 * e->y[i];
		Scalar dz = 2 * e->z[i];

		res += wt[i] * (u[0]->val[i] * vi->val[i]
				- (dx * e->nx[i] + dy * e->ny[i] + dz * e->nz[i] + fnc(e->x[i], e->y[i], e->z[i])) * vi->val[i]);
	}
	return res;
}
Пример #28
0
int main(){
      
   int X[] = {10,8};
   int Y[] = {2,9,10};
   
   int a = 2;
   int b = 3;
       
   int aux2 = fnc (X,a,Y,b);
 
    printf("%d",aux2);
getch();
return 0;

}
double BaseDensity::enclosedMass(const double r) const
{
    if(r<=0) return 0;   // this assumes no central point mass! overriden in Plummer density model
    // default implementation is to integrate over density inside given radius;
    // may be replaced by cheaper and more approximate evaluation for derived classes
    DensityIntegrandNdim fnc(*this);
    double xlower[3] = {0, 0, 0};
    double xupper[3] = {scaledr_from_r(r), 1, 1};
    double result, error;
    int numEval;
    const int maxNumEval = 10000;
    math::integrateNdim(fnc, xlower, xupper, EPSREL_DENSITY_INT, maxNumEval,
        &result, &error, &numEval);
    return result;
}
Пример #30
0
// needed for calculation norms and used by visualizator
double exact_solution(double x, double y, double z, double &dx, double &dy, double &dz) {
#ifdef XM_YN_ZO
	dx = m * pow(x, m - 1) * pow(y, n) * pow(z, o) + 2 * x * pow(y, 3) - 3 * pow(x, 2) * z;
	dy = n * pow(x, m) * pow(y, n - 1) * pow(z, o) + 3 * pow(x, 2) * pow(y, 2);
	dz = o * pow(x, m) * pow(y, n) * pow(z, o - 1) - pow(x, 3) + 4 * pow(z, 3);
#elif defined XM_YN_ZO_2
	dx = m * pow(x, m-1) * pow(y, n) * pow(z, o) + 2 * x * pow(y, 3) - 2 * x * z;
	dy = n * pow(x, m) * pow(y, n-1) * pow(z, o) + 3 * pow(x, 2) * pow(y, 2);
	dz = o * pow(x, m) * pow(y, n) * pow(z, o-1) - pow(x, 2) + 4 * pow(z, 3);
#elif defined X2_Y2_Z2
	dx = 2 * x;
	dy = 2 * y;
	dz = 2 * z;
#endif

	return fnc(x, y, z);
}