有人能帮我吗,因为我在这段代码上遇到错误,我不知道哪里出错了。我收到以下信息:错误 C2059:语法错误:'return',错误 C2334:'{'之前的意外令牌;跳过明显的函数体,错误 C2039: 'rtn' : is not a member of 'corr_coefficient' 请参阅 'corr_coefficient' 的声明 谢谢。
using namespace std;
class corr_coefficient
{
matrix x, y;
double sum, C, corr[5];
int j;
public:
double calc_mu(matrix x, int j=0);
double calc_covariance(matrix x, matrix y, int j);
double calc_correlation();
double StandardDeviation(matrix a, int j=0);
double return(int i){return corr[i];
};
corr_coefficient(matrix x, matrix y);
};
double corr_coefficient::calc_mu(matrix x, int j)
{
sum=0;
for(int i=0; i<C; i++)
{
sum = sum+x(i,j);
}
return sum/C;
}
double corr_coefficient::calc_covariance(matrix x, matrix y, int j)
{
double mux=calc_mu(x,0);
double muy=calc_mu(y,j);
sum=0;
for (int i=0; i<C; i++)
{
sum=sum+(x(i,0)-mux)*(y(i,j)-muy);
}
return sum/(C-1);
}
double corr_coefficient::StandardDeviation(matrix a, int j)
{
double mua=calc_mu(a,j);
sum=0;
for (int i=0; i<C; i++)
{
sum=sum+((a(i,j))-mua)*((a(i,j))-mua);
}
return sqrt(sum/(C-1));
}
corr_coefficient::corr_coefficient(matrix x, matrix y)
{
C=35;
for (int j=0; j<5; j++)
{
corr[j]=calc_covariance(x, y, j)/(StandardDeviation(x, 0)*StandardDeviation(y, j));
}
}