This commit is contained in:
AZEN-SGG 2025-05-11 17:02:30 +03:00
parent f140ae9722
commit 6efd4f5786
20 changed files with 51 additions and 34 deletions

View file

@ -1,6 +1,8 @@
#ifndef INIT_F_H
#define INIT_F_H
#define NUM_FPE 1e-300
int get_call_count (void);
double f0 (double x);
double f1 (double x);

View file

@ -3,11 +3,11 @@
#include <math.h>
#include <float.h>
int t1_solve (
double t1_solve (
double (*f) (double),
double x, double h
) {
if (h < DBL_EPSILON)
if (h < NUM_FPE)
return DBL_MAX;
return (f(x + h) - f(x)) / h;
}

View file

@ -1,7 +1,9 @@
#ifndef SOLVE_H
#define SOLVE_H
int t1_solve (
#define NUM_FPE 1e-300
double t1_solve (
double (*f) (double),
double x, double h
);

View file

@ -3,11 +3,11 @@
#include <math.h>
#include <float.h>
int t2_solve (
double t2_solve (
double (*f) (double),
double x, double h
) {
if (h < DBL_EPSILON)
if (h < NUM_FPE)
return DBL_MAX;
return (f(x + h) - f(x - h)) / (2 * h);
}

View file

@ -1,7 +1,9 @@
#ifndef SOLVE_H
#define SOLVE_H
int t2_solve (
#define NUM_FPE 1e-300
double t2_solve (
double (*f) (double),
double x, double h
);

View file

@ -19,7 +19,7 @@ int main (int argc, char *argv[])
!((argc == 4) &&
sscanf(argv[1], "%lf", &x) == 1 &&
((sscanf(argv[2], "%lf", &h) == 1) && (h > 0)) &&
((sscanf(argv[3], "%d", &k) == 1) && ((0 <= k) && (k <= len_f))))
((sscanf(argv[3], "%d", &k) == 1) && ((0 <= k) && (k < len_f))))
) {
fprintf(stderr, "Usage: %s x h k\n", argv[0]);
return -1;

View file

@ -3,12 +3,13 @@
#include <math.h>
#include <float.h>
int t3_solve (
double t3_solve (
double (*f) (double),
double x, double h
) {
if (h < DBL_EPSILON)
double h_2 = h * h;
if (h_2 < NUM_FPE)
return DBL_MAX;
return (f(x + h) - 2 * f(x) + f(x - h)) / (h * h);
return (f(x + h) - 2 * f(x) + f(x - h)) / h_2;
}

View file

@ -1,7 +1,9 @@
#ifndef SOLVE_H
#define SOLVE_H
int t3_solve (
#define NUM_FPE 1e-300
double t3_solve (
double (*f) (double),
double x, double h
);