void hex_unlineate (unsigned int l, signed int * x, signed int * y) { unsigned int r = 0, k = 0, i = 0; int remainder; if (l == 0) { *x = 0; *y = 0; return; } //printf ("%s: have %d\n", __FUNCTION__, l); while (fx (r) <= l) { r++; } //printf ("%s: %d (fx (%d)) is smallest hex larger than l-val\n", __FUNCTION__, fx (r), r); remainder = l - fx (r - 1); //printf ("%s: %d remaining with r assigned as %d\n", __FUNCTION__, remainder, r); assert (r != 0); k = remainder / r; i = remainder % r; //printf ("got {%d %d %d} from %d\n", r, k, i, l); hex_rki2xy (r, k, i, x, y); return; }
//------------------------------------------------------------ // // Part I : Reachability Decision for Hyperbox // //------------------------------------------------------------ bool System::isReachable(Hyperbox* source, Hyperbox* sink){ //Four cases corresponding to 2D hyperbox. //Case I : x-const, y varies, checking x' to be negative. //Case II : y-const, x varies, checking y' to be positive. //Case III: x-const, y varies, checking x' to be positive. //Case IV : y-const, x varies, checking y' to be negative. //Case I: if(source->min[0]==sink->max[0]){ if(fx(source->min[0], source->min[1], source->max[1])!=positive){ return true; } } //Case II: if(source->max[1] == sink->min[1]){ if(fy(source->max[1], source->min[0], source->max[0]) != negative){ return true ; } } //Case III: if(source->max[0] == sink->min[0]){ if(fx(source->max[0], source->min[1], source->max[1]) != negative){ return true; } } //Case IV: if(source->min[1] == sink->max[1]){ if(fy(source->min[1], source->min[0], source->max[0]) != positive){ return true; } } return false; }
void Calculate() { int i; double kx[4],kv[4]; kx[0] = fx(v)*dt; kv[0] = fv(x)*dt; kx[1] = fx(v+kv[0]/2.0)*dt; kv[1] = fv(x+kx[0]/2.0)*dt; kx[2] = fx(v+kv[1]/2.0)*dt; kv[2] = fv(x+kx[1]/2.0)*dt; kx[3] = fx(v+kv[2])*dt; kv[3] = fv(x+kx[2])*dt; t += dt; x += (kx[0]+2.0*kx[1]+2.0*kx[2]+kx[3])/6.0; v += (kv[0]+2.0*kv[1]+2.0*kv[2]+kv[3])/6.0; T = m*pow((l*v),2.0)/2.0; U = g/l*(1.0-cos(x)); E = T + U; for(i=0;i<GN-1;i++){ graphT[i] = graphT[i+1]; graphU[i] = graphU[i+1]; } graphT[GN-1] = T; graphU[GN-1] = U; }
void RomeoSimpleActuator::computeAllModelDeriv(double& dt, const stateVec_t& X,const stateVec_t& Xdes,const commandVec_t& U) { Xreal = X + Xdes; fx = fxBase; fx(1,3) += A13atan*(a/(1+a*a*Xreal(3,0)*Xreal(3,0))); fx(3,3) -= A33atan*(a/(1+(a*a*Xreal(3,0)*Xreal(3,0)))); fxx[3](1,3) = -((2*dt*Jm*R)/(pi*Jl))*Cf0*((2*a*a*a*Xreal(3,0))/((1+(a*a*Xreal(3,0)*Xreal(3,0)))*(1+(a*a*Xreal(3,0)*Xreal(3,0))))); fxx[3](3,3) = +((2*dt*Cf0)/(pi*Jl))*((2*a*a*a*Xreal(3,0))/((1+(a*a*Xreal(3,0)*Xreal(3,0)))*(1+(a*a*Xreal(3,0)*Xreal(3,0))))); }
Real fy(Real y) { Real fx(Real x); ysav = y; return qsimp(fx,xmin,xmax); }
void my_f(double *f, double *x, double *u, double time)// evaluate of f(x) { // double testtemp; // testtemp = norm(u, nc); fx(f, x, N, d); //What exactly is the vector x ??? Is it n*ns*nx+nx or just nx ??? S(f, x, N, d); M(f, x, N, d); L(f, x, N, d); int i; for(i=0; i<d; i++) { *(f + (N+1)*d + i) += u[i]; } *(f+nx-1) = 0.5*nu*norm(u, nc)*norm(u, nc) + l1(x, N, d); //What exactly is the vector u ??? Is it n*ns*nc or just nc ??? return; }
void polyfill(int n, vec2 points[]) { int i; int xoff, yoff; MWPOINT pv[MAXPOLY]; if(!hdc) return; /* calc window offset*/ xoff = hdc->hwnd->clirect.left; yoff = hdc->hwnd->clirect.top; /* only plot non-trivial polygons*/ if(n > 2) { for(i=0; i<n; ++i) { pv[i].x = fx(points[i].x) + xoff; pv[i].y = fy(points[i].y) + yoff; /* fix: floating round error, y intercept difference * with GdLine */ /*pv[i].x = fx(points[i].x + xoff);*/ /*pv[i].y = fy(points[i].y + yoff);*/ } GdSetForegroundColor(hdc->psd, hdc->pen->color); GdFillPoly(hdc->psd, n, pv); } }
void createSampleGrid(SGPP::base::Grid& grid, size_t l, SGPP::optimization::VectorFunction& f, SGPP::base::DataMatrix& functionValues) { SGPP::base::GridStorage& gridStorage = *grid.getStorage(); const size_t d = f.getNumberOfParameters(); const size_t m = f.getNumberOfComponents(); // generate regular sparse grid gridStorage.emptyStorage(); std::unique_ptr<SGPP::base::GridGenerator>(grid.createGridGenerator())->regular(l); const size_t n = gridStorage.size(); SGPP::base::DataVector x(d); SGPP::base::DataVector fx(m); functionValues.resize(n, m); for (size_t i = 0; i < n; i++) { SGPP::base::GridIndex& gp = *gridStorage[i]; // don't forget to set the point distribution to Clenshaw-Curtis // if necessary (currently not done automatically) if (grid.getType() == SGPP::base::GridType::BsplineClenshawCurtis || grid.getType() == SGPP::base::GridType::ModBsplineClenshawCurtis || grid.getType() == SGPP::base::GridType::LinearClenshawCurtis) { gp.setPointDistribution( SGPP::base::GridIndex::PointDistribution::ClenshawCurtis); } for (size_t t = 0; t < d; t++) { x[t] = gp.getCoord(t); } f.eval(x, fx); functionValues.setRow(i, fx); } }
Array<double,2> NumericalJacobian<F>::Jacobian(Array<double,1>& x) { int i,j; Array<double,2> result(f.retdim(),f.argdim()); Array<double,1> fx(f(x).copy()); Array<double,1> dx(f.argdim()); dx = 0.0; for (j=0; j<f.argdim(); j++) { dx(j) = d; Array<double,1> xdx(x + dx); Array<double,1> fxdx(f(xdx).copy()); for (i=0; i<f.retdim(); i++) result(i,j) = (fxdx(i)-fx(i))/d; dx(j) = 0.0; } return result; }
void Permittivity<EvalT, Traits>:: init_KL_RF(std::string &type, Teuchos::ParameterList& sublist, Teuchos::ParameterList& p){ is_constant = false; if (type == "Truncated KL Expansion") randField = UNIFORM; else if (type == "Log Normal RF") randField = LOGNORMAL; Teuchos::RCP<PHX::DataLayout> scalar_dl = p.get< Teuchos::RCP<PHX::DataLayout> >("QP Scalar Data Layout"); Teuchos::RCP<PHX::DataLayout> vector_dl = p.get< Teuchos::RCP<PHX::DataLayout> >("QP Vector Data Layout"); PHX::MDField<MeshScalarT,Cell,QuadPoint,Dim> fx(p.get<std::string>("QP Coordinate Vector Name"), vector_dl); coordVec = fx; this->addDependentField(coordVec); exp_rf_kl = Teuchos::rcp(new Stokhos::KL::ExponentialRandomField<MeshScalarT>(sublist)); int num_KL = exp_rf_kl->stochasticDimension(); // Add KL random variables as Sacado-ized parameters rv.resize(num_KL); Teuchos::RCP<ParamLib> paramLib = p.get< Teuchos::RCP<ParamLib> >("Parameter Library", Teuchos::null); for (int i=0; i<num_KL; i++) { std::string ss = Albany::strint("Permittivity KL Random Variable",i); new Sacado::ParameterRegistration<EvalT, SPL_Traits>(ss, this, paramLib); rv[i] = sublist.get(ss, 0.0); } } // (type == "Truncated KL Expansion" || type == "Log Normal RF")
haskell_range<T> operator| ( TFx&& fx, const haskell_range<T>& set ) { std::vector<T> comprehension; comprehension.reserve( set.items.size() ); for ( auto& item : set ) { comprehension.emplace_back( fx( item ) ); } return haskell_range<T>( std::move( comprehension ) ); }
//计算f(x) int fx(int x) { if(x = 1) return 1; else{ return fx(x-1)*x; } }
void CameraCalibration::set4Params(float _fx, float _fy, float _cx, float _cy){ m_intrinsic = cv::Matx33f::zeros(); fx() = _fx; fy() = _fy; cx() = _cx; cy() = _cy; }
A jtfxeachv(J jt,I r,A w){A*wv,x,z,*zv;I n,wd; RZ(w); n=AN(w); wv=AAV(w); wd=(I)w*ARELATIVE(w); ASSERT(r>=AR(w),EVRANK); ASSERT(n,EVLENGTH); ASSERT(BOX&AT(w),EVDOMAIN); GA(z,BOX,n,AR(w),AS(w)); zv=AAV(z); DO(n, RZ(zv[i]=x=fx(WVR(i))); ASSERT(VERB&AT(x),EVDOMAIN););
set_build<T> operator| ( const set_build<T>& set, TFx&& fx ) { std::vector<T> comprehension; comprehension.reserve( set.items.size() ); for ( auto& item : set ) { comprehension.emplace_back( fx( item ) ); } return set_build<T>( std::move( comprehension ) ); }
Absorption<EvalT, Traits>:: Absorption(Teuchos::ParameterList& p) : absorption(p.get<std::string>("QP Variable Name"), p.get<Teuchos::RCP<PHX::DataLayout> >("QP Scalar Data Layout")) { Teuchos::ParameterList* cond_list = p.get<Teuchos::ParameterList*>("Parameter List"); Teuchos::RCP<PHX::DataLayout> vector_dl = p.get< Teuchos::RCP<PHX::DataLayout> >("QP Vector Data Layout"); std::vector<PHX::DataLayout::size_type> dims; vector_dl->dimensions(dims); numQPs = dims[1]; numDims = dims[2]; std::string type = cond_list->get("Absorption Type", "Constant"); if (type == "Constant") { is_constant = true; constant_value = cond_list->get("Value", 1.0); // Add absorption as a Sacado-ized parameter Teuchos::RCP<ParamLib> paramLib = p.get< Teuchos::RCP<ParamLib> >("Parameter Library", Teuchos::null); this->registerSacadoParameter("Absorption", paramLib); } #ifdef ALBANY_STOKHOS else if (type == "Truncated KL Expansion") { is_constant = false; Teuchos::RCP<PHX::DataLayout> scalar_dl = p.get< Teuchos::RCP<PHX::DataLayout> >("QP Scalar Data Layout"); PHX::MDField<MeshScalarT,Cell,QuadPoint,Dim> fx(p.get<std::string>("QP Coordinate Vector Name"), vector_dl); coordVec = fx; this->addDependentField(coordVec); exp_rf_kl = Teuchos::rcp(new Stokhos::KL::ExponentialRandomField<RealType>(*cond_list)); int num_KL = exp_rf_kl->stochasticDimension(); // Add KL random variables as Sacado-ized parameters rv.resize(num_KL); Teuchos::RCP<ParamLib> paramLib = p.get< Teuchos::RCP<ParamLib> >("Parameter Library", Teuchos::null); for (int i=0; i<num_KL; i++) { std::string ss = Albany::strint("Absorption KL Random Variable",i); this->registerSacadoParameter(ss, paramLib); rv[i] = cond_list->get(ss, 0.0); } } #endif else { TEUCHOS_TEST_FOR_EXCEPTION(true, Teuchos::Exceptions::InvalidParameter, "Invalid absorption type " << type); } this->addEvaluatedField(absorption); this->setName("Absorption" ); }
int main() {double x1=5,x2,y1,y2,x,y=APPROX; unsigned iterations=0; y1=fx(x1);x2=x1-1;y2=fx(x2);clrscr(); clrscr(); while(fabs(y)>=APPROX) {x=x1-y1/(y1-y2)*(x1-x2); y=fx(x); x2=x1,y2=y1; x1=x,y1=y; iterations++; printf("Iteration%d: x=%f\n",iterations,x); } printf("\nThe Root of the Equation is :\ %f\nTotal Iterations=%u",x,iterations); getch(); return 0; }
int main(void) { int i,nb=NBMAX; float *xb1,*xb2; xb1=vector(1,NBMAX); xb2=vector(1,NBMAX); zbrak(fx,X1,X2,N,xb1,xb2,&nb); printf("\nbrackets for roots of bessj0:\n"); printf("%21s %10s %16s %10s\n","lower","upper","f(lower)","f(upper)"); for (i=1;i<=nb;i++) printf("%s %2d %10.4f %10.4f %3s %10.4f %10.4f\n", " root ",i,xb1[i],xb2[i]," ", fx(xb1[i]),fx(xb2[i])); free_vector(xb2,1,NBMAX); free_vector(xb1,1,NBMAX); return 0; }
void BehaviorFunction::update(float dt) { timeAlive += dt; if(fx){ var->x = fx(timeAlive); } if(fy){ var->y = this->fy(timeAlive); } }
haskell_range<T> operator% ( TFx&& fx ) { std::vector<T> filtered; filtered.reserve( items.size() ); for ( auto&& item : items ) { if ( fx( item ) ) filtered.emplace_back( item ); } items = std::move( filtered ); return *this; }
cv::Point3d PinholeCameraModel::projectPixelTo3dRay(const cv::Point2d& uv_rect) const { assert( initialized() ); cv::Point3d ray; ray.x = (uv_rect.x - cx() - Tx()) / fx(); ray.y = (uv_rect.y - cy() - Ty()) / fy(); ray.z = 1.0; return ray; }
/***定义求解搜索方向函数Sk*********/ void solveS(double x,double y,double *s) //在(x,y)处求解,s为存放搜索向量 { double a[2],A; a[0]=fx(x,y); //偏x值 a[1]=fy(x,y); //偏y值 A=sqrt(a[0]*a[0]+a[1]*a[1]); s[0]=-a[0]/A; //归一化 s[1]=-a[1]/A; }
//fx Declaration //PURPOSE: Recursive function to process f(x) = f(x-1) + 2 //AUTHOR: Brodie Davis //DATE CREATED: 12/12/2015 //Function's Dictionary of Variables ///x is input ///result is used to return the result of the calculations //Function's Inputs ///input value from main function int fx(int x){ int result=0; //printf("\nfx round %d",++counter); //debugging statement, shows number of times function calls itself if(x<=0) result = 0; else result = fx(x-1)+2; return result; }
void TruncatedKL<EvalT,Traits>:: DependentFields(Source<EvalT,Traits> &source, Teuchos::ParameterList& p) { Teuchos::RCP<PHX::DataLayout> vector_dl = p.get< Teuchos::RCP<PHX::DataLayout> >("QP Vector Data Layout"); PHX::MDField<MeshScalarT,Cell,Point,Dim> fx(p.get<std::string>("QP Coordinate Vector Name"), vector_dl); m_coordVec = fx; source.addDependentField(m_coordVec); }
set_build<T>& operator, ( TFx&& fx ) { std::vector<T> filtered; filtered.reserve( items.size() ); for ( auto&& item : items ) { if ( fx( item ) ) filtered.emplace_back( item ); } items = std::move( filtered ); return *this; }
static T__ fxy(const T__ &y, const T__ &x, const size_t &nx, const size_t &ny) { switch(nx) { case(0): { switch(ny) { case(0): { return f(y,x); break; } case(1): { return fy(y,x); break; } default: { // TODO: NEED TO IMPLEMENT THIS assert(false); return 0; break; } } } case(1): { switch(ny) { case(0): { return fx(y,x); break; } default: { // TODO: NEED TO IMPLEMENT THIS assert(false); return 0; break; } } } default: case(2): { // TODO: IMPLEMENT THIS assert(false); return 0; break; } } }
void NR::zbrak(DP fx(const DP), const DP x1, const DP x2, const int n, Vec_O_DP &xb1, Vec_O_DP &xb2, int &nroot) { int i; DP x,fp,fc,dx; int nb=xb1.size(); nroot=0; dx=(x2-x1)/n; fp=fx(x=x1); for (i=0;i<n;i++) { fc=fx(x += dx); if (fc*fp <= 0.0) { xb1[nroot]=x-dx; xb2[nroot++]=x; if(nroot == nb) return; } fp=fc; } }
void ConstitutiveModelParameters<EvalT, Traits>:: parseParameters(const std::string &n, Teuchos::ParameterList &p, Teuchos::RCP<ParamLib> paramLib) { Teuchos::ParameterList pl = p.get<Teuchos::ParameterList*>("Material Parameters")->sublist(n); std::string type_name(n + " Type"); std::string type = pl.get(type_name, "Constant"); if (type == "Constant") { is_constant_map_.insert(std::make_pair(n, true)); constant_value_map_.insert(std::make_pair(n, pl.get("Value", 1.0))); new Sacado::ParameterRegistration<EvalT, SPL_Traits>(n, this, paramLib); if (have_temperature_) { if (pl.get<std::string>("Temperature Dependence Type", "Linear") == "Linear") { temp_type_map_.insert(std::make_pair(n,"Linear")); dparam_dtemp_map_.insert (std::make_pair(n, pl.get<RealType>("Linear Temperature Coefficient", 0.0))); ref_temp_map_.insert (std::make_pair(n, pl.get<RealType>("Reference Temperature", -1))); } else if (pl.get<std::string>("Temperature Dependence Type", "Linear") == "Arrhenius") { temp_type_map_.insert(std::make_pair(n,"Arrhenius")); pre_exp_map_.insert( std::make_pair(n, pl.get<RealType>("Pre Exponential", 0.0))); exp_param_map_.insert( std::make_pair(n, pl.get<RealType>("Exponential Parameter", 0.0))); } } } else if (type == "Truncated KL Expansion") { is_constant_map_.insert(std::make_pair(n, false)); PHX::MDField<MeshScalarT, Cell, QuadPoint, Dim> fx(p.get<std::string>("QP Coordinate Vector Name"), dl_->qp_vector); coord_vec_ = fx; this->addDependentField(coord_vec_); exp_rf_kl_map_. insert( std::make_pair(n, Teuchos::rcp( new Stokhos::KL::ExponentialRandomField<MeshScalarT>(pl)))); int num_KL = exp_rf_kl_map_[n]->stochasticDimension(); // Add KL random variables as Sacado-ized parameters rv_map_.insert(std::make_pair(n, Teuchos::Array<ScalarT>(num_KL))); for (int i(0); i < num_KL; ++i) { std::string ss = Albany::strint(n + " KL Random Variable", i); new Sacado::ParameterRegistration<EvalT, SPL_Traits>(ss, this, paramLib); rv_map_[n][i] = pl.get(ss, 0.0); } } }
int main(){ int n,i,j; char s[100]; char c; fx(4); int y = fx(5); strcpy(s,"000123456"); strcpy(s,"0001'''3456"); printf("%s_\n",s); c = '0'; c = '\"'; c = '"'; //putchar(c); n=100; for (i=2;i<=n;i++){ for (j=2;j*j<=i;j++) if (i%j==0) break; if (j*j>i) printf("%d\n",i); } return 0; }
double max_euler_error(size_t k, Vector const *euler_ys_half_h) { double max_f = 0; double max_fx = 0; double max_fy = 0; for (size_t i = 0; i < euler_ys_half_h->size; ++i) { max_f = max(max_f, fabs(f(get_x(i, 0.5 * h), euler_ys_half_h->values[i]))); max_fx = max(max_fx, fabs(fx(get_x(i, 0.5 * h), euler_ys_half_h->values[i]))); max_fy = max(max_fy, fabs(fy(get_x(i, 0.5 * h), euler_ys_half_h->values[i]))); } return 0.5 * (max_fx + max_f * max_fy) / max_fy * h * exp(max_fy * (get_x(k, h) - get_x(0, h))); }