recitation 7 -...

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

View Full Document Right Arrow Icon
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") { 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)
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: printf(&quot;b=[(%5.1f)*(%5.1f)-(%5.1f)*(%5.1f)/(%5.1f)*(%5.1f)-(%i)*(%5.1f)]= %.2f\n\n&quot;, sumx, sumxy, sumxx, sumy, sumx, sumx, count, sumxx, b) printf(&quot;LINEAR REGRESSION RESULT: Y_fit = %.2f X + %4.2f\n\n\n&quot;, m, b) printf(&quot; x y x*x x*x Y_fit y - Y_fit\n\n&quot;) for(i=0 i&lt;count i++) { printf(&quot; %6.1f %6.1f %6.1f %6.1f %6.1f %6.1f&quot;, 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(&quot;\n&quot;) } } printf(&quot;------- ------- ------- -------\n&quot;) printf(&quot; %5.1f %5.1f %5.1f %5.1f\n&quot;, sumx, sumy, sumxy, sumxx) printf(&quot; sumx sumy sumxy sumxx&quot;) fclose(input_file) Sheet1 Page 2 printf(&quot;\n\n&quot;) return 0 }...
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

recitation 7 -...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online