完成函数FindRealZeros
,该函数接受一个多项式作为一个列表,并以递增的顺序返回多项式根的列表,重复出现的次数与此相同
到目前为止,我断言只有最小阶数为1的多项式才能传递到函数中。任何顺序为0的函数都会立即使断言失败。接下来,输出一阶多项式的根。你知道吗
我遇到的问题是定义函数的其余部分的阶数大于2的多项式。例如和x^3项。你知道吗
def FindRealZeros(polynomial):
assert len(polynomial) > 1.
# Above i have made sure the polynomial is never just a constant or empty list such as [a], or y = a and [].
assert EnsureStandardForm(polynomial)
# Above ensures that there are never additional zeros that does not satisfy the previous assertion.
if len(polynomial) == 2:
#######################################################################
# Here i am saying that if given a linear polynomai, ax + b, then return the root #
# (given by the equation using the members of the list) #
#######################################################################
first_member = polynomial[0]
second_member = polynomial[1]
root = [(-first_member)/second_member]
return root
到目前为止,我实现的代码工作得很好。问题是我下一步该怎么解决。我可以试着找出一种方法,在第三,第四,等,多项式根可以计算,但这并没有帮助我,因为我需要能够产生任何n阶多项式给定的代码。你知道吗
似乎你不知道多项式求根背后的基本数学。概述一下:
但幸运的是,有一个} ,正好适合您的需要。你知道吗
numpy
函数^{相关问题 更多 >
编程相关推荐