MATLAB Answers

0

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

Asked by Carly Williams on 23 Apr 2019
Latest activity Commented on by Carly Williams on 24 Apr 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

  0 Comments

Sign in to comment.

1 Answer

Answer by James Tursa
on 24 Apr 2019
 Accepted Answer

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

  1 Comment

That's exactly it. Thank you so much!

Sign in to comment.