使用 Python 查找多项式根——可能的 Numpy 扩展错误 [英] Finding polynomial roots using Python -- Possible Numpy Extension Bug

查看:68
本文介绍了使用 Python 查找多项式根——可能的 Numpy 扩展错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Numpy 来获取多项式的根.Numpy 提供了一个模块多项式".

I am using Numpy to obtain the roots of polynomials. Numpy provides a module 'polynomial'.

我对 x^2 + 5*x + 6 = 0 的手算是 x = -2 &x = -3.(简单)

My hand calc for x^2 + 5*x + 6 = 0 is x = -2 & x = -3. (Simple)

但我的代码显示了错误的答案:array([-0.5 , -0.33333333])(反转?)

But my code shows me the wrong answer: array([-0.5 , -0.33333333]) (Inversed?)

有人能在我的代码中找到罪魁祸首吗?还是只是一个错误?

Could anyone please find the culprit in my code? Or is it simply a bug?

from numpy.polynomial import Polynomial as P
p = P([1, 5, 6])
p.roots()

推荐答案

只需按其他顺序传递即可,

Simply pass it in the other order,

p = P([6, 5, 1])

这篇关于使用 Python 查找多项式根——可能的 Numpy 扩展错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆