9951 explained code solutions for 126 technologies


python-numpyGet cubic equation roots


import numpy as np
arr = np.array([1, 24, -32, 1]) # x^3 + 24*x^2 - 32*x + 1
roots = np.roots(arr)ctrl + c
import numpy as np

load Numpy module for Python

np.array

declare Numpy array

[1, 24, -32, 1]

this array declares sample polynom x^3 + 24*x^2 - 32*x + 1 to get roots for

.roots(

return array with roots

roots

will contain calculated roots