Hi everybody,
I am trying to write my first program. Unfortunately, it won't work for large input values. Realistic values for my application would be n = 250, p = 10 and t = 15.
I'd like to know, if my program is not properly working or if it might also be a hardware problem. I am working with Windows XP Professional x64, in case that is important.
I tried to explain what I did in the program. If somebody might care to run it, it might be easier to run it completely (including uncommented parts).
Briefly, the idea is as follows
for different w from 1 to t
- I create a nxn array
- set all elements to zero
- set one random element = 1 (coordinates are two random numbers)
- set all sorrounding elements in an area p = 1 (square with center p and edge length 2p+1)
- then I check if the last array created, that is t, has mutual 1 entries with array t-1, t-2 and so on. I do this by multiplying the array entries: a mutual 1 is found when the product is 1).
- Now I multiply dann an exponential term, whose value depends on the number of the array that I compare to array t.
-in the end I sum up ALL entries (all entries from all arrays)
This might be a little difficult to understand, but maybe someone wouldn't mind to take a look at my code. I hope I didn't explain it to badly, but I am really tired as I am working on that problem for quite some time - I even posted my code in german first. :-)
Thanks, Laura
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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <conio.h>
#include <gsl/gsl_rng.h>
#include <windows.h>
#include <time.h>
unsigned const int n;
const int p;
unsigned const int t;
unsigned const int A;
//unsigned const int t0;
//unsigned const int y;
int main(void)
{
/********************************************************************************************************/
input:
n : size of array (n x n)
p : size of area with a one, square with center p and edge length 2p+1
t : number of arrays */
/********************************************************************************************************/
printf("n = : ");
scanf("%d", &n);
printf("p = : ");
scanf("%d", &p);
printf("t = : ");
scanf("%d", &t);
int w;
int m;
int q;
int Surface[t][n][n];
/********************************************************************************************************/
/* random Numbers */
/********************************************************************************************************/
//srand(573);
srand(time(0));
for (w=0; w<t; w++){
int hitX = rand() % n + 0;
int hitY = rand() % n + 0;
/***************************************************************************************/
/*********** Sets all array elements zero **********/
/***************************************************************************************/
for (m=0; m<n; m++)
{
for (q=0; q<n; q++)
{
Surface[w][m][q]=0;
}
}
/***************************************************************************************/
/* Sets one array element Surface[hitX][hitY] = 1 */
/***************************************************************************************/
//
Surface[w][hitX][hitY]=1;
/***************************************************************************************/
/* Print Array (test) */
/***************************************************************************************/
//for (q=0; q<n; q++)
//{
// for (m=0; m<n; m++)
// {
// printf("%-3d\t", Surface[w][m][q]);
// }
//printf("\n");
//}
//printf("\n");
/***************************************************************************************/
/* Fill area with 1s */
/***************************************************************************************/
int left = max(hitX - p, 0);
int right = min(hitX + p, n-1);
int top = max(hitY - p, 0);
int bottom = min(hitY + p, n-1);
int y;
int x;
for (y = top; y <= bottom; y++)
{
for (x = left; x <= right; x++)
{
Surface [w][x][y] = 1;
}
}
/***************************************************************************************/
/* Print array again (test) */
/***************************************************************************************/
//for (q=0; q<n; q++)
//{
// for (m=0; m<n; m++)
// {
// printf("%-3d\t", Surface [w][m][q]);
// }
// printf("\n");
// }
//printf("\n");
}
/*******************************************************************************
/********************************************************************************************************/
//printf("\n");
//printf("Einzelne Ueberlappe");
//printf("\n");
/**************************************************************************************
/***************************************************************************************/
int i;
double Surface2 [t][n][n];
double Summe = 0;
int t0 =2;
for(i=0;i<t-1;i++){
for (q=0; q<n; q++)
{
for (m=0; m<n; m++)
{
Surface2 [t-1][m][q]= (Surface [t-1][m][q] * Surface [t-(2+i)][m][q] * exp(-((i+1.0)/t0)));
}
}
//printf("\n");
/***************************************************************************************/
/* Print Arrays (test)*/
/***************************************************************************************/
for (q=0; q<n; q++)
{
for (m=0; m<n; m++)
{
printf("%-.3f\t", Surface2 [t-1][m][q]);
}
printf("\n");
}
printf("\n");
for (q=0; q<n; q++)
{
for (m=0; m<n; m++)
{
Summe = Summe + Surface2 [t-(1)][m][q];
}
}
/***************************************************************************************/
/* Sum over all array elements of single array*/
/***************************************************************************************/
//printf("\n");
//printf("%-.3f\t", Summe);
//printf("\n");
/***************************************************************************************/
/* Sum over all array elements of all arrays*/
/***************************************************************************************/
}
printf("\n");
printf("%-.3f\t", Summe);
printf("\n");
getch();
}
|