%% Set the parameters of the simulation
Cs=1; % this is the initial condition
T=30; % this is the half-life time (we are making the simulation code general)
N=60; % this is simulation time (number of simulation steps)
%% Run the simulation
a = exp(-log(2)/T); % this is the calculation to find out the proportion left after a year
% we shall store the results in an array for plotting or further processing
Cs_sim=zeros(N,1); % the initial array of 60 zeroes
% now the simulation
for i=1:N
Cs=a*Cs; % calculate the new value from the old value (Cs_new=a*Cs_old)
Cs_sim(i)=Cs; % ... and store the result
end
% and plotting:
plot(Cs_sim)
% nicer plot
plot((1:N),Cs_sim,'r-',(1:N),Cs_sim,'b.')
title(['Radioactive decay: T_{1/2}=' num2str(T)])