Filter löschen
Filter löschen

How can I change a command after a certain value is reached?

3 Ansichten (letzte 30 Tage)
Anna Boehm
Anna Boehm am 1 Okt. 2018
Kommentiert: JohnGalt am 1 Okt. 2018

Here is my task:

"An electronic system has 4 independent components, which are all functioning. The life times (L) of the components are mutually independent, and each of them has a Weibull distribution. Whenever a component fails, it will be taken into repair instantaneously. This repair takes 1/2 units of time with probability 1/2 and 3/2 units of time with probability 1/2. After a repair, a component functions as if it were a completely new component. The repair times are mutually independent and also independent of the life times. The electronical system as a whole goes down when none of the components is functioning anymore. Management wants to know what the expected time is until the first failure."

My plan was the following:

1. Simulate the life time of each compenent with a weibull distribution

2. Let the life time go down by one time unit for each t

3. In the moment, the life time is zero, set the life time to -1/2 with probability 1/2 and to -3/2 with probability 1/2.

4. After this, the life time should go up again one life time unit per time unit till it is back at zero.

5. The moment it reaches zero again, the life time should be calculated again with the weibull distribution.

I hope this is understandable. Anyway, so far, I have point 1-3, but I don't know how to make the system go up after one failure, neither how to make it start over (point 5). My code so far is:

K=4;
T=1000;
t=1:T;
alpha=1.01;
lamda=0.249;
a=1/2;
b=3/2;
p=1/2;
for k=1:K
    u1(k,1)=rand;
    x(k,1)=((-(1/lamda))*(log(1-u1(k,1))))^(1/alpha);
    for t=2:T
       x(k,t)=x(k,t-1)-0.1;
    if x(k,t)<=0
       u2=rand;
       if u2 < p
          x(k,t)= - a;
       else
          x(k,t)= - b;
       end
    end
      end
end
  1 Kommentar
JohnGalt
JohnGalt am 1 Okt. 2018
take a look into the 'break' command ... very useful in conjunction with 'while' loops. e.g.
while true
% count down
if lifetime==0
% do something then...
break % exit the while loop
end
end
while true
% count up
if lifetime==0
% do something then...
break % exit the while loop
end
end

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Resource Allocation Modeling finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by