python - 定义一个函数以定位给定多项式的零点
问题描述
完成FindRealZeros
接受多项式作为列表并返回多项式根的列表的函数,按递增顺序,出现次数与重复次数相同
到目前为止,我已经断言只有最小 1 阶的多项式可以传递给函数。任何 0 阶函数都会立即使断言失败。接下来输出 1 阶多项式的根。
我遇到的问题是为大于 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 阶多项式生成代码。
解决方案
推荐阅读
- gradle - Gradle 中测试和检查任务的区别
- asp.net - Html Agility Pack 在 html 中获取 span 类名
- node.js - 为什么节点 SerialPort Readline 解析器不工作?
- python - Python多线程 - 与来自父/主线程的子线程交互
- c - C endWord 验证;你会如何解释这段代码?
- matlab - 将一个非常大的矩阵加载到求解器时,如何避免同时拥有两个实例?
- python-3.x - Boto3 - 打印 AWS 实例类型定价
- database - 在没有本地文件的情况下进行 Oracle DB 到 Cassandra DB 迁移或导入的方法
- wordpress - 修改一个 Wordpress 函数,使其每次迭代 10 次
- mysql - 在 mysql 中使用 IDENTITY() 函数我可以在函数中包含字母数字字符,例如这个