I made a function that uses the np.roots()
to calculate the roots of a cubic function after I solved for coefficients p1
,p2
, and p3
. I'm trying to make it return multiple roots.
Here is my code:
def Q(): . . . coeff = [1,p1, p2, p3] roots = np.roots(coeff) #prints out the real positive root for i in range(0, len(roots)): if np.isreal(roots[i]): return np.real(roots[i]) return root = Q(T1,P1,Tc,Pc) print(root)
output:
root 1
what I want:
root 1 root 2 . . . root n
https://stackoverflow.com/questions/66486136/how-do-i-make-my-function-returns-multiple-values-within-my-for-loop-beginner March 05, 2021 at 11:00AM
没有评论:
发表评论