It's a lot...

Main Function

Code:

#include<stdio.h>
#include<stdlib.h>
#include"corrheader.h"
struct
{
int PAS_type, cluster_number;
double *d_norm, *delta_phi_deg, *amplitude_cluster, *phi_deg, *AS_deg, *Q, *sigma_deg, **R;
} Node_B, UE;
int main()
{
int i,j, dlink=-1, Field=-1, M, N;
/*---------------------------------------------------------------------------------*/
*Node_B.R=malloc(M*sizeof(double*));
for(i=0;i<M;i++)
Node_B.R[i]=malloc(M*sizeof(double));
*UE.R=malloc(N*sizeof(double*));
for(i=0;i<N;i++)
UE.R[i]=malloc(N*sizeof(double));
/*****************THESE VALUES ARE ALL OBTAINED FROM ANOTHER FUNCTION, BUT POSTING ALL THAT WOULD BE EXCESSIVE**********/
/*SECOND FUNCTION USED 1ST TIME, NO PROBLEMS OCCUR*/
correlation(M, Node_B.PAS_type, Node_B.cluster_number, Field, Node_B.d_norm, Node_B.delta_phi_deg, Node_B.amplitude_cluster, Node_B.phi_deg, Node_B.AS_deg,
Node_B.Q, Node_B.sigma_deg, Node_B.R);
/*FUNCTION USED SECOND TIME CREATES A PROBLEM*/
correlation(N, UE.PAS_type, UE.cluster_number, Field, UE.d_norm, UE.delta_phi_deg, UE.amplitude_cluster, UE.phi_deg, UE.AS_deg, UE.Q, UE.sigma_deg, UE.R);
printf("\n\nUE.R\n");
for(i=0;i<N;i++)
{for(j=0;j<N;j++)
{
printf("%.4lf\t", UE.R[i][j]);
}printf("\n");
}
return 0;
}

Correlation (Second Function):

Code:

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define Pi 3.14159265
double correlation(int M, int PAS_type, int cluster_number, int Field, double *d_norm, double *delta_phi_deg, double *amplitude_cluster, double *phi_deg,
double *AS_deg, double *Q, double *sigma_deg, double **R)
{
/* Normalization*/
int i, j, k;
double *Rxx=malloc(M*sizeof(double));
double *Rxy=malloc(M*sizeof(double));
double *tmp=malloc(M*sizeof(double));
if( Rxx==NULL || Rxx==NULL || B==NULL)
printf("Mem. All. failed!");
if (M>1)
{
for(i=0;i<M;i++)
{
Rxx[i] = bessel(B[i]);
Rxy[i] = 0;
}
printf("\ntmp:\n");
for(i=0;i<M;i++)
{
tmp[i] = (Rxx[i]*Rxx[i])+(Rxy[i]*Rxy[i]);
printf("%.4lf\t", tmp[i]);
}
/*I BELIEVE THE PROBLEM OCCURS IN THE FOLLOWING FUNCTION*/
**R=toeplz_vec(M, tmp, R);
}
free(tmp_real); free(Rxx); free(Rxy);
return 0;
}

toeplz_vec (Third Function):

Code:

#include<stdio.h>
double toeplz_vec(int size, double *tmp, double **R)
{
int i, j, k;
/*******FROM WHAT I CAN TELL BY TESTING USING PRINTF, THE ERROR OCCURS SOMEWHERE WITHIN THIS LOOP******/
for(k=0;k<size;k++)
{
for(i=0;i<size;i++)
{
for(j=0;j<size;j++)
{
if(i==j)
R[i][j]=tmp[0];
else if(i==(j-k)||i==(j+k))
R[i][j]=tmp[k];
}
}
}
return **R;
}

Sorry for so much code.