Hey everyone,

Can anyone identify a problem with my functions because I'm not getting the values I expect, I think my logic is sound, I reckon it's just a problem with my lack of knowledge of functions. Once again no code please just point out where I've gone wrong cheers guys:

Code:#include <stdio.h> #include <stdlib.h> #include <math.h> float sum_xsquared_by_sigmasquared(float myarray[10000][4], int num_elements); //Create prototypes for summing values in file float sum_y_by_sigmasquared(float myarray[10000][4], int num_elements); float sum_x_by_sigmasquared(float myarray[10000][4], int num_elements); float sum_xy_by_sigmasquared(float myarray[10000][4], int num_elements); float sum_one_over_sigmasquared(float myarray[10000][4], int num_elements); int main() { int i, c=10000, v=4; //Define float x,y,sx,sy,myarray[c][v]; //Define Array for storage and co-ordinates FILE *myfile; //Define a pointer to the file input for(c=0; c<10000; c++) //Initialise Array { for(v=0; v<4; v++) { myarray[c][v]=0; } } myfile=fopen("/home/sam/Documents/C Projects/LargeDataSet","r"); //Find and open File and store data for(c=0; !feof(myfile); c++) { fscanf(myfile,"%f%f%f%f", &x,&sx,&y,&sy); //Read file and store data in array myarray[c][0]=x; myarray[c][1]=sx; myarray[c][2]=y; myarray[c][3]=sy; } float a, b, a_sigma_squared, b_sigma_squared, a_sigma, b_sigma; //Define values for output for Line a=((sum_y_by_sigmasquared(myarray, c)*sum_xsquared_by_sigmasquared(myarray, c))-(sum_x_by_sigmasquared(myarray, c)*sum_xy_by_sigmasquared(myarray, c)))/((sum_one_over_sigmasquared(myarray, c)*sum_xsquared_by_sigmasquared(myarray, c))-pow(sum_x_by_sigmasquared(myarray, c),2)); b=((sum_one_over_sigmasquared(myarray, c)*sum_xy_by_sigmasquared(myarray, c))-(sum_x_by_sigmasquared(myarray, c)*sum_y_by_sigmasquared(myarray, c)))/((sum_one_over_sigmasquared(myarray, c)*sum_xsquared_by_sigmasquared(myarray, c))-pow(sum_x_by_sigmasquared(myarray, c),2)); a_sigma_squared=sum_xsquared_by_sigmasquared(myarray, c)/((sum_one_over_sigmasquared(myarray, c)*sum_xsquared_by_sigmasquared(myarray, c))-pow(sum_x_by_sigmasquared(myarray, c),2)); b_sigma_squared=sum_one_over_sigmasquared(myarray, c)/((sum_one_over_sigmasquared(myarray, c)*sum_xsquared_by_sigmasquared(myarray, c))-pow(sum_x_by_sigmasquared(myarray, c),2)); a_sigma=sqrt(a_sigma_squared); b_sigma=sqrt(b_sigma_squared); printf("The value of sum_xsquard/sigmasquared is: %f\n", sum_xsquared_by_sigmasquared(myarray, c)); printf("The value of sum_y/sigmasquared is: %f\n", sum_y_by_sigmasquared(myarray, c)); printf("The value of sum_x/sigmasquared is: %f\n", sum_x_by_sigmasquared(myarray, c)); printf("The value of sum_xy/sigmasquared is: %f\n", sum_xy_by_sigmasquared(myarray, c)); printf("The value of sum_one/sigmasquared is: %f\n\n", sum_one_over_sigmasquared(myarray, c)); printf("Y= Ax + B\n\n"); printf("Here follows the values for your Linear Least Squares variables:\n\n"); //Print Values printf("The A Value is: %f\n", a); printf("The error in A is: %f\n", a_sigma); printf("The B Value is: %f\n", b); printf("The error in B is: %f\n", b_sigma); fclose(myfile); return 0; } float sum_xsquared_by_sigmasquared(float myarray[10000][4], int num_elements) //Functions for summing values required for a and b calculation { int i, sum=0; for (i=0; i<num_elements; i++) { sum = sum + pow(myarray[i][0],2)/pow(myarray[i][3],2); } return(sum); } float sum_y_by_sigmasquared(float myarray[10000][4], int num_elements) { int i, sum=0; for (i=0; i<num_elements; i++) { sum = sum + myarray[i][2]/pow(myarray[i][3],2); } return(sum); } float sum_x_by_sigmasquared(float myarray[10000][4], int num_elements) { int i, sum=0; for (i=0; i<num_elements; i++) { sum = sum + myarray[i][0]/pow(myarray[i][3],2); } return(sum); } float sum_xy_by_sigmasquared(float myarray[10000][4], int num_elements) { int i, sum=0; for (i=0; i<num_elements; i++) { sum = sum + (myarray[i][0]*myarray[i][2])/pow(myarray[i][3],2); } return(sum); } float sum_one_over_sigmasquared(float myarray[10000][4], int num_elements) { int i, sum=0; for (i=0; i<num_elements; i++) { sum = sum + 1/pow(myarray[i][3 ],2); } return(sum); }