Question

P5. Write a python program to solve the following polynomials. (Solving a polynomial means finding the roots of the polynomial) x2 3x 2 0 3x2 x 6-0 x3- 2x2 -x-2 0 Print the roots as x1-?, x2-?, x3-? Are the roots real or imaginary?

In python. Thanks

0 0
Add a comment Improve this question Transcribed image text
Answer #1

# p[0] * x**n + p[1] * x**(n-1) + ... + p[n-1]*x + p[n]


import numpy as np
def fun():
k = np.roots(p)
  
for i in range(0,len(k)):
    print('x',i+1," = ",k[i])

print(type(k[0])) #if roots are imaginary then ouput will be complex
# else float as a real number
print()
  
p = (1,3,2)  
fun();  
p = (3,1,6)  
fun();  
p = (1,-2,-1,-2)  
fun();  

output:::-----

x 1  =  -2.0
x 2  =  -1.0
<class 'numpy.float64'>

x 1  =  (-0.16666666666666663+1.4043582955293932j)
x 2  =  (-0.16666666666666663-1.4043582955293932j)
<class 'numpy.complex128'>

x 1  =  (2.6589670819169937+0j)
x 2  =  (-0.3294835409584969+0.8022545575574102j)
x 3  =  (-0.3294835409584969-0.8022545575574102j)
<class 'numpy.complex128'>
Add a comment
Know the answer?
Add Answer to:
In python. Thanks P5. Write a python program to solve the following polynomials. (Solving a polynomial...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT