aboutsummaryrefslogtreecommitdiffstats
path: root/main_23.c
diff options
context:
space:
mode:
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;