Advertisement
Guest User

Untitled

a guest
Jun 15th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.51 KB | None | 0 0
  1. %% Pushing the limit of all diamond anvils
  2. % Edoweiss
  3. % 2018-06-15
  4.  
  5. close all; clear all; clc
  6.  
  7. %% simulations parameters
  8. trials = 100000;
  9. available_potential = 13;
  10. initial_level = 5;
  11.  
  12. %% Setup
  13. pTable = [  1
  14.             1
  15.             1
  16.             1
  17.             1
  18.             0.88
  19.             0.78
  20.             0.68
  21.             0.59
  22.             0.51
  23.             0.50
  24.             ];
  25.  
  26. d_levels = [];
  27.  
  28. %% Diamond Anvils
  29. % we keep trying until we run out of diamond anvils or potential
  30. for i = 1:trials;
  31.     pot = available_potential; % potential remaining
  32.     lvl = initial_level; % current enhancement level
  33.     while pot > 0 && lvl < 40
  34.         if lvl < length(pTable)
  35.             check = pTable(lvl+1);
  36.         else
  37.             check = 0.50;
  38.         end
  39.         if rand < check % success
  40.             lvl = lvl + 1;
  41.         else %failure
  42.             pot = pot - 1;
  43.         end
  44.     end
  45.     d_levels = [d_levels; lvl];
  46. end
  47.  
  48. %%
  49. fig1 = figure;
  50. [h_d,e_d]  = histcounts(d_levels,'Normalization','pdf');
  51. for i = 1:length(e_d)-1 % get centers of bins
  52.     c_d(i) = (e_d(i)+e_d(i+1))/2;
  53. end
  54.  
  55. area(c_d,h_d)
  56.  
  57. ylabel('Probability Density')
  58. xlabel('enhancement level')
  59. saveas(fig1,'dia-maxpdf.png')
  60.  
  61. %%
  62. fig2 = figure;
  63. [h_d,e_d]  = histcounts(d_levels,'Normalization','cdf');
  64. for i = 1:length(e_d)-1 % get centers of bins
  65.     c_d(i) = (e_d(i)+e_d(i+1))/2;
  66. end
  67. c_d = [5 c_d];
  68. h_d = [1 1-h_d];
  69. area(c_d,h_d)
  70.  
  71. ylabel('Probability')
  72. xlabel('enhancement level')
  73. saveas(fig2,'dia-maxcdf.png')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement