This is an example on how to document Python modules using doc strings and the sphinx tool. The doc strings can make use of the reStructuredText format, see http://docutils.sourceforge.net/docs/user/rst/quickstart.html. It is recommended to document Python modules according to the rules of the numpy package. See also A Guide to NumPy/SciPy Documentation.
Return the two roots in the quadratic equation:
a*x**2 + b*x + c = 0
or written with math typesetting
The returned roots are real or complex numbers, depending on the values of the arguments a, b, and c.
Parameters : | a: int, real, complex :
b: int, real, complex :
c: int, real, complex :
verbose: bool, optional :
|
---|---|
Returns : | root1, root2: real, complex :
|
Raises : | ValueError: :
|
See also
Notes
The algorithm is a straightforward implementation of a very well known formula [R1].
References
[R1] | (1, 2) Any textbook on mathematics or Wikipedia. |
Examples
>>> roots(-1, 2, 10)
(-5.3166247903553998, 1.3166247903553998)
>>> roots(-1, 2, -10)
((-2-3j), (-2+3j))
Alternatively, we can in a doc string list the arguments and return values in a table
Parameter | Type | Description |
---|---|---|
a | float/complex | coefficient for quadratic term |
b | float/complex | coefficient for linear term |
c | float/complex | coefficient for constant term |
r1, r2 | float/complex | return: the two roots of the quadratic polynomial |
Representation of a quadratic polynomial:
Example:
>>> q = Quadratic(a=2, b=4, c=-16)
>>> print q
2*x**2 + 4*x - 16
>>> r1, r2 = q.roots()
>>> r1
2.0
>>> r2
-4.0
>>> q(r1), q(r2) # check
(0.0, 0.0)
>>> repr(q)
'Quadratic(a=2, b=4, c=-16)'
Methods
__call__(x) | |
roots() | Return the two roots of the quadratic polynomial. |
value(x) | Return the value of the quadratic polynomial for x. |
The arguments a, b, and c are coefficients in the quadratic polynomial:
a*x**2 + b*x + c
or
Argument | Type | Description |
---|---|---|
a | float/complex | coefficient for quadratic term |
b | float/complex | coefficient for linear term |
c | float/complex | coefficient for constant term |
Raises : | ValueError: :
|
---|
Return the two roots of the quadratic polynomial. The roots are real or complex, depending on the coefficients in the polynomial.
Let us define a quadratic polynomial:
>>> q = Quadratic(a=2, b=4, c=-16)
>>> print q
2*x**2 + 4*x - 16
The roots are then found by
>>> r1, r2 = q.roots()
>>> r1
2.0
>>> r2
-4.0