Issue
I need help in creating a statement with this initial set of positive numbers for the roots of an equation. I have to substitute them to my polynomial equation to determine if that certain number is a root or not. This is what I came up so far:
k = [4.0, 2.0, 1.0054, 0.9946] # Set of roots (sign-less)
pol = x**4 + 6*x**3 + 7*x**2 - 6*x - 8 # Polynomial equation
(pol(k)) <= abs(1)
With the output:
array([False, False, True, True])
Basically, what I wanted is to print those True as it is and reverse the sign of those False, since the latter gave a very large value and therefore might not be the root to my equation. Desired output should be like this:
[-4.0, -2.0, 1.0054, 0.9946]
I'm somewhat stuck in my third line since I could not think how the next step shall be executed. Any help would be appreciated. I am very new in python coding. Thanks!
Solution
code :
k = [4.0, 2.0, 1.0054, 0.9946]
array = ([False, False, True, True])
if len(k)==len(array):
for i in range(len(k)):
if array[i] == False:
k[i]-=(2*k[i])
print(k)
**output : **
[-4.0, -2.0, 1.0054, 0.9946]
have a look, this code will update your k list to desired form.
Answered By - Omkar Kalantre
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.