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

### Carly Williams (view profile)

on 23 Apr 2019
Latest activity Commented on by Carly Williams

on 24 Apr 2019

### James Tursa (view profile)

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.

### James Tursa (view profile)

on 24 Apr 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

Carly Williams

### Carly Williams (view profile)

on 24 Apr 2019
That's exactly it. Thank you so much!