A one-dimensional polynomial class. .. note:: This forms part of the old polynomial API. Since version 1.4, the new polynomial API defined in `numpy.polynomial` is preferred. A summary of the differences can be found in the :doc:`transition guide </reference/rou
| 1094 | |
| 1095 | @set_module('numpy') |
| 1096 | class poly1d: |
| 1097 | """ |
| 1098 | A one-dimensional polynomial class. |
| 1099 | |
| 1100 | .. note:: |
| 1101 | This forms part of the old polynomial API. Since version 1.4, the |
| 1102 | new polynomial API defined in `numpy.polynomial` is preferred. |
| 1103 | A summary of the differences can be found in the |
| 1104 | :doc:`transition guide </reference/routines.polynomials>`. |
| 1105 | |
| 1106 | A convenience class, used to encapsulate "natural" operations on |
| 1107 | polynomials so that said operations may take on their customary |
| 1108 | form in code (see Examples). |
| 1109 | |
| 1110 | Parameters |
| 1111 | ---------- |
| 1112 | c_or_r : array_like |
| 1113 | The polynomial's coefficients, in decreasing powers, or if |
| 1114 | the value of the second parameter is True, the polynomial's |
| 1115 | roots (values where the polynomial evaluates to 0). For example, |
| 1116 | ``poly1d([1, 2, 3])`` returns an object that represents |
| 1117 | :math:`x^2 + 2x + 3`, whereas ``poly1d([1, 2, 3], True)`` returns |
| 1118 | one that represents :math:`(x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x -6`. |
| 1119 | r : bool, optional |
| 1120 | If True, `c_or_r` specifies the polynomial's roots; the default |
| 1121 | is False. |
| 1122 | variable : str, optional |
| 1123 | Changes the variable used when printing `p` from `x` to `variable` |
| 1124 | (see Examples). |
| 1125 | |
| 1126 | Examples |
| 1127 | -------- |
| 1128 | >>> import numpy as np |
| 1129 | |
| 1130 | Construct the polynomial :math:`x^2 + 2x + 3`: |
| 1131 | |
| 1132 | >>> import numpy as np |
| 1133 | |
| 1134 | >>> p = np.poly1d([1, 2, 3]) |
| 1135 | >>> print(np.poly1d(p)) |
| 1136 | 2 |
| 1137 | 1 x + 2 x + 3 |
| 1138 | |
| 1139 | Evaluate the polynomial at :math:`x = 0.5`: |
| 1140 | |
| 1141 | >>> p(0.5) |
| 1142 | 4.25 |
| 1143 | |
| 1144 | Find the roots: |
| 1145 | |
| 1146 | >>> p.r |
| 1147 | array([-1.+1.41421356j, -1.-1.41421356j]) |
| 1148 | >>> p(p.r) |
| 1149 | array([ -4.44089210e-16+0.j, -4.44089210e-16+0.j]) # may vary |
| 1150 | |
| 1151 | These numbers in the previous line represent (0, 0) to machine precision |
| 1152 | |
| 1153 | Show the coefficients: |
no outgoing calls
no test coverage detected
searching dependent graphs…