// Programm harmonischerOszillator simuliert einen harmonischen Oszillator // x'' = - w^2 x, w = 2 PI/T, der in jedem Sampling-Schritt zufaellig // gestoert wird. // // 13.10.03, Thomas Maiwald #include #include #include #include #include "nr.h" #include "nrutil.h" // Unterschiedlicher Name des Time-Headers in Windows und Unix: #ifdef WIN32 #include #else #include #endif #define PI 3.141592653589793 int main(int argc, char** argv) { // Lese Uebergabeparameter: if(argc != 3) { printf("Aufruf: harmonischerOszillator T N\n"); exit(1); } double T = atof(argv[1]); const int N = atoi(argv[2]); // Programm beenden, falls N zu klein ist if(N < 2) { printf("N muss groesser als 2 sein.\n"); exit(1); } // Aktuelle Millisekunden dienen als 'seed' fuer den Zufallszahlengenerator: long millisekunden = 0; #ifdef WIN32 struct __timeb64 timebuffer; _ftime64( &timebuffer ); millisekunden = timebuffer.millitm; #else struct timeval tp; gettimeofday(&tp, NULL); millisekunden = tp.tv_usec; #endif long idum = - millisekunden; // Simuliere harmonischen Oszillator double a1 = 2 * cos(2*PI/T); double a2 = -1; double* x = new double[N]; x[0] = 1.8; // Startwerte x[1] = 2; cout << x[0] << endl; cout << x[1] << endl; for(int i=2; i