I am working on a program that uses Jacobi iteration (http://en.wikipedia.org/wiki/Jacobi_iteration). But I'm getting a seg fault. The code looks correct to me, and I'm thoroughly frustrated at this point. Maybe someone can point out my mistake.
int main(void) {
double* coeff_Matrix;
int nx, ny;
do{
//Get values of nx and ny from user.
printf("Please enter the number of x-points and the number of y-points desired. \n");
printf("\n");
printf("How many x-points do you want? Enter zero for default (1024). \n");
scanf("%d", &nx);
printf("How many y-points do you want? Enter zero for default (1024). \n");
scanf("%d", &ny);
coeff_Matrix = NULL;
coeff_Matrix = (double**) malloc(nx*sizeof(double*)); //SEGMENTATION FAULT DUE TO THIS?
if(nx > 0) {
PDE_calculate(nx, ny, &coeff_Matrix); //This method is used to generate a diagonally dominant matrix.
jacobi_Calculate(&coeff_Matrix, nx); //This method does the Jacobi iteration.
}
else {
puts("Invalid choice or memory available was exceeded ... Try again.");
if(coeff_Matrix != NULL)
free(coeff_Matrix);
}
}while(more()); //The more() method just asks the user if they would like to do a different problem. User just says "y/n". Mainly here to allow for expanded functionality.
return 0;
} //end main
So, as you can see, the program asks for x-points and y-points. (Tolerance is already set via a #define statement.) Any ideas?