我正在使用Python 2和维基百科文章"Cubic函数"中给出的相当简单的方法.这也可能是我必须定义的立方根函数的问题,以便创建标题中提到的函数.
# Cube root and cubic equation solver
#
# Copyright (c) 2013 user2330618
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, you can obtain one at http://www.mozilla.org/MPL/2.0/.
from __future__ import division
import cmath
from cmath import log, sqrt
def cbrt(x):
"""Computes the cube root of a number."""
if x.imag != 0:
return cmath.exp(log(x) / …Run Code Online (Sandbox Code Playgroud)