DEV Community

Caleb Zhao
Caleb Zhao

Posted on

Incorrect calculations: Horner polynomials

In this blog post, we explore issues related to incorrect polynomial evaluations using the Horner scheme (also known as the Qin Jiushao algorithm) within MATLAB.

Example 1. Consider the polynomial function f(x) defined as:

f(x) = ((((((c7*x+c6)*x+c5)*x+c4)*x+c3)*x+c2)*x+c1)*x+c0,
Enter fullscreen mode Exit fullscreen mode

where the coefficients are given by c7 = 111990.0, c6 = 5115500000.0, c5 = 949100000.0, c4 = 4058000000.0, c3 = 1531000000.0, c2 = 5781000000.0, c1 = 350800000.0, and c0 = -321499872.52. Calculate the value of f(x) at x = 45678.0.

Using MATLAB, I computed the value of the polynomial at x = 45678.0. The result is shown in the following screenshot.

MATLAB outputFrom the above screenshot, it can be seen that the output from MATLAB is a large number having 38 integer digits.

However, the accurate value of the polynomial is -0.64307299252e9 (as provided by ISRealsoft). Thus, the output from MATLAB is incorrect.

previous \,\quad\quad\quad\quad\hspace{7.2cm} next

Top comments (0)