我们正在为课堂上的一个项目做线性回归。我必须写一个函数。我已经尝试过静态转换和其他将“int n”更改为双精度的方法,这样它就不会引发错误?还是我完全走错了思路?
功能
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;
}
错误信息
Invalid operands of types 'int' and 'double(double*, double*, int)' to
binary operator.