{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

recitation 7

recitation 7 -...

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

Sheet1 Page 1 //R7_ //Nov 1st, 2006 #include <stdio.h> #define R 1000 #define C 2 int main (void) { int i=0, j=0, count=0 FILE *input_file double x[R][C], sumx=0, sumy=0, sumxx=0, sumxy=0, m, b, Y_fit input_file = fopen("data_2D.txt", "r") while (fscan(input_file, "%lf", &x[i][j]) == 1) { j++ if (j%C==0) { i++ j=0 } } count=i for(i=0 i<count i++) { sumx+=x[i][0] sumy+=x[i][1] sumxy+=x[i][0]*x[i][1] sumxx+=x[i][0]*x[i][0] } m=((sumx*sumy-count*sumxy)/(sumx*sumx-count*sumxx)) b=((sumx*sumxy-sumxx*sumy)/(sumx*sumx-count*sumxx)) //printf("\n\n slope: m = %.2f\n", m) //printf( "y-intercept: b = %.2f\n\n", b) printf("m=[(%5.1f)*(%5.1f)-(%i)*(%5.1f)]/[(%5.1f)*(%5.1f)-(%i)*(%5.1f)]= %.2f\n, sumx, sumy, count, sumxy, sumx, sumx, count, sumxx, m)

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: printf("b=[(%5.1f)*(%5.1f)-(%5.1f)*(%5.1f)/(%5.1f)*(%5.1f)-(%i)*(%5.1f)]= %.2f\n\n", sumx, sumxy, sumxx, sumy, sumx, sumx, count, sumxx, b) printf("LINEAR REGRESSION RESULT: Y_fit = %.2f X + %4.2f\n\n\n", m, b) printf(" x y x*x x*x Y_fit y - Y_fit\n\n") for(i=0 i<count i++) { printf(" %6.1f %6.1f %6.1f %6.1f %6.1f %6.1f", x[i][0], x[i][1], x[i][0]*x[i][1], x[i][0]*x[i][0], m*x[i][0]+b, x[i][1]-(m*x[i][0]+b)) if (j%C==0) { printf("\n") } } printf("------- ------- ------- -------\n") printf(" %5.1f %5.1f %5.1f %5.1f\n", sumx, sumy, sumxy, sumxx) printf(" sumx sumy sumxy sumxx") fclose(input_file) Sheet1 Page 2 printf("\n\n") return 0 }...
View Full Document

{[ snackBarMessage ]}

Page1 / 2

recitation 7 -...

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

View Full Document
Ask a homework question - tutors are online