// Program to use the Euler-Cromer method to incrementally solve the // equation for radioactive decay, for a given mean lifetime and timestep // Author: Shawn Havery // Creation Date: 02-28-08 // Include stuff #include using namespace std; int main() { const double tmax = 15.0; // maximum time double N = 1; // current fraction of radioactive nuclei double t = 0; // current time double tau, dt; // mean lifetime and timestep cerr << "Tau: "; cin >> tau; // get mean lifetime cerr << "Timestep: "; cin >> dt; // get timestep do { cout << t << " " << N << endl; // output values t += dt; // increment time N -= dt * N / tau; // compute next N } while (t <= tmax); // repeat until max time }