I’m running this code to calculate square root of x[i][j] - y[j] but it gives me nonsense!
bool X[I][J]={}; //nodes
bool Y[J]={}; //medians
double denominator=0;
double miu=0;
outFile<< "denominator= " << denominator << endl;
for(i=0;i<I;i++)
for(j=0;j<J;j++)
{
denominator+=sqrt(double (X[i][j]-Y[j]));
}
outFile<< "denominator= " << denominator << endl;
The first outFile prints 0 which is the original value but the second one prints -1.#IND.
That probably means that at some point
X[i][j] - Y[j]was negative, and you’re getting a NaN (not a number) back fromsqrt.See this wikipedia page for an explanation of NaNs.
Also,
XandYare arrays of booleans, soX[i][j] - Y[j]will always be 1, 0, or -1, and you really don’t need thesqrt. Is this what you want?