3 dimensional array with all possible combinations of the 3 numbers

I have been working on this for a long time. As soon as I think I have all the possible combinations, I think of a few more. There has to be an easier way to this. I am calculating oblique room modes and need any combination of the 3 numbers (representing each dimension of the room) to be fed into an equation. So, I would need 1,2,2; 1,1,2; 1,1,3; 1,2,3; 3,2,1; the list goes on. So far, I have a 3 dimensional array with loops running and have all of the combinations for if all elements increase (aka 1,1,1; 2,2,2) one of the elements increases while 2 remain constant (aka 2,1,1; 3,1,1; 4,1,1; 3,2,2; 4,2,2) and if 2 elements increase while 1 remains constant (aka 1,2,2; 1,3,3; 2,3,3). My problem is that I don't have any which contain combinations of each number being different (like 1,2,3; 1,3,5; 2,4,1; etc.) and for me to do a loop for each of these seems ridiculous. Another tricky part is that I need the loops to stop calculating once a number (frequency "m") is obtained. The variable "m" will be calculated with another formula later. It is just simplified for now. Is there an easier way to do this or do I need a whole bunch more loops?

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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//Modes below the Schroeder Frequency
#include <iostream>
#include <math.h>
#include<string>
using namespace std;

// global variables
double l,w,h,temp,c,m,volume,surfaceArea; int a,i,j,k;
//declaring global arrays

const int NUM=20; // maximum number of modes calculated
double mode[NUM][NUM][NUM];

double obliqueModes(double l, double w, double h, double c, double m)
{
//1 dimension changes per loop  
for (int j=1; j<NUM; j++) //makes the constants increase each outer loop
	{
	for (int i=1; i<NUM; i++) //width and height are constant, length increases by 1 each loop: this loop also includes modes where all 3 counters are the same
	{	
		mode[i][j][j]=c/2*sqrt(pow((i/l),2)+pow((j/w),2)+pow((j/h),2));  //not having the if statement before this allows 1 1 1, 2 2 2 to be calculated
		cout<<"oblique width height mode with length changing= "<<i<<" "<<j<<" "<<j<<" , "<<mode[i][j][j]<<" Hz"<<endl;
		
		if (mode[i][j][j]>m)
		break;
	}
	}
	
for (int j=1; j<NUM; j++) //makes the constants increase each outer loop
	{
	for (int i=1; i<NUM; i++) //length and height are constant, width increases by 1 each loop
	{
		if (i>j || i<j) //stops unnecessary calculation of 1,1,1; 2,2,2; etc.
		{
		mode[j][i][j]=c/2*sqrt(pow((j/l),2)+pow((i/w),2)+pow((j/h),2));
		cout<<"oblique length height mode with width changing= "<<j<<" "<<i<<" "<<j<<" , "<<mode[j][i][j]<<" Hz"<<endl;
		}
		
		if (mode[j][i][j]>m)
		break;
	}
	}
	
for (int j=1; j<NUM; j++) //makes the constants increase each outer loop
	{
	for (int i=1; i<NUM; i++) //length and width are constant, height increases by 1 each loop
	{	
		if (i>j || i<j) 
		{
		mode[j][j][i]=c/2*sqrt(pow((j/l),2)+pow((j/w),2)+pow((i/h),2));
		cout<<"oblique length width mode with height changing= "<<j<<" "<<j<<" "<<i<<" , "<<mode[j][j][i]<<" Hz"<<endl;
		}
		
		if (mode[j][j][i]>m)
		break;
	}
	}

//2 dimensions change per loop
for (int j=1; j<NUM; j++) //makes the constants increase each outer loop
	{
	for (int i=1; i<NUM; i++) //length is constant, width and height increases by 1 each loop
	{	
		if (i>j || i<j)
		{
		mode[j][i][i]=c/2*sqrt(pow((j/l),2)+pow((i/w),2)+pow((i/h),2));
		cout<<"oblique length mode with width and height changing= "<<j<<" "<<i<<" "<<i<<" , "<<mode[j][i][i]<<" Hz"<<endl;
		}
		
		if (mode[j][i][i]>m)
		break;
	}
	}

for (int j=1; j<NUM; j++) //makes the constants increase each outer loop
	{
	for (int i=1; i<NUM; i++) //width is constant, length and height increases by 1 each loop
	{	
		if (i>j || i<j) 
		{
		mode[i][j][i]=c/2*sqrt(pow((i/l),2)+pow((j/w),2)+pow((i/h),2));
		cout<<"oblique width mode with length and height changing= "<<i<<" "<<j<<" "<<i<<" , "<<mode[i][j][i]<<" Hz"<<endl;
		}
		
		if (mode[i][j][i]>m)
		break;
	}
	}
	
for (int j=1; j<NUM; j++) //makes the constants increase each outer loop
	{	
	for (int i=1; i<NUM; i++) //height is constant, length and width increases by 1 each loop
	{	
		if (i>j || i<j)
		{
		mode[i][i][j]=c/2*sqrt(pow((i/l),2)+pow((i/w),2)+pow((j/h),2));
		cout<<"oblique height mode with length and width changing= "<<i<<" "<<i<<" "<<j<<" , "<<mode[i][i][j]<<" Hz"<<endl;
		}
		
		if (mode[i][i][j]>m)
		break;
	}
	}
}
int main ()
{
	cout<<"Use this program for a rectangular room to calculate:"<<endl;
	cout<<"Modal frequencies below the Shroeder Frequency"<<endl;
	
	cout<<"What is the height of the room?"<<endl;cin>>h;cout<<endl;
	cout<<"What is the width of the room?"<<endl;cin>>w;cout<<endl;
	cout<<"What is the length of the room?"<<endl;cin>>l;cout<<endl;

//	cout<<"What is the temperature of the room in degrees Celsius?"<<endl;cin>>temp;cout<<endl;

	cout<<"width= "<<w<<"  length= "<<l<<"   height="<<h<<endl;
//	cout<<"temperature= "<<temp;
	
	//insert "is this correct?" and repeat input option here!!!
	c=345;

//	c=20.047*pow(273.15+temp,0.5);

	volume=w*l*h;
	surfaceArea=2*((l*w)+(w*h)+(h*l));
	cout<<"The speed of sound is "<<c<<" meters/second"<<endl;
	cout<<"The volume of the room is "<<volume<<" cubic meters."<<endl;
	cout<<"The surface area of the room is "<<surfaceArea<<" square meters. "<<endl;
	
	m=300; //determines the frequency at which the modes stop being calculated.  Will be set to a formula for the schroeder frequency later.

	obliqueModes(l,w,h,c,m);
	
	return 0;
}
Topic archived. No new replies allowed.