Find an Error
This commit is contained in:
parent
093280d5cd
commit
dc3c871ae1
6 changed files with 43 additions and 37 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -109,3 +109,4 @@ System Volume Information/
|
|||
|
||||
# Linux system files
|
||||
lost+found/
|
||||
.nfs*
|
||||
|
|
|
@ -1,28 +1,13 @@
|
|||
#ifndef INIT_F_H
|
||||
#define INIT_F_H
|
||||
|
||||
int get_call_function_count (void) ;
|
||||
int get_call_derivative_count (void);
|
||||
|
||||
int get_call_count (void);
|
||||
double f0 (double x);
|
||||
double d0 (double x);
|
||||
|
||||
double f1 (double x);
|
||||
double d1 (double x);
|
||||
|
||||
double f2 (double x);
|
||||
double d2 (double x);
|
||||
|
||||
double f3 (double x);
|
||||
double d3 (double x);
|
||||
|
||||
double f4 (double x);
|
||||
double d4 (double x);
|
||||
|
||||
double f5 (double x);
|
||||
double d5 (double x);
|
||||
|
||||
double f6 (double x);
|
||||
double d6 (double x);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -26,34 +26,34 @@ double f1 (double x)
|
|||
|
||||
double f2 (double x)
|
||||
{
|
||||
// double x_2 = x * x;
|
||||
double x_2 = x * x;
|
||||
cl++;
|
||||
return 4 - x * x;
|
||||
return 4 - x_2;
|
||||
}
|
||||
|
||||
double f3 (double x)
|
||||
{
|
||||
//double x_2 = x * x;
|
||||
//double x_3 = x * x_2;
|
||||
double x_2 = x * x;
|
||||
double x_3 = x * x_2;
|
||||
cl++;
|
||||
|
||||
return x * x * x + 3 * x * x + 16;
|
||||
return x_3 + 3 * x_2 + 16;
|
||||
}
|
||||
|
||||
double f4 (double x)
|
||||
{
|
||||
//double x_2 = x * x;
|
||||
//double x_4 = x_2 * x_2;
|
||||
double x_2 = x * x;
|
||||
double x_4 = x_2 * x_2;
|
||||
cl++;
|
||||
|
||||
return 3 - 2 * x * x - x * x * x * x;
|
||||
return 3 - 2 * x_2 - x_4;
|
||||
}
|
||||
|
||||
double f5 (double x)
|
||||
{
|
||||
//double sq_x = sqrt(fabs(x) + 1);
|
||||
double sq_x = sqrt(fabs(x) + 1);
|
||||
cl++;
|
||||
return sqrt(fabs(x) + 1) - 2;
|
||||
return sq_x - 2;
|
||||
}
|
||||
|
||||
double f6 (double x)
|
||||
|
|
|
@ -40,7 +40,10 @@ int t3_solve (
|
|||
|
||||
for (it = 1; it <= m; ++it)
|
||||
{
|
||||
c = a - ((a - b) / (y_a - y_b)) * y_a;
|
||||
if (fabs(y_b) < fabs(y_a))
|
||||
c = b - ((a - b) / (y_a - y_b)) * y_b;
|
||||
else
|
||||
c = a - ((a - b) / (y_a - y_b)) * y_a;
|
||||
y = f(c);
|
||||
|
||||
memcpy(&bits, &y, sizeof(bits));
|
||||
|
|
|
@ -40,8 +40,7 @@ int t5_solve (
|
|||
return -1;
|
||||
|
||||
if (
|
||||
is_equal(y_a, y_b) ||
|
||||
is_equal(y_a, y_c) ||
|
||||
(is_equal(y_a, y_b) || is_equal(y_a, y_c)) ||
|
||||
is_equal(y_b, y_c)
|
||||
)
|
||||
return -3;
|
||||
|
@ -49,11 +48,26 @@ int t5_solve (
|
|||
for (it = 1; it < m+1; ++it)
|
||||
{
|
||||
double *temp_pnt = 0, *inner_max_pnt;
|
||||
const double angle = (c - a) / (y_c - y_a);
|
||||
const double x_new = a -
|
||||
double angle, x_new, y_new;
|
||||
|
||||
if (is_equal(y_a, y_b))
|
||||
return -3;
|
||||
else if (is_equal(y_a, y_c))
|
||||
return -3;
|
||||
else if (is_equal(y_b, y_c))
|
||||
return -3;
|
||||
|
||||
if (
|
||||
(is_equal(y_a, y_b) || is_equal(y_a, y_c)) ||
|
||||
is_equal(y_b, y_c)
|
||||
)
|
||||
return -3;
|
||||
|
||||
angle = (c - a) / (y_c - y_a);
|
||||
x_new = a -
|
||||
angle * y_a +
|
||||
((((b - c) / (y_b - y_c)) - angle) / (y_b - y_a)) * y_a * y_c;
|
||||
const double y_new = f(x_new);
|
||||
y_new = f(x_new);
|
||||
|
||||
if (is_eps(y_new, eps))
|
||||
{
|
||||
|
@ -62,15 +76,15 @@ int t5_solve (
|
|||
}
|
||||
|
||||
if (
|
||||
is_equal(x_new, a) ||
|
||||
is_equal(x_new, c) ||
|
||||
(is_equal(x_new, a) ||
|
||||
is_equal(x_new, c)) ||
|
||||
is_equal(x_new, b)
|
||||
)
|
||||
return -1;
|
||||
|
||||
if (
|
||||
is_equal(y_new, y_a) ||
|
||||
is_equal(y_new, y_c) ||
|
||||
(is_equal(y_new, y_a) ||
|
||||
is_equal(y_new, y_c)) ||
|
||||
is_equal(y_new, y_b)
|
||||
)
|
||||
return -3;
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define EPS 1e-16
|
||||
|
||||
static inline double * fpmax (double *pa, double *pb, double fa, double fb, double *max_f_p)
|
||||
{
|
||||
|
@ -34,7 +37,7 @@ static inline int is_equal (const double a, const double b)
|
|||
{
|
||||
double diff = a - b;
|
||||
double max_val = (a > b) ? a : b;
|
||||
return ((diff < 0) ? -diff : diff) < (DBL_EPSILON * max_val);
|
||||
return (fabs(diff) < (EPS * fabs(max_val)));
|
||||
}
|
||||
|
||||
static inline int is_null (const double a)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue