8 const float threshold = .52;
10 static float z, der0, der1,der2,der3;
13 z = 0.5* (threshold + 0.707);
17 der2 = (sqrt(M) * z) / (M*M);
18 der3 = (sqrt(M) / ( M *
M ) + (3 * (z*z) * sqrt(M) ) / (M * M * M) ) ;
20 printf(
"%f %f %f %f \n", der0, der1, der2, der3);
23 return der0 + m * ( der1 + m * ( (der2/2) + m * (der3/6) ) );
30 float der7 = 15.0f/ (48*7);
31 return x * ( der1 + x2 *( der3 + x2 * (der5 + der7 * x2 )));
35 #define myacos(x) ( ((float) (M_PI/2) ) - myasin(x)) 37 *rho = sqrtf(x*x+y*y);
46 *theta = -
myacos(x / *rho);
48 *theta = -
myasin( (-y) / *rho) ;
82 gsl_vector * res = gsl_vector_alloc(2);
91 printf(
"Projection of %f %f is %f %f \n",
gvg(X,0),
gvg(X,1),
97 double should_be_nan[2] = { 0.0 / 0.0, GSL_NAN };
99 if(!isnan(should_be_nan[i])) {
100 printf(
"#%d: isnan(%f) failed \n", i, should_be_nan[i]);
103 if(!
is_nan(should_be_nan[i])) {
104 printf(
"#%d: is_nan(%f) failed \n", i, should_be_nan[i]);
109 double max_error = 0;
112 double theta = (i * 2 *
M_PI) / (num-1);
113 double x = cos(theta), y = sin(theta);
115 double theta_est, rho;
116 polar(x,y,&rho,&theta_est);
117 double error = fabs(
angleDiff(theta_est,theta) );
118 if(error > max_error)
119 printf(
"%d x %f y %f theta %f theta_est %f error %f \n", i, x, y, theta, theta_est, error);
120 max_error = GSL_MAX(error, max_error);
123 int NUM2 = 1000;
int k;
124 float c[num], s[num];
126 double theta = (i * 2 *
M_PI) / (num-1);
127 c[i]= cos(theta); s[i] = sin(theta);
130 clock_t start1 = clock();
134 polar(c[i],s[i],&rhof, &thetaf);
136 clock_t end1 = clock();
138 clock_t start2 = clock();
142 polar2(c[i],s[i],&rho, &theta);
144 clock_t end2 = clock();
146 float seconds1 = (end1-start1)/((
float)CLOCKS_PER_SEC);
147 float seconds2 = (end2-start2)/((
float)CLOCKS_PER_SEC);
149 printf(
" polar: %f polar2: %f\n", seconds1, seconds2);
151 printf(
"Maximum error for polar(): %lf rad = %lf deg\n", max_error,
rad2deg(max_error));
gsl_vector * vector_from_array(unsigned int n, double *x)
double angleDiff(double a, double b)
#define M(matrix, rows, col)
void polar(float x, float y, double *restrict rho, double *restrict theta)
void polar2(double x, double y, double *restrict rho, double *restrict theta)
double rad2deg(double rad)