Write a c algorithm for the problem below Not an actual code
Write a c++ algorithm for the problem below. (Not an actual code - jus verbal insructions of what in put is needed, what output is expected the step by step process and the test data)
The amount of material left after decay of radioactive isotope is given by the equation
Qt = Q0 e-t
where Q0 is the initial amount of the radioactive material, is the decay constant, and t is the elapsed time in years and Qt is the amount after t years have elapsed. Develop a process to prompt the user to enter the original amount of carbon 14 present and the current amounts of carbon 14. Given the decay constant for carbon 14 is 0.00012097 per year, determine the amount of time that has elapsed. (For now assume the users enters a larger values for the original amounts than for the current amounts and both arrays are the same size.)
Solution
C++ program
#include<iostream>
#include <math.h> // exp() function
#include <stdlib.h> // abs() function
using namespace std;
int main()
{
double Q0,Qt,f,df,err,t_new; // variables
double t = 5,tol = 0.00000001,lamda = 0.00012097;// t: initial guess, tol: tolerence
cout << \"Enter the original amount of carbon 14 present Q0 = \";
cin >> Q0;
cout << \"Enter current amounts of carbon 14 Qt = \";
cin >> Qt;
f = Qt-Q0*exp(-1*lamda*t); // the equation of decay of radioactive isotope
df = lamda*Q0*exp(-1*lamda*t); // derivative of decay of radioactive isotope
err = abs(f/df);
while( err>tol) // loop til accuracy achieves
{
t_new = t - f/df; // updating t using Newtons method
err = abs(t_new-t);// finding error
t = t_new;
f = Qt-Q0*exp(-1*lamda*t);// evaluating the equation of decay of radioactive isotope for new t
df = lamda*Q0*exp(-1*lamda*t);// evaluating the derivative of decay of radioactive isotope for new t
}
cout << \"Time elapsed = \" << t << \"years\" << endl; // output
return 0;
}
OUTPUT
$ g++ radioactive_decay.cpp -lm
$ ./a.out
Enter the original amount of carbon 14 present Q0 = 1000
Enter current amounts of carbon 14 Qt = 500
Time elapsed = 5729.91 years
