/* Routine di integrazione. Gli argomenti sono: * _ double (*f)(double) -> puntatore alla funzione integranda; * _ double (*method)(double (*g)(double), double, double) -> puntatore alla * funzione per il metodo di integrazione; * _ double a, double b -> estremi di integrazione; * _ int N -> numero di sottointervalli per integrazione composita. */ double integration (double (*f)(double), double (*method)(double (*g)(double), double, double), double a, double b, int N) { if(a == b) return 0; int i; double S = 0; double step; step = (b - a)/N; /* Per diminuire errori di somma (per N troppo grande) si binnano -se * possibile- i sottointervalli. */ if((N%BINW)==0) { int m = N/BINW; for(i=0; i<BINW; i++) S += integration(f, method, a+i*m*step, a+(i+1)*m*step, m); } else for(i = 0; i< N; i++) S += method(f, a + i*step, a + step*(i + 1)); return S; }
/* *description: the direct method of * best square approximation. */ Poly* bsa_direct(func f, double a, double b, size_t n) { size_t i, j; Poly* res = NULL; Matrix* H = create_matrix_n(n + 1); Matrix* D = create_vector(n + 1); Matrix* A; for (i = 0; i < H->m; i++) { for (j = 0; j < H->n; j++) { double h = pow(b, i + j + 1) - pow(a, i + j + 1); H->mem[i][j] = h / (i + j + 1); } } for (i = 0; i < D->m; i++) D->mem[i][0] = integration(f, a, b, 1e-6); A = me_gauss_elim(H, D, false); for (i = 0; i < A->m; i++) poly_add_inp(&res, create_poly(A->mem[i][0], i)); destroy_matrix(&H); destroy_matrix(&D); destroy_matrix(&A); return res; }
void compare_integration(const char *root = "result.root") { gROOT->SetStyle("Plain"); TFile *f = new TFile(root); integration(f); }
PreferencesGeneralPageWidget::PreferencesGeneralPageWidget(QWidget *parent) : QWidget(parent), m_acceptLanguage(SettingsManager::getValue(QLatin1String("Network/AcceptLanguage")).toString()), m_ui(new Ui::PreferencesGeneralPageWidget) { m_ui->setupUi(this); m_ui->startupBehaviorComboBox->addItem(tr("Continue previous session"), QLatin1String("continuePrevious")); m_ui->startupBehaviorComboBox->addItem(tr("Show startup dialog"), QLatin1String("showDialog")); m_ui->startupBehaviorComboBox->addItem(tr("Show home page"), QLatin1String("startHomePage")); m_ui->startupBehaviorComboBox->addItem(tr("Show start page"), QLatin1String("startStartPage")); m_ui->startupBehaviorComboBox->addItem(tr("Show empty page"), QLatin1String("startEmpty")); const int startupBehaviorIndex(m_ui->startupBehaviorComboBox->findData(SettingsManager::getValue(QLatin1String("Browser/StartupBehavior")).toString())); m_ui->startupBehaviorComboBox->setCurrentIndex((startupBehaviorIndex < 0) ? 0 : startupBehaviorIndex); m_ui->homePageLineEdit->setText(SettingsManager::getValue(QLatin1String("Browser/HomePage")).toString()); Menu *bookmarksMenu(new Menu(Menu::BookmarkSelectorMenuRole, m_ui->useBookmarkAsHomePageButton)); m_ui->useBookmarkAsHomePageButton->setMenu(bookmarksMenu); m_ui->useBookmarkAsHomePageButton->setEnabled(BookmarksManager::getModel()->getRootItem()->rowCount() > 0); m_ui->downloadsFilePathWidget->setSelectFile(false); m_ui->downloadsFilePathWidget->setPath(SettingsManager::getValue(QLatin1String("Paths/Downloads")).toString()); m_ui->alwaysAskCheckBox->setChecked(SettingsManager::getValue(QLatin1String("Browser/AlwaysAskWhereToSaveDownload")).toBool()); m_ui->tabsInsteadOfWindowsCheckBox->setChecked(SettingsManager::getValue(QLatin1String("Browser/OpenLinksInNewTab")).toBool()); m_ui->delayTabsLoadingCheckBox->setChecked(SettingsManager::getValue(QLatin1String("Browser/DelayRestoringOfBackgroundTabs")).toBool()); m_ui->reuseCurrentTabCheckBox->setChecked(SettingsManager::getValue(QLatin1String("Browser/ReuseCurrentTab")).toBool()); m_ui->openNextToActiveheckBox->setChecked(SettingsManager::getValue(QLatin1String("TabBar/OpenNextToActive")).toBool()); PlatformIntegration *integration(Application::getInstance()->getPlatformIntegration()); if (integration == NULL || integration->isDefaultBrowser()) { m_ui->setDefaultButton->setEnabled(false); } else if (!integration->canSetAsDefaultBrowser()) { m_ui->setDefaultButton->setVisible(false); m_ui->systemDefaultLabel->setText(tr("Run Otter Browser with administrator rights to set it as a default browser.")); } else { connect(m_ui->setDefaultButton, SIGNAL(clicked()), integration, SLOT(setAsDefaultBrowser())); } connect(bookmarksMenu, SIGNAL(triggered(QAction*)), this, SLOT(useBookmarkAsHomePage(QAction*))); connect(m_ui->useCurrentAsHomePageButton, SIGNAL(clicked()), this, SLOT(useCurrentAsHomePage())); connect(m_ui->restoreHomePageButton, SIGNAL(clicked()), this, SLOT(restoreHomePage())); connect(m_ui->acceptLanguageButton, SIGNAL(clicked()), this, SLOT(setupAcceptLanguage())); }
int main(int argc, const char * argv[]) { int const nI = 64; // Number of bodies in X, Y and Z directions int const nBod = nI*nI*nI; // Total Number of bodies int const maxIter = 20; // Total number of iterations (time steps) float const initDist = 1.0; // Initial distance between the bodies float *rA; // Coordinates float *vA; // Velocities float *fA; // Forces int iter; double startTime0, endTime0; double startTime1, endTime1; char host[HOSTLEN]; rA = (float*)malloc(3*nBod*sizeof(float)); fA = (float*)malloc(3*nBod*sizeof(float)); vA = (float*)malloc(3*nBod*sizeof(float)); #pragma offload target(mic) out(numProc, host) { gethostname(host, HOSTLEN); numProc = omp_get_num_procs(); } printf("Host name: %s\n", host); printf("Available number of processors: %d\n", numProc); // Setup initial conditions initCoord(rA, vA, fA, initDist, nBod, nI); startTime0 = omp_get_wtime(); // Main loop #pragma offload target(mic) inout(rA, fA, vA:length(3*nBod)) in(nBod) for ( iter = 0; iter < maxIter; iter++ ) { forces(rA, fA, nBod); integration(rA, vA, fA, nBod); } endTime0 = omp_get_wtime(); printf("\nTotal time = %10.4f [sec]\n", endTime0 - startTime0); free(rA); free(vA); free(fA); return 0; }
void SPHSystem::sphLoop() { TIMER[NEIGHBOR].Start(); computeNeighbor(); TIMER[NEIGHBOR].Stop(); TIMER[DENSITY].Start(); computeDensityPressure(); TIMER[DENSITY].Stop(); TIMER[FORCE].Start(); computeForce(); TIMER[FORCE].Stop(); TIMER[INTEGRATION].Start(); integration(); TIMER[INTEGRATION].Stop(); numFrame++; }
void FormEditor::slotQrcFileChangedExternally(const QString &path) { QDesignerIntegration *designerIntegration = qobject_cast<QDesignerIntegration *>(integration()); if (!designerIntegration) return; QDesignerIntegration::ResourceFileWatcherBehaviour behaviour = designerIntegration->resourceFileWatcherBehaviour(); if (behaviour == QDesignerIntegration::NoWatcher) { return; } else if (behaviour == QDesignerIntegration::PromptAndReload) { QMessageBox::StandardButton button = dialogGui()->message(topLevel(), QDesignerDialogGuiInterface::FileChangedMessage, QMessageBox::Warning, tr("Resource File Changed"), tr("The file \"%1\" has changed outside Designer. Do you want to reload it?").arg(path), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); if (button != QMessageBox::Yes) return; } resourceModel()->reload(path); }
void main() { printf("Calculating integration. "); printf("Result: %lf \n", integration(func_to_calc)); }
wf wavefunction(long double e,int L,long double a,long double t,long double m){ wf result; // to store the result // variables to use in the RK long double xmin, ep, x, yp; long double a1, b1, a2, b2, a3, b3, a4, b4, Vxh, Vxnew; result.y = malloc(sizeof(long double)*5); if (result.y==NULL){ printf("Error allocating memory!\n"); return result; } xmin = minimum(L); ep = m*e; x = h; //begin of the integration according to initial conditions result.y[0] = powl(x,L+1); yp = (L+1)*powl(x,L); int i = 0; // Runge-Kutta order 4 do{ a1 = h*yp; b1 = h*Veffminusepsilon(x,L,ep)*result.y[i]; a2 = h*(yp+b1*0.5); Vxh = Veffminusepsilon(x+h*0.5,L,ep); b2 = h*Vxh*(result.y[i]+a1*0.5); a3 = h*(yp+b2*0.5); b3 = h*Vxh*(result.y[i]+a2*0.5); a4 = h*(yp+b3); Vxnew = Veffminusepsilon(x+h,L,ep); b4 = h*Vxnew*(result.y[i]+a3); long double *temp = realloc(result.y, (i+2)*sizeof(long double)); if ( temp != NULL ) //realloc was successful { result.y = temp; //printf("more memory given!\n"); } else //there was an error { free(result.y); printf("Error allocating memory!\n"); return result; } result.y[i+1] = result.y[i] + a1/6. + a2/3. + a3/3. + a4/6.; yp = yp + b1/6. + b2/3. + b3/3. + b4/6.; //printf("y = %Lf\n",result.y[i]); x = x+h; i = i+1; }while(!(Vxnew > 0 && x > xmin && result.y[i]*yp > 0 )); result.N = i; int j; long double u2[result.N]; for(j=0;j<result.N;j++){ u2[j] = result.y[j]*result.y[j]; } long double norm = integration(result.N,u2); for(j=0;j<result.N;j++){ result.y[j] = (1/sqrtl(norm))*result.y[j]; } return result; }
int main( int argc, char **argv) { //i: wait() for loop. status: used in wait() int i, status; //Stores the command line input long int m, n, r, s; //PID of the processes pid_t parent, child1, child2, child3, child4; //Used for printing to stdout char error[256], buffer[256]; sprintf( buffer, "Main Started \n" ); write( 1, buffer, strlen( buffer ) ); //Basic Error checking on inputs if ( argc == 1 ) { sprintf( error, "No arguments were given.\n" ); write( 2, error, strlen( error ) ); return ( -1 ); } if ( argc == 2 ) { sprintf( error, "Only one arguments were given.\n" ); write( 2, error, strlen( error ) ); return ( -1 ); } if ( argc == 3 ) { sprintf( error, "Only two arguments were given.\n" ); write( 2, error, strlen( error ) ); return ( -1 ); } if ( argc == 4 ) { sprintf( error, "Only three arguments were given.\n" ); write( 2, error, strlen( error ) ); return ( -1 ); } if ( argc > 5 ) { sprintf( error, "Too many arguments were given.\n" ); write( 2, error, strlen( error ) ); return ( -1 ); } //assigns input to variables m = atoi( argv[1] ); n = atoi( argv[2] ); r = atoi( argv[3] ); s = atoi( argv[4] ); parent = getpid(); sprintf( buffer, "Main Process Started\n" ); write( 1, buffer, strlen( buffer ) ); sprintf( buffer, "Number of Random Numbers = %li\n", m ); write( 1, buffer, strlen( buffer ) ); sprintf( buffer, "Fibonacci Input = %li\n", n ); write( 1, buffer, strlen( buffer ) ); sprintf( buffer, "Buffon's Needle Iterations = %li\n", r ); write( 1, buffer, strlen( buffer ) ); sprintf( buffer, "Integration Iterations = %li\n", s ); write( 1, buffer, strlen( buffer ) ); //child1 fork with error checking //It will call the method heap if all goes well if ( ( child1 = fork() ) == 0 ) { if ( getppid() != parent ) { sprintf( error, " Child1's parent does not match original parent. \n" ); write( 2, error, strlen( error ) ); return -1; } //Run function for desired operation then exit sprintf( buffer, "Heap Sort Process Created\n" ); write( 1, buffer, strlen( buffer ) ); heap( &m ); return 1; } if ( child1 < 0 ) { sprintf( error, " Child1 fork() failed. Now exiting. \n" ); write( 2, error, strlen( error ) ); return -1; } //child2 fork with error checking //It will call the method Fibonacci if all goes well if ( ( child2 = fork() ) == 0 ) { if ( getppid() != parent ) { sprintf( error, " Child2's parent does not match original parent. \n" ); write( 2, error, strlen( error ) ); return -1; } //Run function for desired operation then exit sprintf( buffer, "Fibonacci Process Created\n" ); write( 1, buffer, strlen( buffer ) ); fibonacci( &n ); return 1; } if ( child2 < 0 ) { sprintf( error, " Child2 fork() failed. Now exiting. \n" ); write( 2, error, strlen( error ) ); return -1; } //child3 fork with error checking //It will call the method buffon if all goes well if ( ( child3 = fork() ) == 0 ) { if ( getppid() != parent ) { sprintf( error, " Child3's parent does not match original parent. \n" ); write( 2, error, strlen( error ) ); return -1; } //Run function for desired operation then exit sprintf( buffer, "Buffon's Needle Process Created\n" ); write( 1, buffer, strlen( buffer ) ); buffon( &r ); return 1; } if ( child3 < 0 ) { sprintf( error, " Child3 fork() failed. Now exiting. \n" ); write( 2, error, strlen( error ) ); return -1; } //child4 fork with error checking //It will call the method integration if all goes well if ( ( child4 = fork() ) == 0 ) { if ( getppid() != parent ) { sprintf( error, " Child4's parent does not match original parent. \n" ); write( 2, error, strlen( error ) ); return -1; } //Run function for desired operation then exit sprintf( buffer, "Integration Process Created\n" ); write( 1, buffer, strlen( buffer ) ); integration( &s ); return 1; } if ( child4 < 0 ) { sprintf( error, " Child4 fork() failed. Now exiting. \n" ); write( 2, error, strlen( error ) ); return -1; } sprintf( buffer, "Main Process Waits\n" ); write( 1, buffer, strlen( buffer ) ); for (i = 0; i < 4; i++) wait( &status ); sprintf( buffer, "Main Process Exits\n" ); write( 1, buffer, strlen( buffer ) ); return 1; }