int DecideWhichCluster(F_VECTOR *fvect, VECTOR_OF_F_VECTORS *clusterMeans, VECTOR_OF_F_VECTORS *clusterVars, int numClusters, int varianceNormalize) { int i; float tempDesc; int index; float Discriminant; Discriminant = ComputeDiscriminant(clusterMeans[0], clusterVars[0], fvect, varianceNormalize); index = 0; for (i = 1; i < numClusters; i++) { tempDesc = ComputeDiscriminant(clusterMeans[i], clusterVars[i], fvect, varianceNormalize); if (tempDesc < Discriminant) { index = i; Discriminant = tempDesc; } } return(index); }
QuadraticEquationSolution ComputeRoots(const double & a, const double & b, const double & c) { if (a == 0) { return NotAQuadraticEquation(); } const double discriminant = ComputeDiscriminant(a, b, c); if (discriminant < 0) { return NoRealRoots(); } if (discriminant == 0) { return -b / 2 * a; // one root } return std::make_pair((-b + sqrt(discriminant)) / (2 * a), (-b - sqrt(discriminant)) / (2 * a)); // Two roots }