Reliability Issue
Apr 9, 2013 at 4:42am UTC
I am trying to write a program that simulates the configuration shown below, using a component reliability of 0.8 for components 1 and 2, and 0.95 for components 3 and 4. I want to print the estimate of the reliability, using 5,000 simulations. (The analytical reliability of
this system is 0.9649.) This is what I have so far however I'm getting a reliability value of 1 so I think I have gone wrong somewhere. Thanks for any help! :)
Configuration c= component
C1-----C2
a----| |---b
C3-----C4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#include <cstdlib>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include<cmath>
using namespace std;
double rand_double(double a, double b) {
return ((double )rand()/RAND_MAX)*(b-a) + a;
}
int main()
{
double c1,c2,c3, c4;
int success = 0;
int total = 5000;
for (int i = 0; i < total; i++)
{
c1 = rand_double(0,1);
c2 = rand_double(0,1);
c3 = rand_double(0,1);
c4 = rand_double (0,1);
if ( c1 < 0.8 || c2 < 0.8 || c3 < 0.95 || c4 < 0.95)
{
success++;
}
}
cout << "By simulation, reliability is " << (double )success/total << endl;
system("PAUSE" );
return 0;
}
Last edited on Apr 9, 2013 at 4:54am UTC
Apr 9, 2013 at 4:51am UTC
Try seeding the random number generator with srand(time(NULL)) once at the start of your program.
Apr 9, 2013 at 5:20am UTC
Thanks for the tip! I tried doing that but the program is not compiling! :( Ive never used the srand(time(NULL)) command so I may be missing something.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
#include <cstdlib>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include<cmath>
using namespace std;
double rand_double(double a, double b) {
return ((double )rand()/RAND_MAX)*(b-a) + a;
}
int main()
{
srand(time(NULL))
double c1,c2,c3, c4;
int success = 0;
int total = 5000;
for (int i = 0; i < total; i++)
{
c1 = rand_double(0,1);
c2 = rand_double(0,1);
c3 = rand_double(0,1);
c4 = rand_double (0,1);
if ( c1 < 0.8 || c2 < 0.8 || c3 < 0.95 || c4 < 0.95)
{
success++;
}
}
cout << "By simulation, reliability is " << (double )success/total << endl;
system("PAUSE" );
return 0;
}
Apr 9, 2013 at 5:34am UTC
When there are errors, you should provide them so we can figure out the problem.
Apr 9, 2013 at 6:18am UTC
Sorry! It says " 17:16: error :'time' was not declared in this scope"
Topic archived. No new replies allowed.