From e485ad5c703518a827a0dc6e5398383cbfe80cd9 Mon Sep 17 00:00:00 2001 From: Krishna Vedala Date: Thu, 9 Apr 2020 09:44:05 -0400 Subject: [PATCH] errors less when the first coefficient is "1" --- numerical_methods/durand_kerner_roots.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/numerical_methods/durand_kerner_roots.c b/numerical_methods/durand_kerner_roots.c index 756b6483..888907db 100644 --- a/numerical_methods/durand_kerner_roots.c +++ b/numerical_methods/durand_kerner_roots.c @@ -101,6 +101,15 @@ int main(int argc, char **argv) else if (coeffs[n] != 0) printf("(%g) x^%d = 0\n", coeffs[n], degree - n - 1); + double tmp; + if (n > 0) + coeffs[n] /= tmp; /* numerical errors less when the first coefficient is "1" */ + else + { + tmp = coeffs[0]; + coeffs[0] = 1; + } + /* initialize root approximations with random values */ if (n < degree - 1) {