aboutsummaryrefslogtreecommitdiffstats
path: root/main_23.c
diff options
context:
space:
mode:
authorjustanothercatgirl <sotov2070@gmail.com>2024-09-25 16:39:11 +0300
committerjustanothercatgirl <sotov2070@gmail.com>2024-09-25 16:39:11 +0300
commit3b3907d9c00185d5c4920df586d14293a3589366 (patch)
tree445c01b9f200a1fa8baf1ba0158a4e640d09d54a /main_23.c
parent9ef5c1d62ce09e4b4e736baf843e9a4f8bad3c49 (diff)
changed differentiation to central difference
Diffstat (limited to 'main_23.c')
-rw-r--r--main_23.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/main_23.c b/main_23.c
index cf736ab..f6936da 100644
--- a/main_23.c
+++ b/main_23.c
@@ -69,8 +69,8 @@ struct dval *differentiate(func_t f, double start, double end, double step, long
struct dval *vals = calloc(tlength, sizeof(struct dval));
for (long i = 0; i < tlength; ++i) {
double x = start + step * i;
- double xi = start + step * (1+i);
- double y = (f(xi) - f(x))/step;
+ // central difference
+ double y = (f(x+step) - f(x-step))/ (2*step);
vals[i] = (struct dval){.x = x, .y = y};
}
*length = tlength;