Exponential decay in MATLAB

Hi,
i need to calculate exponential decay of a radioisotope and store the data in a mat file, here is what i got so far...
I need use user inputs to calculate exponential decay, display when (numYears) the atomsLeft gets below the Threshold(T), and store all the values calculated into a mat file.
N = input('Enter the number of radioactive atoms we start with (integer): ');
HL = input('The lenght of half-life(in years): ');
T = input('The target threshold number of atoms (integer): ');
numYears = 0;
%Calculate the number of years for the decay to reach the target threshold.
for x = 1:HL
atomsLeft = N.* 0.5.^(1:HL);
N = atomsLeft;
numYears = numYears + 1;
if T>N
disp(['It took ' num2str(numYears) ' years to get below the treshold']);
end
end
save('mydata.mat', 'numYears'); %saves d in the data file 'mydata.mat'
save('mydata.mat', 'atomsLeft', '-append'); %adds t to the data file
I DK if its right
Outputs are rthe number of years it takes to decay below the threshold (T) And the atomsleft after numyears
And save the data in a mat file

 Respuesta aceptada

Walter Roberson
Walter Roberson el 3 de Abr. de 2013

0 votos

One thing to fix:
atomsLeft = N.* 0.5.^(x);
It appears to me that there are other problems with the code, but you will need to indicate what your desired output is for us to be sure.

Más respuestas (1)

Jan
Jan el 3 de Abr. de 2013

0 votos

Outputs are rthe number of years it takes to decay below the threshold (T) And the atomsleft after numyears
And save the data in a mat file

Categorías

Más información sobre Particle & Nuclear Physics en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

Jan
el 3 de Abr. de 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by