在Python中分解二次多项式 [英] Factor a quadratic polynomial in Python

查看:56
本文介绍了在Python中分解二次多项式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从在我的脑中分解出一个二次方程式以来,这种事情就发生了,而且自从我学会了它以来就做到了-我将如何着手用Python编写二次分解器?

Since factoring a quadratic equation in my head just happens, and has done that since I learned it - how would I go about starting to write a quadratic factorer in Python?

推荐答案

改善Keiths的答案:

Improving Keiths's answer:

以多项式开始 P(x)= a * x ^ 2 + b * x + c .使用二次方程式(或您选择的另一种方法)来找到根 r1 r2 P(x)= 0 的根.

Start with a polynomial P(x) = a*x^2 + b*x + c. Use the quadratic formula (or another another method of your choice) to find the roots r1 and r2 to P(x) = 0.

您现在可以将P(x)分解为 a *(x-r1)(x-r2).

You can now factor P(x) as a*(x-r1)(x-r2).

如果您的因子(3x-4)(x-9),则解将为3 *(x-4/3)(x-9).您可能想找到一种将3乘以因子的方法,以消除分数/看起来很漂亮.在这种情况下,使用分数算术代替双精度可能会有所帮助,这样您就可以更好地了解分母.

If your factor (3x - 4)(x - 9) the solution will be 3*(x - 4/3)(x - 9). You might want to find a way to multiply the 3 into the factors to get rid of fractions / look pretty. In this case, it might help to use fraction arithmetic instead of doubles so you can know the denominators better.

这篇关于在Python中分解二次多项式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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