D
Darius Fatakia
Hi,
I seem to be having trouble with some of my math functions (pow, sqrt,
acos). They're the only ones I use in my code and they prevent the program
from compiling. I get a "undefined reference to 'pow'" error. Here is the
relevant portion of my code.
Your help would be appreciated. Thanks!
* Genetic Algorithm module
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include "string.h"
/* GetSD
*
* This function returns the standard deviation of the feature vectors
* in a dataT * array.
*/
static double GetSD(dataT *dataArr[], int data_size, int features[], double
mean[]) {
int i, j;
double data_vect[GENES_PER_CHROM], data_sum, mean_sum, ang_sum, dotprod,
data_norm, mean_norm, angle;
double sd;
ang_sum = 0;
for(i = 0; i < data_size; i++) {
for(j = 0; j < GENES_PER_CHROM; j++) {
data_vect[j] = dataArr->val[(features[j])];
}
// get dot product of the two vectors
dotprod = 0;
for(j = 0; j < GENES_PER_CHROM; j++) {
dotprod += data_vect[j] * mean[j];
}
// get the norms
data_sum = 0;
mean_sum = 0;
for(j = 0; j < GENES_PER_CHROM; j++) {
data_sum += pow(data_vect[j], 2);
mean_sum += pow(mean[j], 2);
}
data_norm = sqrt(data_sum);
mean_norm = sqrt(mean_sum);
// compute the angle
angle = acos(dotprod/(data_norm * mean_norm));
ang_sum += pow(angle, 2);
}
sd = sqrt(ang_sum / (data_size - 1));
return sd;
}
I seem to be having trouble with some of my math functions (pow, sqrt,
acos). They're the only ones I use in my code and they prevent the program
from compiling. I get a "undefined reference to 'pow'" error. Here is the
relevant portion of my code.
Your help would be appreciated. Thanks!
* Genetic Algorithm module
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include "string.h"
/* GetSD
*
* This function returns the standard deviation of the feature vectors
* in a dataT * array.
*/
static double GetSD(dataT *dataArr[], int data_size, int features[], double
mean[]) {
int i, j;
double data_vect[GENES_PER_CHROM], data_sum, mean_sum, ang_sum, dotprod,
data_norm, mean_norm, angle;
double sd;
ang_sum = 0;
for(i = 0; i < data_size; i++) {
for(j = 0; j < GENES_PER_CHROM; j++) {
data_vect[j] = dataArr->val[(features[j])];
}
// get dot product of the two vectors
dotprod = 0;
for(j = 0; j < GENES_PER_CHROM; j++) {
dotprod += data_vect[j] * mean[j];
}
// get the norms
data_sum = 0;
mean_sum = 0;
for(j = 0; j < GENES_PER_CHROM; j++) {
data_sum += pow(data_vect[j], 2);
mean_sum += pow(mean[j], 2);
}
data_norm = sqrt(data_sum);
mean_norm = sqrt(mean_sum);
// compute the angle
angle = acos(dotprod/(data_norm * mean_norm));
ang_sum += pow(angle, 2);
}
sd = sqrt(ang_sum / (data_size - 1));
return sd;
}