Advertisement
Guest User

Untitled

a guest
Jan 18th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.89 KB | None | 0 0
  1.  
  2. % Setting Initial Parameters
  3. N = 2000;
  4. init_pop = [N, 0, 0, 0];
  5. half_lives = [2.5e5, 8e4, 1.6e3, 4/365];
  6. t = linspace(0, 1e6, 1000);
  7.  
  8. %Calling monte carlo simulation function
  9. pop_time_data = simulate_decay ( init_pop , half_lives , t);
  10.  
  11. l = log(2)./half_lives;
  12. % Determining analytical solution
  13. N1 = N*exp(-l(1)*t);
  14. N2 = N*(l(1)/(l(2)-l(1)))*(exp(-l(1)*t)-exp(-l(2)*t));
  15. N3 = N*l(1)*l(2)*((exp(-l(1)*t)/((l(1)-l(2))*(l(1)-l(3))))+(exp(-l(2)*t)/((l(2)-l(3))*(l(2)-l(1))))+(exp(-l(3)*t)/((l(3)-l(1))*(l(3)-l(2)))));
  16. N4 = N - (N1+N2+N3);
  17.  
  18. hold on
  19.  
  20. %Plotting analytical solution
  21. plot(t,N4,'k')
  22. plot(t,N3,'g')
  23. plot(t,N2,'r')
  24. plot(t,N1,'b')
  25.  
  26. %Plotting monte carlo solution data
  27. plot(t, pop_time_data(:,1)','--')
  28. plot(t, pop_time_data(:,2)','--')
  29. plot(t, pop_time_data(:,3)','--')
  30. plot(t, pop_time_data(:,4)','--')
  31.  
  32. xlabel("Time (years)")
  33. ylabel("Number of particles")
  34. hold off
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement