0 c++ binary types operands operator-keyword
我们正在为课堂上的项目进行线性回归.我必须写一个函数.我已经尝试过静态转换和其他将"int n"更改为double的方法,因此它不会抛出错误?还是我完全错误的思路?
功能
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;
}
Run Code Online (Sandbox Code Playgroud)
错误信息
Invalid operands of types 'int' and 'double(double*, double*, int)' to
binary operator.
Run Code Online (Sandbox Code Playgroud)
在n * sum_product_of_arrays,sum_product_of_arrays是一个你打电话来获得的功能product_x_y.你的意思是用product_x_y吗?