We are doing linear regression for a project in class. I have to write a function. I've tried static casting and other ways of changing this "int n" to a double so it doesn't throw an error? Or am I completely on the wrong train of thought?
Function
void linear_regression(double x[], double y[], int n,
double *slope, double *y_int)
{
double sum_x, sum_y, sum_x_Squared, sum_Squared_x, product_x_y;
double m = *slope, b = *y_int;
sum_x = sum_array(x, n);
sum_y = sum_array(y, n);
sum_Squared_x = sum_square_array(x, n);
sum_x_Squared = sum_array(x, n) * sum_array(x, n);
product_x_y = sum_product_of_arrays(x, y, n);
//I'm getting an error on the next statement, about the n
m = ((sum_x * sum_y) - (n * sum_product_of_arrays)) /
((sum_x_Squared) - (n * sum_Squared_x));
b = ((sum_y - (m * sum_x))/(n));
return;
}
Error message
Invalid operands of types 'int' and 'double(double*, double*, int)' to
binary operator.
In
n * sum_product_of_arrays
,sum_product_of_arrays
is a function you called to getproduct_x_y
. Did you mean to useproduct_x_y
?