diff options
author | justanothercatgirl <sotov2070@gmail.com> | 2024-09-25 16:39:11 +0300 |
---|---|---|
committer | justanothercatgirl <sotov2070@gmail.com> | 2024-09-25 16:39:11 +0300 |
commit | 3b3907d9c00185d5c4920df586d14293a3589366 (patch) | |
tree | 445c01b9f200a1fa8baf1ba0158a4e640d09d54a | |
parent | 9ef5c1d62ce09e4b4e736baf843e9a4f8bad3c49 (diff) |
changed differentiation to central difference
-rw-r--r-- | main_23.c | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -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; |