Write a function with heath [beta J = my LinRegression (f, x, y), where f is a c
ID: 645608 • Letter: W
Question
Write a function with heath [beta J = my LinRegression (f, x, y), where f is a cell array containing function handles to basis functions, and x and y are column vectors Con taming noisy data. Assume that x and y are the same length, and that the functions contained in f are vectorised. Let an estimation function for the data contained in x and y he defined as y(x)= B(1). F1(x)+B(2).f2(x)+?+B(n).fn(x), where n is the length of f. Your function should compute beta according to the least squares regression formula. Test Case: Note that your solution may vary by a little hit depending on the random numbers generated.Explanation / Answer
#include #include #include int main(int argc, char **argv) { double *x, *y; double SUMx, SUMy, SUMxy, SUMxx, SUMres, res, slope, y_intercept, y_estimate ; int i,n; FILE *infile; infile = fopen("xydata", "r"); if (infile == NULL) printf("error opening file "); fscanf (infile, "%d", &n); x = (double *) malloc (n*sizeof(double)); y = (double *) malloc (n*sizeof(double)); SUMx = 0; SUMy = 0; SUMxy = 0; SUMxx = 0; for (i=0; i
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.