//devin scott //CS 407 //Numerical analysis #6 void do_gauss(int n, double a[10][10], double x[10], double b[10]); int main() { double A[10][10]; double X[10]; double B[10]; int x = 0, y = 0, n = 0; printf("Analysis #6 Devin Scott CS 407 \n"); for (x = 0; x < 10; x++) for (y = 0; y < 10; y++) { A[x][y] = 0.0; B[x] = 0.0; } printf("please input the dimension n of your nxn matrix"); scanf("%d", &n); printf("please input a row of %d coeficients with spaces between them\n",n); for (x = 0; x < n; x++) { printf("row %d: ",x+1); for(y = 0; y < n; y++) { //printf("row %d col %d ",x,y); scanf("%lf",&A[x][y]); } printf("B %d: ",x+1); scanf("%lf",&B[x]); for(y = 0; y < n; y++) { printf("%lf ",A[x][y]); } printf(" | %lf\n",B[x]); } printf("\n\n\n\n SOLVING MATRIX:\n"); for (x = 0; x < n; x++) { for(y = 0; y < n; y++) { printf("%lf ",A[x][y]); } printf(" | %lf\n",B[x]); } do_gauss(n - 1, A, X, B); printf("\n\n\n"); printf("RESULTS\n"); for (x = 1; x smax) { smax = tempval; } } s[i] = smax; } for (k=0; k<=n-1; k++) { rmax=0; for(i=k; i<=n; i++) { //r=|ali,k/sli| r = a[l[i]][k] / s[l[i]]; if (r < 0) { r = -r; } if (r > rmax) { rmax = r; j=i; } } //lj=lk; //lk=lj; tempval = l[j]; l[j] = l[k]; l[k] = tempval; for (i=(k+1); i<=n; i++) { xmult = a[l[i]][k]/a[l[k]][k]; a[l[i]][k] = xmult; for (j=(k+1); j<=n; j++) { //ali,j = ali,j - (xmult)alk,j; a[l[i]][j] = a[l[i]][j] - xmult * a[l[k]][j]; } } } ////second part of procedure................... for (k=0; k<=(n-1); k++) { for (i=(k+1); i<=n; i++) { b[l[i]] = b[l[i]] - a[l[i]][k] * b[l[k]]; } } x[n] = b[l[n]]/a[l[n]][n]; for (i=(n-1); i >=0; i--) { sum = b[l[i]]; for (j=(i+1); j<=n; j++) { sum = sum - a[l[i]][j]*x[j]; } x[i] = sum/a[l[i]][i]; } }