2015-05-19 114 views
1

我需要在某个组件的整个生命周期内生成一定数量的随机故障。我拥有组件的故障率,即如果我知道它在720小时的工作中失败了6次,那么它的故障率是6/720 = 0.0083次/小时。 现在,如果我考虑两种可能的功能状态(0 =组件工作正常,1 =组件失败),我想在Matlab中创建一个脚本,为我提供一个数组,该数组对于720小时生命周期,它会根据已知的故障率给出0或1,无论组件是否工作。非常感谢。如何根据给定的概率生成随机事件?

+1

该解决方案的假设很强烈依赖有关如何世界的作品。例如。如果某个组件发生故障,它是否保持失败,是否可以返回到功能状态,还是由相同的组件替换?失败事件的分布是什么?另见:[生存分析](http://en.wikipedia.org/wiki/Survival_analysis) –

+0

既然你提到“每个小时”,我想你想考虑离散时间? –

回答

0

之一,是许多的解决方案:

numFailures = 6; 
timeLength = 720; % hours 

% create array with one element per hour 
p = false(1, timeLength); 
p(1:numFailures) = true; 

% randomly sort p 
p = p(randperm(timeLength)); 

% generate a random index for sampling 
index = randi(timeLength, 1); 

% Sample the array 
% this will be true if there was a failure 
p(index) 
+1

将下摆放在相同的答案! –

2

又如

numFailures = 6; 
timeLength = 720; % hours 

pFailure = numFailures/timeLength; 

% call this to randomly determine if there was a failure. If called enough times the probability of 1 will be equal to pFailure 
isFailed = rand(1) < pFailure; 

我们可以通过调用在一个循环验证:

for k=1:1e5 
    isFailed(k) = rand(1) < pFailure; 
end 



sum(isFailed)/k 

ans = 

    0.008370000000000