Python 中的卡尔达诺公式
我需要有人检查我在 Python 中使用卡尔达诺公式的尝试。我正在尝试求解三次方程的根,我想知道到目前为止我所做的是否正确(或错误)。泰亚
def solve(a,b,c,d):
Q = (3*a*c - (b**2)) / (9*(a**2))
R = (9*a*b*c - 27*(a**2)*d - 2*(b**3)) / (54*(a**3))
D = (Q**3) + (R**2)
S = (R + (D**(1/2)))**(1/3)
T = (R - (D**(1/2)))**(1/3)
x1 = S + T - (b/(3*a))
x2 = -((S + T)/2) - (b/(3*a)) + 0.5j * (3**(1/2)) * (S - T)
x3 = -((S + T)/2) - (b/(3*a)) - 0.5j * (3**(1/2)) * (S - T)
return (x1,x2,x3)
I need someone to check my attempt in using Cardano's Formula in Python. I'm trying to solve for the roots of a cubic equation, and I'm wondering if what I'm doing is correct (or wrong) so far. TYIA
def solve(a,b,c,d):
Q = (3*a*c - (b**2)) / (9*(a**2))
R = (9*a*b*c - 27*(a**2)*d - 2*(b**3)) / (54*(a**3))
D = (Q**3) + (R**2)
S = (R + (D**(1/2)))**(1/3)
T = (R - (D**(1/2)))**(1/3)
x1 = S + T - (b/(3*a))
x2 = -((S + T)/2) - (b/(3*a)) + 0.5j * (3**(1/2)) * (S - T)
x3 = -((S + T)/2) - (b/(3*a)) - 0.5j * (3**(1/2)) * (S - T)
return (x1,x2,x3)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将根代回方程中,看看是否得到零。
You can substitute the roots back into your equation and see if you get zero.
您错误地写出了三次方程的解。一般来说,没有方程组是不可能的,所以我可以提供以下解决方案
You have incorrectly written down the solution of the cubic equation. In general, it is impossible to do without a system of equations, so I can offer the following solution