Write your question here.
here is code that works every cycle:
// non-lin (oscillator), Last point approx. (Cromer) version (w/ quadratic dissipation and momentary drive).
// Is an approximation for the numerical integration of a clock's equation of motion: ~ a Synchronome
#include <iostream>
#include <fstream> /* for output file */
#include <cmath>
#include <iomanip> /* for setw() */
#include <stdlib.h> /* for exit() */
using namespace std;
// The expression "\"" is just too ugly.
// Define a nicer-looking synonym:
string const Q = "\"";
// C++ modulo operator "%" only works for integers
// Generalize to doubles
double mod(double const num, double const denom){
return num - denom * floor(num / denom);
}
////////////////////////////////////////
// Main program
//
int main() {
cout << "/////////////////////////////////////" << endl;
cout << "Is the numerical model of a clock pendulum," << endl;
cout << "w/ gravity type drive every 30s, and quadratic dissipation. " << endl;
cout << "and uses the LPA aproximation." << endl;
cout << "///////////////////////////////" << endl;
double period = 2;
double theta = 0.1; //radian ~ 4" / one meter
double d = 1e-4; //temporarily
double dr = 0;
double thetadot = 0;
double energy = thetadot*thetadot * 100;
double t = 0;
double steps_per_cycle = 1e3;
double deltat = period / steps_per_cycle;
double r =3.6e-4; // temporary 'till driving set
cout << "r ~= 3.6e-4 means Q~= 8.7k for a 2s period" << endl;
// cout << "enter drive amplitude; try 1.0e-4"<< endl;
// cin >> d;
cout << "Enter number of steps total: " << endl;
double stop = 0;
cin >> stop;
double po_per_cycle = 1e3; // again temporary
// cin >> po_per_cycle;
double mod_number = steps_per_cycle / po_per_cycle;
cout << "Enter data output filenname. Remember to add the extension: .txt!!!!"<< endl;
string out_filename;
cin >> out_filename;
// Print out something every mod_number steps, (or as close thereto as we can, if mod_number is not an integer).
// Also print out the very last result, (which will not be evenly spaced if total duration
// is not an integer multiple of the spacing between printouts).
if (N == stop || (mod(N + 0.5, mod_number)) < 1) {
p(ouch, t, theta, thetadot, deltag_now, dr, r, energy);
}
} // end main loop
}
The problem w/ this code is the drive (dr is only one side of when theta is zero. To simulate the clock the drive must be "on" equally before and after when the pendulum is at bottom dead center, that is when the angle theta is zero. I'm too new w/ this type coding to solve this after several days work. I need it to submit to a horological science newsletter.