Question: I am creating a code that use the gauss-seidel method. I need help fixing my errors. This is being done in C. #include #include #include

I am creating a code that use the gauss-seidel method. I need help fixing my errors. This is being done in C.

I am creating a code that use the gauss-seidel method. I needhelp fixing my errors. This is being done in C. #include #include

#include #include #include

#define DEBUG 0 #define MAX_ITER 1000

int i, j, n = 126, iter, lambda, ea; double *bv, *xsol, *xprev, *Am, dummy, sum, sentinel; //float *dummy, *sum, *sentinel;

double Gseid(Am, bv, n, xsol){

for(i=0; i

for(j=0; j

for(i=0; ies) { sentinel = 0; } } iter = iter + 1; } } }

int main() { FILE *BinInp, *TxtOut;

/* Input Code: Reads bv, Am in binary form from CGrad.bin */ if ( (BinInp = fopen("CGrad.bin","r")) == NULL ) { fprintf(stderr, "Cannot open matrix binary file INPUT... exiting "); exit(-1); }

bv = malloc (n*sizeof(double)); if (!fread(bv, sizeof(double), n, BinInp)) { fprintf(stderr, "Cannot read bv vector... exiting "); exit(1); } else { if (DEBUG) { for (i = 0; i

Am = malloc (n*sizeof(double*)); Am[0] = malloc (n*n*sizeof(double)); for (i = 1; i

if (fclose(BinInp) == EOF) { fprintf(stderr, "Cannot close matrix binary file INPUT... exiting "); exit(-1); }

xsol = malloc (n*sizeof(double)); xprev = malloc (n*sizeof(double)); for (i = 0; i

// PERFORM ITERATIVE SOLUTION OF MATRIX SYSTEM HERE USING JACOBI OR GAUSS-SEIDEL METHODS. // RETURN SOLUTION VECTOR IN xsol; THE CODE BELOW WILL WRITE IT TO A BINARY FILE. // IF NEEDED, USE xprev VECTOR TO STORE PREVIOUS SOLUTION. FEEL FREE TO DEFINE OTHER VARIABLES // AS REQUIRED FOR ITERATIVE SOULTION TO MATRIX SYSTEM.

xsol = Gseid ( Am, bv, n, xsol)

/* Output Code: Writes xsol in text form to Xsol.txt */

if( (TxtOut = fopen("Xsol.txt", "w")) == NULL ) { fprintf(stderr, "Cannot open matrix text file OUTPUT... exiting "); exit(-1); } for (i = 0; i

if (fclose(TxtOut) == EOF) { fprintf(stderr, "Cannot close matrix text file INPUT... exiting "); exit(-1); }

return (0); }

int i, j, n 126 iter lambda ea. double bv *x xpre *Arm, dummy sum, sentinel xsol float *dummy, *sum, Sentinel double Geseid (Arm bv, n, xsol) for (i o; i<.>

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!