Description
In numerical analysis, the Horner scheme or Horner algorithm, named after William George Horner, is an algorithm for the efficient evaluation of polynomials in monomial form. Horner’s method describes a manual process by which one may approximate the roots of a polynomial equation. The Horner scheme can also be viewed as a fast algorithm for dividing a polynomial by a linear polynomial with Ruffini’s rule.
Application
The Horner scheme is often used to convert between different positional numeral systems — in which case x is the base of the number system, and the ai coefficients are the digits of the base-x representation of a given number — and can also be used if x is a matrix, in which case the gain in computational efficiency is even greater.
History
Even though the algorithm is named after William George Horner, who described it in 1819, the method was already known to Isaac Newton in 1669, and even earlier to the Chinese mathematician Ch’in Chiu-Shao in the 13th century. TASK: write a program to calculate sum of Polynomial by Horner scheme.
Input
tow lines. The first line have tow numbers,n and x, n<=20, x<=10 The second line have n+1 numbers, a0,a1…an.
Output
The sum of Polynomial
Sample Input
5 2
0 1 2 3 4 5
Sample Output
258
#include<iostream>
using namespace std;
int qinjiushao(int a[], int n, int x)
{
int sum = a[n];
for (int i = n - 1; i >= 0; i--)
{
sum = sum*x + a[i];
}
return sum;
}
int main()
{
int arr[1005], n, x;
cin >> n >> x;
for (int i = 0; i < n+1;i++)
cin >> arr[i];
cout << qinjiushao(arr, n, x) << endl;
return 0;
}
本文介绍了数值分析中用于高效评估多项式的Horner算法。该算法不仅可用于手动近似多项式方程的根,还可用于不同进制数系统之间的转换,并且在矩阵计算中也有广泛应用。文中提供了一个简单的C++程序示例,演示了如何使用Horner算法来计算多项式的值。
577

被折叠的 条评论
为什么被折叠?



