horner.py

Created by ews31415

Created on June 06, 2025

224 Bytes

Horner’s Method

Evaluation of polynomial p(x) at a point x. p(x) is represented as a list of coefficients with powers in descending order.

p(x) = a_n * x^n + a_(n-1) * x^(n-1) + … + a2 * x^2 + a1 * x + a0 l1 = [a_n, a_(n-1), … , a2, a1, a0]


from math import *
print("Horners Method")
print("p=ax**n+bx**(n-1)+...")
l1=eval(input("List of coefs? "))
x=eval(input("x? "))
p=l1[0]
n=len(l1)
for i in range(1,n):
  p=p*x+l1[i]
print("p(x)= "+str(p))
  
  

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.