double mu_e_2(double n, double np, double f, set_const * C) { double res = pow(C->C_r, 2.0) * D *(n - 2.0 * np) / (2.0 * m_n *m_n* C->eta_r(f)); //cout << res << endl; res -= sqrt(pow(m_n * C->phi_n(f), 2.0) + pow(p_f(np), 2.0)); //cout << res << endl; res += sqrt(pow(m_n * C->phi_n(f), 2.0) + pow(p_f(n - np), 2.0)); //cout << res << endl; return res; }
double mu_e(double n, double np, double f, set_const * C) { double res = pow(C->C_r, 2.0) * D *(n - 2.0 * np) / (2.0 * m_n *m_n* C->eta_r(f)); res -= sqrt(pow(m_n * C->phi_n(f), 2.0) + pow(p_f(np), 2.0)); res += sqrt(pow(m_n * C->phi_n(f), 2.0) + pow(p_f(n - np), 2.0)); double dn = 1e-6; if (dn > np){ dn = np / 2.0; } double mu_n = (t_E(n - np - 2 * dn, np, f, C) - 8 * t_E(n - np - dn, np, f, C) + 8 * t_E(n - np + dn, np, f, C) - t_E(n - np + 2 * dn, np, f, C)) / (12 * D * dn); double mu_p = (t_E(n - np, np - 2 * dn, f, C) - 8 * t_E(n - np, np - dn, f, C) + 8 * t_E(n - np, np + dn, f, C) - t_E(n - np, np + 2 * dn, f, C)) / (12 * D * dn); double res2 = mu_n - mu_p; return res; }
void ConvexPolygon::project(const Eigen::Vector3d& p, Eigen::Vector3d& output) { Eigen::Vector3f output_f; Eigen::Vector3f p_f(p[0], p[1], p[2]); project(p_f, output_f); pointFromVectorToVector<Eigen::Vector3f, Eigen::Vector3d>(output_f, output); }
void stfnum::c_jac_lour(double *p, double *jac, int m, int n, void *adata) { // m: the number of parameters that are to be fitted // adata: pointer to a struct that (1) specifies which parameters are to be fitted // and (2) contains the constant parameters fitInfo *fInfo=static_cast<fitInfo*>(adata); // total number of parameters, including constants: int tot_p=(int)fInfo->fit_p.size(); // all parameters, including constants: Vector_double p_f(tot_p); for (int n_tp=0,n_p=0,n_f=0;n_tp<tot_p;++n_tp) { // if the parameter needs to be fitted... if (fInfo->fit_p[n_tp]) { // ... take it from *p, ... p_f[n_tp] = p[n_p++]; } else { // ... otherwise, take it from the fInfo struct: p_f[n_tp] = fInfo->const_p[n_f++]; } } for (int n_x=0,n_j=0;n_x<n;++n_x) { // jac_f will calculate the derivatives of all parameters, // including the constants... Vector_double jac_f(jac_lour((double)n_x*fInfo->dt,p_f)); // ... but we only need the derivatives of the non-constants... for (int n_tp=0;n_tp<tot_p;++n_tp) { // ... hence, we will eliminate the derivatives of the constants: if (fInfo->fit_p[n_tp]) { jac[n_j++]=jac_f[n_tp]; } } } }
int main() { static seq[4] = {1, 2, 5, 20}; int i, j, df1; for (i = 0; i < 4; i++) { df1 = seq[i]; printf("***** p_f(%d, df2, f) *****\n", df1); printf(" F %-16s %-16s %-16s %-16s\n", "df2=1", "df2=2", "df2=5", "df2=20"); for (j = 0; j <= 10; j++) printf("%4d %16.14f %16.14f %16.14f %16.14f\n", j, p_f(df1, 1, j), p_f(df1, 2, j), p_f(df1, 5, j), p_f(df1, 20, j)); } return EXIT_SUCCESS; }
double p_f_d(double x) { int i = 1; double r = 1.0f; for ( ; i <= 6 ; i++ ) { r = r + ( p_f(x) / ( x - ( ( i + 1 ) / ( 10 * i ) ) ) ); } return r; }
void stfnum::c_func_lour(double *p, double* hx, int m, int n, void *adata) { // m: the number of parameters that are to be fitted // adata: pointer to a struct that (1) specifies which parameters are to be fitted // and (2) contains the constant parameters fitInfo *fInfo=static_cast<fitInfo*>(adata); // total number of parameters, including constants: int tot_p=(int)fInfo->fit_p.size(); // all parameters, including constants: Vector_double p_f(tot_p); for (int n_tp=0, n_p=0, n_f=0;n_tp<tot_p;++n_tp) { // if the parameter needs to be fitted... if (fInfo->fit_p[n_tp]) { // ... take it from *p, ... p_f[n_tp] = p[n_p++]; } else { // ... otherwise, take it from the fInfo struct: p_f[n_tp] = fInfo->const_p[n_f++]; } } for (int n_x=0;n_x<n;++n_x) { hx[n_x]=func_lour( (double)n_x*fInfo->dt, p_f); } }
int evaluate(int t) { int err = 0; /* switch on lookup */ switch(t) { case '+': case '-': case '*': case '/': /* binaere rechenoperation */ /* wenn fehlerwert zurueckgegeben wird wird die fehlerroutine aufgerufen */ if((err = binop_f(t))) error(err); break; /* stack metafunctionen */ case 'p': if((err = p_f())) error(err); break; case 'f': if((err = f_f())) error(err); break; case 'c': if((err = c_f())) error(err); break; case 'd': if((err = d_f())) error(err); break; case 'r': if((err = r_f())) error(err); break; /* EOS fuer stdin oder 'q' -> quit */ case EOF: printf("Reached end of input.\n"); case 'q': printf("Goodbye.\n"); return FALSE; default: /* wenn lookup whitespace ist, ignorieren */ if(isws(t)) ; /* andernfalls wenn lookup eine ziffer ist zahl einlesen und auf den stack legen */ else if(isnum(t)) { uint v = 0; if((err = read_int(&v)) || (err = stack_push(v))) { error(err); } /* recursion damit der lookup nach einlesen der zahl nicht in main ueberschrieben wird. */ return evaluate(lookup(NULL)); } /* andernfalls ist ein unbekannter befehl eingelesen worden */ else { error(ERR_MAIN_UNKNOWN); } } return TRUE; }
void ConvexPolygon::project(const Eigen::Vector3d& p, Eigen::Vector3f& output) { Eigen::Vector3f p_f(p[0], p[1], p[2]); project(p_f, output); }
double t_E(std::vector<double> n, double f, set_const * C) { double res = 0.5 * pow(m_n * m_n * f / C->C_s, 2.0)*C->eta_s(f); res += C->U(f); int num = n.size(); /*std::vector<double> nvec; for (int i = 0; i < num; i++){ nvec.push_back(boost::python::extract<double>(n[i])); }*/ double o_sum = 0; double r_sum = 0; for (int i = 0; i < num; i++){ // cout << i << ", n[i] = " << n[i] << ", pf = " << p_f(n[i]) << endl; //res += KineticIntegral(p_f(n[i]), C->M[i] * C->phi_n(C->X_s[i] * f), C); res += KineticIntegral(p_f(n[i]), C->M[i] * C->phi_n(C->X_s[i] * (C->M[0]/C->M[i]) * f), C); o_sum += C->X_o[i] * n[i]; r_sum += C->X_r[i] * C->T[i] * n[i]; } res += 0.5 * pow(C->C_o * D * (o_sum) / m_n, 2.0) / (C->eta_o(f)); res += 0.5 * pow(C->C_r * D * (r_sum) / m_n, 2.0) / (C->eta_r(f)); //double me = m_e; //double pf_e = 0; //if (pow(mu_e(n[0] + n[1], n[1], f, C), 2.0) - me*me >= 0){ // pf_e = sqrt(pow(mu_e(n[0] + n[1], n[1], f, C), 2.0) - me*me); //} //if (n[1] != 0.0){ // res += KineticIntegral(pf_e, m_e, C); //} //double mmu = m_mu; //double pf_mu = 0; //if (pow(mu_e(n[0] + n[1], n[1], f, C), 2.0) - mmu*mmu >= 0){ // pf_mu = sqrt(pow(mu_e(n[0] + n[1], n[1], f, C), 2.0) - mmu*mmu); //} //if (n[1] != 0.0){ // res += KineticIntegral(pf_mu, m_mu, C); //} //gsl_function F; //F.function = &func_e; //double result = 0.0; //double error; //double me = m_e; //F.params = &me; //double pf_e = 0; //if (pow(mu_e_2(n[0] + n[1], n[1], f, C), 2.0) - me*me >= 0){ // pf_e = sqrt(pow(mu_e_2(n[0] + n[1], n[1], f, C), 2.0) - me*me); //} //// cout << "MU_E = " << mu_e(nn+np, np, f, C) << endl; //gsl_integration_qags(&F, 0.0, pf_e, 0, 1e-10, 1000, w_t_E, &result, &error); //if (n[1] != 0.0){ // //cout << "hey! " << np << endl; // res += result / (pi*pi); //} ////cout << "RESULT " << result << endl; //double mmu = m_mu; //F.params = &mmu; //double pf_mu = 0; //if (pow(mu_e_2(n[0] + n[1], n[1], f, C), 2.0) - mmu*mmu >= 0){ // pf_mu = sqrt(pow(mu_e_2(n[0] + n[1], n[1], f, C), 2.0) - mmu*mmu); //} //gsl_integration_qags(&F, 0.0, pf_mu, 0, 1e-10, 1000, w_t_E, &result, &error); //if (n[1] != 0.0){ // //cout << "hey! " << np << endl; // res += result / (pi*pi); //} return res; }