How can I model the decay rate of Carbon 11 and its bar graph?

4 vues (au cours des 30 derniers jours)
Carly Williams
Carly Williams le 23 Avr 2019
Commenté : Carly Williams le 24 Avr 2019
So I'm needing to model decay of carbon and I've gotten very close. I just need to figure out how to manipulate my code to be more exponential and less linear. I've been told to relplicate the decay of each atom, I'm just not sure how to fix my code.
k = .0338;
t = 1:100;
TheoR = 100*exp(-k*t);
f = zeros(1,100);
R = zeros(1,100);
N = 100;
for i = 1:100
for j = 1:100
r = rand();
if r < .0338 % atom decays
f(j) = 1;
end
end
R(i) = N - sum(f(1:i));
end
figure
bar(1:100,R);
hold on
plot(t,TheoR);
This is what it is supposed to look like.
carbondecay.png

Réponse acceptée

James Tursa
James Tursa le 24 Avr 2019
You need to account for all of the atoms in your plot. E.g., this
R(i) = N - sum(f(1:i)); % <-- Wrong, you are only plotting the first "i" number of atoms
should be this
R(i) = N - sum(f); % Here you are plotting all of the atoms at each step

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by