Testing task 2
This commit is contained in:
parent
3e90cc7ebb
commit
64182805a0
5 changed files with 19 additions and 18 deletions
|
@ -81,7 +81,6 @@ double f4 (double x)
|
|||
|
||||
double d4 (double x)
|
||||
{
|
||||
double x_2 = x * x;
|
||||
cl_d++;
|
||||
|
||||
return -4 * x - 4 * ((x * x) * x);
|
||||
|
@ -96,7 +95,7 @@ double f5 (double x)
|
|||
double d5 (double x)
|
||||
{
|
||||
cl_d++;
|
||||
return (((signbit(x)) ? -1 : 1) * (1.0 / (sqrt(fabs(x) + 1))) * 0.5;
|
||||
return (((signbit(x)) ? -1 : 1) * (1.0 / (sqrt(fabs(x) + 1)))) * 0.5;
|
||||
}
|
||||
|
||||
double f6 (double x)
|
||||
|
|
|
@ -1,21 +1,27 @@
|
|||
#ifndef INIT_F_H
|
||||
#define INIT_F_H
|
||||
|
||||
int get_call_count (void);
|
||||
int get_call_function_count (void) ;
|
||||
int get_call_derivative_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);
|
||||
|
||||
|
|
|
@ -13,10 +13,9 @@ int main(int argc, char *argv[])
|
|||
|
||||
double (*f) (double);
|
||||
double (*f_lst[]) (double) = {f0, f1, f2, f3, f4, f5, f6, sin}; // TODO: Remove sin
|
||||
double (*d_lst[]) (double) = {d0, d1, d2, d3, d4, d5, d6, cos}; // TODO: Remove cos
|
||||
int len_f = sizeof(f_lst) / sizeof(f_lst[0]);
|
||||
|
||||
double (*d) (double);
|
||||
double (*d_lst[]) (double) = {d0, d1, d2, d3, d4, d5, d6, cos}; // TODO: Remove cos
|
||||
|
||||
if (
|
||||
!((argc == 5) &&
|
||||
|
@ -35,7 +34,7 @@ int main(int argc, char *argv[])
|
|||
it = t2_solve(f, d_lst[k], x_0, eps, m, &x);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
|
||||
cl = get_call_count();
|
||||
cl = get_call_function_count();
|
||||
|
||||
if (it >= m)
|
||||
{
|
||||
|
|
|
@ -3,27 +3,23 @@
|
|||
#include <math.h>
|
||||
#include <float.h>
|
||||
|
||||
int t7_solve (
|
||||
int t2_solve (
|
||||
double (*f) (double),
|
||||
double (*d) (double),
|
||||
double x_0, double eps,
|
||||
int m, double *x
|
||||
) {
|
||||
int it = 0;
|
||||
double y = f(x_0);
|
||||
|
||||
if (fabs(y - x_0) - eps < DBL_EPSILON)
|
||||
{
|
||||
*x = x_0;
|
||||
return 1;
|
||||
}
|
||||
for (it = 1; it < m; ++it)
|
||||
{
|
||||
if (y - eps < DBL_EPSILON)
|
||||
break;
|
||||
|
||||
for (it = 0; it < m; ++it)
|
||||
{
|
||||
x_0 = y;
|
||||
x_0 -= (y / d(x_0));
|
||||
y = f(x_0);
|
||||
|
||||
if (fabs(y - x_0) - eps < DBL_EPSILON)
|
||||
break;
|
||||
}
|
||||
|
||||
*x = x_0;
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
#ifndef SOLVE_H
|
||||
#define SOLVE_H
|
||||
|
||||
int t7_solve (
|
||||
int t2_solve (
|
||||
double (*f) (double),
|
||||
double (*d) (double),
|
||||
double x_0, double eps,
|
||||
int m, double *x
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue