<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.21.0/tensorflow/python/ops/math_ops.py#L5461-L5530) |

Computes the elementwise value of a polynomial.

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.math.polyval`](https://www.tensorflow.org/api_docs/python/tf/math/polyval)

<br />

    tf.math.polyval(
        coeffs, x, name=None
    )

If `x` is a tensor and `coeffs` is a list n + 1 tensors,
this function returns the value of the n-th order polynomial

`p(x) = coeffs[n-1] + coeffs[n-2] * x + ... + coeffs[0] * x**(n-1)`

evaluated using Horner's method, i.e.

    p(x) = coeffs[n-1] + x * (coeffs[n-2] + ... + x * (coeffs[1] + x * coeffs[0]))

#### Usage Example:

    coefficients = [1.0, 2.5, -4.2]
    x = 5.0
    y = tf.math.polyval(coefficients, x)
    y
    <tf.Tensor: shape=(), dtype=float32, numpy=33.3>

#### Usage Example:

    tf.math.polyval([2, 1, 0], 3) # evaluates 2 * (3**2) + 1 * (3**1) + 0 * (3**0)
    <tf.Tensor: shape=(), dtype=int32, numpy=21>

[`tf.math.polyval`](https://www.tensorflow.org/api_docs/python/tf/math/polyval) can also be used in polynomial regression. Taking
advantage of this function can facilitate writing a polynomial equation
as compared to explicitly writing it out, especially for higher degree
polynomials.

    x = tf.constant(3)
    theta1 = tf.Variable(2)
    theta2 = tf.Variable(1)
    theta3 = tf.Variable(0)
    tf.math.polyval([theta1, theta2, theta3], x)
    <tf.Tensor: shape=(), dtype=int32, numpy=21>

<br />

<br />

<br />

| ## Args ||
|---|---|
| `coeffs` | A list of `Tensor` representing the coefficients of the polynomial. |
| `x` | A `Tensor` representing the variable of the polynomial. |
| `name` | A name for the operation (optional). |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A `tensor` of the shape as the expression p(x) with usual broadcasting rules for element-wise addition and multiplication applied. ||

<br />

<br />

## numpy compatibility

<br />

Equivalent to numpy.polyval.

<br />

<br />