NumPy: Compute the given polynomial values

NumPy Mathematics: Exercise-17 with Solution

Write a NumPy program to compute the following polynomial values.

Sample Solution:

Python Code:

import numpy as np
print("Polynomial value when x = 2:")
print(np.polyval([1, -2, 1], 2))
print("Polynomial value when x = 3:")
print(np.polyval([1, -12, 10, 7, -10], 3))

Sample Output:

Polynomial value when x = 2:                                           
Polynomial value when x = 3:                                           

Pictorial Presentation:

NumPy Mathematics: Compute the given polynomial values.

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a NumPy program to find the roots of the following polynomials.
Next: Write a NumPy program to add one polynomial to another, subtract one polynomial from another, multiply one polynomial by another and divide one polynomial by another.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz

Python: Tips of the Day

Getting rid of unwanted characters:

You can get rid of whitespaces or any specific character using strip methods in Python. You can use either plain strip for both sides, lstrip for the left side and rstrip for the right side only.

str="+++Welcome python+++"



+++Welcome python+++