recitation8

# recitation8 - for (i=0 i<=1 i++) eliminate (AB, 3, i)...

This preview shows pages 1–2. Sign up to view the full content.

Sheet1 Page 1 #include <stdio.h> #include <math.h> #define N 100 int main (void) { int i=0, j, count, r, c double AB[N][N+1], S[N*(N+1)] FILE *Matt_Senko Matt_Senko = fopen ("data.8.txt", "r") i++ count=i r=sqrt(count) c=r+1 //DATA ECHO for(i=0 i<count i++) printf("%2.0f", S[i]) printf("\n\n") p //ARRAY COPYING for (i=0 i<r i++) for (j=0 j<c j++) { AB[i][j] = S[c*i+j] if(j<4) { printf("%2.0f X%d ", AB[i][j], j+1 if(j!=c-2) printf("+") } else printf("= %2.0f ", AB[i][j]) if((j+1)%c==0) printf("\n") } double X[3] void eliminate (double [N][N+1], int, int) void back_substitute (double [N][N+1], int, double []) v for (i=0 i<3 i++) printf("%2.0f %2.0f %2.0f %2.0f\n", AB[i][0], AB[i][1], AB[i][2], AB[i][3]

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: for (i=0 i<=1 i++) eliminate (AB, 3, i) back_substitute (AB, 3, X) for (i=0 i<3 i++) printf("\nX%d = %5.2f", i+1, X[i] printf("\n\n") Sheet1 Page 2 fclose(Matt_Senko) return0 } void eliminate (double AB[N][N+1], int n, int i) { int row, col double scale_factor for (row = i+1 row<n row++) { scale_factor = -AB[row][i]/AB[i][i] AB[row][i]=0 for (col=i+1 col<=n col++) AB[row][col]+=AB[i][col]*scale_factor } return } void back_substitute (double AB[N][N+1], int n, double X[3]) { int row, col X[n-1] = AB[n-1][n]/AB[n-1][n-1] for (row=n-2 row>=0 row--) { for (col=n-1 col>=row+1 col--) AB[row][n]/AB[row][row] } return }...
View Full Document

## This homework help was uploaded on 04/07/2008 for the course ESC 121 taught by Professor Serrano during the Spring '08 term at Cleveland State.

### Page1 / 2

recitation8 - for (i=0 i<=1 i++) eliminate (AB, 3, i)...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online