Component reliability

I am working on the same question as another member posted here, but I am going about it slightly differently as I see the equation differently.. I can get my program to compile and run, but I run into an issue after I enter in my unsigned int seed. It says that i have not declared "component reliability" even tho I clearly have. What do I seem to be missing here?

Also, under this area: " if (((num1<=component_reliability) &&
((num2<=component_reliability)) &&
(num3<=component_reliability)))", I was considering changing the component reliability to a_parallel considering that is the answer to the equation. I worked out this equation by hand, and it gives me the correct analytical reliability, I just cant seem to get the program to execute it..

Help?!?


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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include<iostream>
#include<cmath>
#include<cstdlib>

using namespace std;

double rand_float(double a, double b); double c;

int main()
{
unsigned int seed;
int n;
double component_reliability, component_reliability1, component_reliability2, component_reliability3,
       a_parallel, parallel_success(0), num1, num2, num3;

cout << "Enter the indvidual component reliability1: \n";
cin >> component_reliability1;
cout << "Enter the indvidual component reliability2: \n";
cin >> component_reliability2;
cout << "Enter the indvidual component reliability3: \n";
cin >> component_reliability3;
cout << "Enter the number of trials: \n";
cin >> n;
cout << "Enter unsigned integer seed: \n";
cin >> seed;
srand(seed);
cout << endl;

a_parallel = (component_reliability1) * (1 - ((1 - component_reliability2) * 
(1 - component_reliability3)));

for (int k=1; k<=n; k++)
{	
num1 = rand_float(0,1);
num2 = rand_float(0,1);
num3 = rand_float(0,1);
if (((num1<=component_reliability) &&
((num2<=component_reliability)) &&
(num3<=component_reliability)))
{
parallel_success++;
}
} 

cout << "Analytical Reliability \n";
cout << "Parallel: " << a_parallel << endl;
cout << "Simulation Reliability " << n << " trials \n";
cout << " Parallel: " << (double)parallel_success/n << endl;

system ("PAUSE");
return 0;
}

double rand_float(double a, double b)
{
return ((double)rand()/RAND_MAX*(b-a) + a);
}

Last edited on
@zblackbeast

Firstly, please edit your post so it uses code tags - the <> button on the right


You have declared component_reliability, but have not assigned a value to it.

The other thing to be careful about is comparing doubles the way you do. Floating point numbers (floats & doubles etc.) are stored as binary fractions and cannot represent every real number. This why they shouldn't be compared directly. Consider this:

1
2
3
4
5
float a = 0.1; // a == 0.09999997
float b = 10.0 * a; // b == 0.9999997

if(a == b) //false


Changing the type to double doesn't help.

You can make use of std::numeric_limits<double>epsilon it needs to be scaled up to the numbers you are using.

Google floating point epsilon to see how to do it correctly.

http://stackoverflow.com/questions/17333/most-effective-way-for-float-and-double-comparison


Also tread the boost stuff in that link.

Hope all goes well. :)
Last edited on
Topic archived. No new replies allowed.