Reputation: 11
would someone be able help me please, as I'm getting errors on this code and I don't know where it is going wrong. I am getting the following: errors C2059: syntax error : 'return', error C2334: unexpected token(s) preceding '{'; skipping apparent function body, error C2039: 'rtn' : is not a member of 'corr_coefficient' see declaration of 'corr_coefficient' Thank you.
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));
}
}
Upvotes: 0
Views: 1449
Reputation: 110658
double return(int i){return corr[i];
};
return
is a keyword. You can't have a function named return
. Just call it something different. Perhaps operator[]
is an appropriate operator to overload here?
double operator[](int i){ return corr[i]; }
Upvotes: 3