D
dphizler
This is the basic concept of my code:
#include <iostream.h>
#include <math.h>
#include <stdlib.h>
int main() {
double Gtotal, L, size, distance, theRandom;
double Gi[ 50 ][ 50 ][ 50 ];
int xi, xf, yi, yf, zi, zf;
Gtotal = 0; size = 50; L = 2;
// here every slot in the matrix has the same
coordinates, to keep things simple
// this code wasn't used to test this particular
situation
xi=2; xf=1; yi=2; yf=1; zi=2; zf=1;
for(int x = 0; x < size; x++) {
for(int y = 0; y < size; y++) {
for(int z = 0; z < size; z++) {
theRandom = (1 + rand()% 6 );
if(theRandom <= 2) Gi[ x ][ y ][ z ] = 0;
else Gi[ x ][ y ][ z ] = x - y + z;
}}}
for(int l = 0; l < size; l++) {
for(int m = 0; m < size; m++) {
for(int n = 0; n < size; n++) {
for(int i = 0; i < size; i++) {
for(int j = 0; j < size; j++) {
for(int k = 0; k < size; k++) {
if(Gi[ i ][ j ][ k ] != 0 || (i != l && j != m && k != n)) {
distance = sqrt((xi - xf)^2 + (yi - yf)^2 + (zi - zf)^2);
Gtotal = Gtotal + (((1/distance) * exp(-distance/L)) * Gi[ i ][ j ][
k ]);
}
}}}
// normally I would have another array
here instead of the same one
// I just wanted to keep things simple
Gi[ l ][ m ][ n ] = Gi[ l ][ m ][ n ] + Gtotal;
cout << Gi[ l ][ m ][ n ] << endl;
}}}
return 0;
}
Basic idea, I have a 3d array 50x50x50 that has some data in it.
I'm trying to make a new 3d array based on the first one where each
slot in the new array is generated from all 50x50x50 slots from the
first 3d array.
Now I know that
(1/distance) * exp(-distance/L)
will be redundant because the distance between two points in the array
will be redundant.
Try to imagine the 3d arrays being data in a cartesian graph where each
slot has cartesian coordinates.
Hopefully this is clear as to what I'm trying to do. I want to improve
the the runtime.
#include <iostream.h>
#include <math.h>
#include <stdlib.h>
int main() {
double Gtotal, L, size, distance, theRandom;
double Gi[ 50 ][ 50 ][ 50 ];
int xi, xf, yi, yf, zi, zf;
Gtotal = 0; size = 50; L = 2;
// here every slot in the matrix has the same
coordinates, to keep things simple
// this code wasn't used to test this particular
situation
xi=2; xf=1; yi=2; yf=1; zi=2; zf=1;
for(int x = 0; x < size; x++) {
for(int y = 0; y < size; y++) {
for(int z = 0; z < size; z++) {
theRandom = (1 + rand()% 6 );
if(theRandom <= 2) Gi[ x ][ y ][ z ] = 0;
else Gi[ x ][ y ][ z ] = x - y + z;
}}}
for(int l = 0; l < size; l++) {
for(int m = 0; m < size; m++) {
for(int n = 0; n < size; n++) {
for(int i = 0; i < size; i++) {
for(int j = 0; j < size; j++) {
for(int k = 0; k < size; k++) {
if(Gi[ i ][ j ][ k ] != 0 || (i != l && j != m && k != n)) {
distance = sqrt((xi - xf)^2 + (yi - yf)^2 + (zi - zf)^2);
Gtotal = Gtotal + (((1/distance) * exp(-distance/L)) * Gi[ i ][ j ][
k ]);
}
}}}
// normally I would have another array
here instead of the same one
// I just wanted to keep things simple
Gi[ l ][ m ][ n ] = Gi[ l ][ m ][ n ] + Gtotal;
cout << Gi[ l ][ m ][ n ] << endl;
}}}
return 0;
}
Basic idea, I have a 3d array 50x50x50 that has some data in it.
I'm trying to make a new 3d array based on the first one where each
slot in the new array is generated from all 50x50x50 slots from the
first 3d array.
Now I know that
(1/distance) * exp(-distance/L)
will be redundant because the distance between two points in the array
will be redundant.
Try to imagine the 3d arrays being data in a cartesian graph where each
slot has cartesian coordinates.
Hopefully this is clear as to what I'm trying to do. I want to improve
the the runtime.