Code:
/*Monte Carlo Simulation with gaussian random number generator*/
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <gsl/gsl_rng.h>
int main(int argc, char *argv[])
{
int N,i;
double Xo, mean, sigma, variance, *a;
{
if(argc != 4)
{
printf("Error!\nUsage:N(int) Xo(double) sigma(double)\n");
return 0;
}
else
N = atoi( argv[1] );
}
Xo = atof( argv[2] );
sigma = atof( argv[3] );
const gsl_rng_type * T;
gsl_rng * r;
gsl_rng_env_setup();
T = gsl_rng_default;
r = gsl_rng_alloc (T);
a = (double *) malloc (N * sizeof *a);
printf ("%d %lf %lf\n", N, Xo, sigma);
for (i = 0; i < N; i++)
{
double u = gsl_ran_gaussian(r,sigma);
a[i]=u;
printf ("%u\n", a[i]);
}
int total = 0, X;
int add_array(double a[i],int N);
{
int i;
for(i = 0; i < N; i++)
total += a[i];
X += a[i] * a[i];
}
mean = total/N;
variance = X/N;
printf ("\nTotal:%d\nMean:%lf\nVariance:%lf\n", total, mean,variance);
free(a);
gsl_rng_free (r);
return 0;
}
MCgsl.c:41: warning: implicit declaration of function `gsl_ran_gaussian'
MCgsl.c:43: warning: unsigned int format, double arg (arg 2)
MCgsl.c:46: warning: `X' might be used uninitialized in this function
I already fixed some of the other warnings I got, but I don't understand what the remaining warnings want me to fix, I suspect warning on line 43 has something to do with %u...