Cody

# Problem 44684. Basic Monte Carlo Simulation

Solution 1556329

Submitted on 11 Jun 2018 by bainhome
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
input1 = [ 2 0.4 5 0.4 9 0.2]; input2 = 0.125; serviceTimeCorrect = 2; assert(isequal(rand2ServiceTime(input1,input2),serviceTimeCorrect))

2   Pass
input1 = [ 2 0.4 5 0.4 9 0.2]; input2 = 0.4; serviceTimeCorrect = 2; assert(isequal(rand2ServiceTime(input1,input2),serviceTimeCorrect))

3   Pass
input1 = [ 2 0.4 5 0.4 9 0.2]; input2 = 0.474; serviceTimeCorrect = 5; assert(isequal(rand2ServiceTime(input1,input2),serviceTimeCorrect))

4   Pass
input1 = [ 2 0.4 5 0.4 9 0.2]; input2 = 0.85; serviceTimeCorrect = 9; assert(isequal(rand2ServiceTime(input1,input2),serviceTimeCorrect))

5   Pass
input1 = [ (45:-1:36)' repmat(0.1,10,1)]; input2 = 0.958; serviceTimeCorrect = 36; assert(isequal(rand2ServiceTime(input1,input2),serviceTimeCorrect))

6   Pass
input1 = [ 1 0.5 2 0.5]; input2 = 0.5; serviceTimeCorrect = 1; assert(isequal(rand2ServiceTime(input1,input2),serviceTimeCorrect))

7   Pass
input1 = [ 1 0.5 2 0.5]; input2 = 0.6; serviceTimeCorrect = 2; assert(isequal(rand2ServiceTime(input1,input2),serviceTimeCorrect))

8   Pass
input1 = [ 2 0.2 3 0.2 4 0.2 5 0.2 6 0.2]; serviceTimeCorrect = 2; for idx = 0.01:0.01:0.2 assert(isequal(rand2ServiceTime(input1,idx),serviceTimeCorrect)) assert(isequal(rand2ServiceTime(input1,idx+0.2),serviceTimeCorrect+1)) assert(isequal(rand2ServiceTime(input1,idx+0.4),serviceTimeCorrect+2)) assert(isequal(rand2ServiceTime(input1,idx+0.6),serviceTimeCorrect+3)) assert(isequal(rand2ServiceTime(input1,idx+0.8),serviceTimeCorrect+4)) end

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!