Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.56 KB | None | 0 0
  1. % Set up boxes
  2.  
  3. p = [0.8; 0.15; 0.05];
  4. X = [10; 30; 80];
  5.  
  6. Target_Value = 20;
  7.  
  8. %% Reduce smallest probability
  9.  
  10. % assume boxes are ordered
  11. assert(p(1) > 0);
  12. assert(X(1) < Target_Value);
  13. assert(Target_Value < X(2));
  14.  
  15. % E = p1*X1 + p2*X2 + (1-p1-p2)*X3
  16. if Target_Value < X(2)
  17.     % We can obtain Target_Value with positive p1.
  18.     c = (p(2)*X(2) + (1-p(1)-p(2))*X(3) - (1-p(1))*Target_Value) / p(1) / (Target_Value - X(1));
  19.     p(1) = c*p(1);
  20. end
  21. p = p / sum(p);
  22.  
  23. E = p'*X;
  24.  
  25.  
  26. >> E
  27.  
  28. E =
  29.  
  30.    20.0000
  31.  
  32. >> p
  33.  
  34. p =
  35.  
  36.     0.6923
  37.     0.2308
  38.     0.0769
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement